Processing a user uploaded photo & displaying

I have a script for altering a photograph.

 <?php 
$thefile = $_FILES["thefile"]['tmp_name'];
$image = imagecreatefromjpeg("$thefile");

function pixelate(&$image) {
    $imagex = imagesx($image); 
    $imagey = imagesy($image);
    $blocksize = 12;
    for ( $x = 0; $x < $imagex; $x += $blocksize)  {
        for ($y = 0; $y < $imagey; $y += $blocksize) {
            $rgb = imagecolorat($image, $x, $y);
            imagefilledrectangle($image, $x, $y, $x + $blocksize - 1, $y + $blocksize - 1, $rgb);
        }
    }
}

pixelate($image);
imagejpeg($image);
imagedestroy($image);
?>

The HTML form for the upload looks like this

<form action="uploaded.php" method="post" enctype="multipart/form-data">
<input type="file" name="thefile" id="thefile">
<input type="hidden" name="MAX_FILE_SIZE", value="30000">
<input type="submit" value="Upload jpeg" name="submit">
</form>

At the moment rather than the image being displayed in the browser I am instead getting question lots of black symbols with question a mark inside

Have you already output a header to the browser to tell it that you’re sending jpeg data?

// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');

// Skip the to parameter using NULL, then set the quality to 75%
imagejpeg($im, NULL, 75);

// Free up memory
imagedestroy($im);
?>

From: http://php.net/manual/en/function.imagejpeg.php

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.