Page 1 of 1
Why won't php work with this image?
Posted: Sat Sep 25, 2004 5:58 pm
by Tygur
When I try to use imagecreatefromjpeg and imagecreatefromstring to work with this one image, it claims that it isn't a valid jpeg image. Why is this, and do I have any options?
Thanks in advance for any help. I'm just trying to automatically generate a thumbnail. The image is a picture taken with a cell phone camera. If it doesn't work with this one, it seems safe to assume it won't work with others, which would be a problem.
It can be found here:
http://www.snsware.net/Image003.jpg
Posted: Sat Sep 25, 2004 6:03 pm
by feyd
post the code you are trying to use with this image.
Posted: Sat Sep 25, 2004 8:59 pm
by Breckenridge
I had this problem with few images and this is what I did. I loaded the image into an image editing program, then did a save as jpeg, ran my code again and it worked. Try it it should work.
Posted: Sat Sep 25, 2004 9:09 pm
by evilmonkey
If you think that taking something like a .gif or a .png and changing the extension to .jpg will work, think again. (this seems like what's happenning). Think of it as taking a book written in French and writing "ENGLISH" on the cover. A person who can read both French and English won't care (same with a program that can read both gifs and jpegs), but a person who doesn't know the first thing about French will be dazed and confused (much like imagecreatefromjpeg() doesn't know anything about anything other than jpegs). I suggest doing what Breckenridge said.
Good luck!
Posted: Sat Sep 25, 2004 11:31 pm
by Tygur
Ok, I made a quick php script that expects the image file to be in the same directory with the script itself:
Code: Select all
<?php
echo "<h1>First let's try imagecreatefromjpeg</h1>";
$image = imagecreatefromjpeg('Image003.jpg');
if ($image===false) {
echo "<p>Something went wrong!";
} else {
echo "<p>Ok, now everything's fine.";
imagedestroy($image);
}
echo "<h1>Now let's try imagecreatefromstring</h1>";
$image_contents = file_get_contents('Image003.jpg');
if ($image_contents===false) {
echo "<p>The image couldn't even be read!";
} else {
echo "<p>The image was read in. Now let's see if it works.";
$image = imagecreatefromstring($image_contents);
if ($image===false) {
echo "<p>Something went wrong!";
} else {
echo "<p>Ok, now everything's fine.";
imagedestroy($image);
}
}
?>
Here is the output I got:
First let's try imagecreatefromjpeg
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'Image003.jpg' is not a valid JPEG file in f:\www\root\image.php on line 3
Something went wrong!
Now let's try imagecreatefromstring
The image was read in. Now let's see if it works.
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Passed data is not in 'JPEG' format in f:\www\root\image.php on line 16
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Couldn't create GD Image Stream out of Data in f:\www\root\image.php on line 16
Something went wrong!
Posted: Sat Sep 25, 2004 11:33 pm
by Tygur
evilmonkey wrote:If you think that taking something like a .gif or a .png and changing the extension to .jpg will work, think again. (this seems like what's happenning).
No, I did not take an image of some other format and change the extension. Check out the script I just posted. imagecreatefromstring recognizes that it looks at first like a jpeg, but it still rejects it for some reason.
Posted: Sun Sep 26, 2004 12:43 am
by feyd
it's possible your version of GD doesn't recognize the type/version of JPEG it is... after all, JPEG is an umbrella format.
Posted: Tue Dec 21, 2004 6:06 pm
by onion2k
My version of GD (bundled (2.0.12 compatible)) is happy to open it. The version on my hosting company's server (2.0.33) isn't though. The only odd thing I can see about it is that theres no resolution defined in the jpeg, and its jpg/jfif compressed rather than jpg/jfif,progressive.. bit of a puzzle really.