Jump to content

Can't resize large images with imagecreatefromjpeg()


floridaflatlander
 Share

Recommended Posts

I Can't resize large images with imagecreatefromjpeg()

 

I can load small 38kb images fine, when they get up 780+- or 1.3 mb +-  (with a width of 2500px * x) I get the below error

 

I also can upload the same pics in another file with out resizing(using imagecreatefromjpeg())  them and the script works fine.

 

my max file upload size with xampp is 128mb / php5

 

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 191 extraneous bytes before marker 0xd9 in C:\xampp\htdocs\ed\phpsol\ch08\work\includes\create_thumb.inc.php on line 35

 

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'C:\xampp\tmp\php9596.tmp' is not a valid JPEG file in C:\xampp\htdocs\ed\phpsol\ch08\work\includes\create_thumb.inc.php on line 35

 

I'm basicly using a switch

switch($type) {

      case 1:

        $source = @ imagecreatefromgif($original);

    if (!$source) {

      $result = 'Cannot process GIF files. Please use JPEG or PNG.';

      }

    break;

      case 2:

        $source = imagecreatefromjpeg($original); <---- LINE 35 where $original is $original = $_FILES['image']['tmp_name'];

    break;

Link to comment
Share on other sites

Check your memory_limit in your php.ini.

 

If it's a hosted server, then you might not be able to change it, especially if it's a free host. Impose a maximum filesize and make them do the bulk of the resizing, even paint can resize images (albeit bad quality), but many free apps can do it easily.

 

If you really want that functionality you will need to use ini_set:

ini_set("memory_limit", "30M"); // Should be, I would say, 10% larger than the max file size you want users to upload.

 

You can use ini_get to see what the memory limit is atm, i am guessing yours is at 8MB

echo(ini_get("memory_limit"));

 

You can also use HTACCESS files or edit the php.ini directly but i highly discourage this as it will use memory that it probably wont need 99% of the time.

Link to comment
Share on other sites

I checked my php.ini and xwampp has a setting if 128m for memory_limit.  And even though memory_limit is set to 128m I added "ini_set("memory_limit", "30M");" anyway and I still got the same message.

 

Like I said in my first post I can up large load images if I don't use  imagecreatefromjpeg() so memoy_limit shouldn't be the problem, I think.

 

Thanks

SJ

Link to comment
Share on other sites

OKay

 

I was looking at http://php.net/manual/en/function.imagecreatefromjpeg.php and noticed a lot of the problems came from cannon cameras so I tried photos from another camea and the code worked like a charm.

 

Now all I got to do his find out how to get it to work with all cameras. I guess I am a php "Irregular" cause right now I'm going for a walk.

 

Thanks for the help ChemicalBliss, maybe I can get this ironed out later.

 

SJ

Link to comment
Share on other sites

There seems to very little info on this and after looking & playing I've found problems on the internet with several different cameras and even a mention of IE.

 

When I took the problem pics and save them again at same size the code worked.  Last I tried to upload to coppermine & got "The image you have uploaded is corrupted or can't be handled by the GD library". Sooo I'm going to go with that for now.

 

All these pics are from a friend and I haven't contacted them to see what type of camera they use.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.