Search code examples
phpgdsyntax-errorgdlibimagefilter

Error with imagefilter() from GD (no file?)


I keep getting the following errors:

/private/var/tmp/phpl3E3lq Warning: imagecreatefromjpeg(/private/var/tmp/phpl3E3lq) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /sites/uploadresults.php on line 10 Conversion failed Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /sites/uploadresults.php on line 22

<?php
move_uploaded_file ($_FILES['Image']['tmp_name'], "/sites/".$_FILES['Image']['name']) or die ('Could not upload');

echo $_FILES['Image']['tmp_name']

 ?>


<?php
$img = imagecreatefromjpeg($_FILES['Image']['tmp_name'])
?>

<?php
if($img && imagefilter($img, IMG_FILTER_PIXELATE, 3))
{
echo $img;
}
else
{

echo 'Conversion failed';
imagedestroy($img);

}

?>

<img src="http://localhost/<?php echo $_FILES['Image']['name'] ?>" />

I'm not sure what is going on. It seems like the $img isn't picking up the jpeg I'm trying to convert to a pixelated form. I'm new to this so it might be my syntax or something.


Solution

  • You need to use the new filename, not the original one from before you moved it:

    $img = imagecreatefromjpeg("/sites/".$_FILES['Image']['name']);