PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Dec 19, 2018 3:40 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sat Sep 25, 2004 5:58 pm 
Offline
Forum Newbie

Joined: Sat Sep 25, 2004 5:55 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 25, 2004 6:03 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
post the code you are trying to use with this image.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 25, 2004 8:59 pm 
Offline
Forum Commoner

Joined: Thu Sep 09, 2004 11:10 pm
Posts: 62
Location: Breckenridge, Colorado
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 25, 2004 9:09 pm 
Offline
Forum Regular
User avatar

Joined: Sun Oct 06, 2002 1:24 pm
Posts: 823
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!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 25, 2004 11:31 pm 
Offline
Forum Newbie

Joined: Sat Sep 25, 2004 5:55 pm
Posts: 3
Ok, I made a quick php script that expects the image file to be in the same directory with the script itself:
Syntax: [ Download ] [ Hide ]
<?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:
Quote:
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!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 25, 2004 11:33 pm 
Offline
Forum Newbie

Joined: Sat Sep 25, 2004 5:55 pm
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 26, 2004 12:43 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
it's possible your version of GD doesn't recognize the type/version of JPEG it is... after all, JPEG is an umbrella format.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 7:06 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group