+ Reply to Thread
Results 1 to 5 of 5

Thread: Memory exhauted on a GD beforecreatefromjpeg function

  1. #1
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Memory exhauted on a GD beforecreatefromjpeg function

    Hello.

    I'm trying to resize a client image before insert it into my web site. The image is choosen on the client post throught a form, and is correctly obtained. It's accessible by $_FILES['fileNameAIns'] array.

    PHP Code:
      $max_cote 1600;
      list(
    $wOri$hOri) = getimagesize($_FILES['fileNameAIns']['tmp_name']);
      
    $ratio $wOri $hOri;
      if (
    $wOri $hOri) {
        
    $modWidth $max_cote;
        
    $modHeight $max_cote $ratio;
      }
      else {
        
    $modHeight $max_cote;
        
    $modWidth $max_cote $ratio;
      }
      
    $tn imagecreatetruecolor($modWidth$modHeight);
      
    $imageOri $_FILES['fileNameAIns']['tmp_name'];
      echo 
    '<br />before imagecreatefromjpeg:'.$imageOri;
      
    $image imagecreatefromjpeg($imageOri);
      echo 
    '<br />before imagecopyresampled';
      
    imagecopyresampled($tn$image0000$modWidth$modHeight$wOri$hOri);
      echo 
    '<br />before imagejpeg';
      
    imagejpeg($tn); 
    the last messages I find on the page is :
    Code:
    <br />before imagecreatefromjpeg:C:\xampp\tmp\php1624.tmp<br />
    <b>Fatal error</b>:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 3072 bytes) in <b>C:\xampp\htdocs\jardin\inc\gesJardin.inc</b> on line <b>82</b><br />
    Line 82 is the imagecreatefromjpeg function.

    Could someone show me where I'm wrong please ?

    Just a precision : on the disk of client machine, the image size is 3,05 Mo.
    Last edited by fomalhaut; 06-30-2010 at 08:10 AM.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Memory exhauted on a GD beforecreatefromjpeg function

    1. Is this on x10hosting? The memory limit is supposed to be 64M

    2. Apparently imagecreatefromjpeg can be a memory hog. See: PHP manual for imagecreatefromjpeg and search the page for 'channel'

    Quoting from one of the posts...

    The memory required to load an image using imagecreatefromjpeg() is a function
    of the image's dimensions and the images's bit depth, multipled by an overhead.
    It can calculated from this formula:
    Num bytes = Width * Height * Bytes per pixel * Overhead fudge factor
    Where Bytes per pixel = Bit depth/8, or Bits per channel * Num channels / 8.
    This script calculates the Overhead fudge factor by loading images of
    various sizes.
    Nothing is always absolutely so.

  3. #3
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Re: Memory exhauted on a GD beforecreatefromjpeg function

    Thank you very much descalzo.
    1. No, it was not on x10, because I test my application on my localhost. So the memory limit is probably 32Mo.

    2.I've add before the image manipulation the function ini_set('memory_limit', '100M')...

    3. ... and it works well !

    Thanks again. I'll go further into the memory management.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Memory exhauted on a GD beforecreatefromjpeg function

    Quote Originally Posted by fomalhaut

    2.I've add before the image manipulation the function ini_set('memory_limit', '100M')...

    3. ... and it works well !

    .
    Be aware that you cannot set the memory limit on x10. If you want to test the script to see if it will work on x10, set the memory limit to 64M on your local script.
    Nothing is always absolutely so.

  5. #5
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Re: Memory exhauted on a GD beforecreatefromjpeg function

    Hello Descalzo

    Yes, of course, you are right. I've made some tests on my owm machine and I can limit the memory at 40Mo, but as a precaution, I code
    PHP Code:
    ini_set('memory_limit''50M'); 
    This is sufficient.

    Thanks again and have a good day.

+ Reply to Thread

Similar Threads

  1. too much memory being used
    By scylla in forum Free Hosting
    Replies: 8
    Last Post: 01-06-2010, 03:37 PM
  2. Memory Problem
    By liguehs in forum Free Hosting
    Replies: 1
    Last Post: 08-23-2009, 01:40 PM
  3. What kinds of USB memory stick are suitable for use as Vista memory
    By frankfriend in forum Computers & Technology
    Replies: 16
    Last Post: 07-09-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers