Is something wrong with this php GD code?
if ($img = @imagecreatefromjpeg('./images/upload/13/1.JPG')) {
imagejpeg($img, $path, 100);
imagedestroy($img);
} else {
die ("image was not created or saved");
}
I'm getting the message:
Warning: imagejpeg(): 8 is not a valid Image resource in C:\xampp\htdocs\invivid\libraries\photograph_classes.php on line 276
Warning: imagedestroy(): 8 is not a valid Image resource in C:\xampp\htdocs\invivid\libraries\photograph_classes.php on line 277
The image is being created initially, we know this from the if statement, but why doesn't imagejpeg or imagedestroy work properly?
Solution:开发者_StackOverflow中文版 Ok, I think it had something to do with an incorrect $path variable, it seems to be working fine now.
I´ve never used it like that (without creating a new image, doing some manipulation, etc.), but it seems the manual is a bit vague: imagecreatefromjpeg returns an image resource identifier and imagejpeg needs an image resource, returned by one of the image creation functions. It certainly looks the same, but perhaps they are not.
From the documentation page on imagecreatefromjpeg (although this seems particulary implausible):
imagecreatefromJPEG is for .JPEG and .JPG ending & imagecreatefromjpeg is for .jpeg and .jpg ending. That function is case sensitive.
Another worthwhile thing to try could be setting
ini_set('gd.jpeg_ignore_warning', 1);
and see if that solves presumed issues with corrupted images.
精彩评论