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
Why won't php work with this image?
Moderator: General Moderators
-
Breckenridge
- Forum Commoner
- Posts: 62
- Joined: Thu Sep 09, 2004 11:10 pm
- Location: Breckenridge, Colorado
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
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!
Good luck!
Ok, I made a quick php script that expects the image file to be in the same directory with the script itself:
Here is the output I got:
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!
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.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).
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.