imagecreatefromjpeg failing with lack of memory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Stewart

    imagecreatefromjpeg failing with lack of memory

    Has anyone else experience of imagecreatefrom jpeg failing with an error
    message about memory even though the size of the image being uploaded is
    nothing like the space available to the script?

    Is imagecreatefrom jpeg particularly memory hungry?

    Immediately prior to the failure memory is given as 2405072
    The jpeg being uploaded is 812201 in size
    Smaller jpegs work fine. jpegs created by different means all seem to fail
    if the size is around 500k plus.

    Error message is
    Fatal error: Allowed memory size of 16777216 bytes exhausted at (null):0
    (tried to allocate 3264 bytes) in
    /home/virtual/site216/fst/var/www/html/mv/private/mvaddinfoinc.ph p on line
    1997

    PHP version is 4.3.3 on a shared server
    GD version is bundled (2.0.15 compatible)
    Memory limit is set to 16M
    Max upload is set to 16M


    if (function_exist s('memory_get_u sage')) {
    $mem_in_use= memory_get_usag e();
    }
    else {
    $mem_in_use="me mory usage indeterminable" ;
    }
    dev_echo("memor y usage= $mem_in_use" );
    $src_img = imagecreatefrom jpeg("$temp_ful lpicname");
    if (!$src_img) {
    $GLOBALS[InfoMsg]->MsgAdd("Coul d not create image from jpeg");
    unlink ( $temp_fullpicna me);
    return false;
    }


  • Erwin Moller

    #2
    Re: imagecreatefrom jpeg failing with lack of memory

    Simon Stewart wrote:
    [color=blue]
    > Has anyone else experience of imagecreatefrom jpeg failing with an error
    > message about memory even though the size of the image being uploaded is
    > nothing like the space available to the script?
    >
    > Is imagecreatefrom jpeg particularly memory hungry?
    >
    > Immediately prior to the failure memory is given as 2405072
    > The jpeg being uploaded is 812201 in size
    > Smaller jpegs work fine. jpegs created by different means all seem to
    > fail if the size is around 500k plus.
    >
    > Error message is
    > Fatal error: Allowed memory size of 16777216 bytes exhausted at (null):0
    > (tried to allocate 3264 bytes) in
    > /home/virtual/site216/fst/var/www/html/mv/private/mvaddinfoinc.ph p on line
    > 1997
    >
    > PHP version is 4.3.3 on a shared server
    > GD version is bundled (2.0.15 compatible)
    > Memory limit is set to 16M
    > Max upload is set to 16M
    >
    >
    > if (function_exist s('memory_get_u sage')) {
    > $mem_in_use= memory_get_usag e();
    > }
    > else {
    > $mem_in_use="me mory usage indeterminable" ;
    > }
    > dev_echo("memor y usage= $mem_in_use" );
    > $src_img = imagecreatefrom jpeg("$temp_ful lpicname");
    > if (!$src_img) {
    > $GLOBALS[InfoMsg]->MsgAdd("Coul d not create image from jpeg");
    > unlink ( $temp_fullpicna me);
    > return false;
    > }[/color]

    Hi Simon,

    I think you have to estimate how much memory is needed for your jpg to store
    it in memory with truecolor.
    jps is a heavily compressed format, so your 500K filesize doesn't say a lot.
    You need to use the pixels. (width times height)

    example:
    If your jpg is 2000X2000 pixels, that is 4.000.000 pixels.
    If stored truecolor you need (i think)
    1 byte R
    1 byte G
    1 byte B
    1 byte alpha channel (transparancy)

    So that is 4.000.000 times 4 bytes is around 16 megs.

    (Note: I am unsure if PHP will want to allocate all that memory when it
    creates an image based on a JPG. I could be possible to use only a part,
    but I expect PHP to want to load it all in memory.)

    Solution is simple: Try to increase the memory allocated to PHP in php.ini
    to get around this problem. Or use smaller images.

    Regards,
    Erwin Moller



    Comment

    • Simon Stewart

      #3
      Re: imagecreatefrom jpeg failing with lack of memory

      Erwin
      Thanks for your comments. It turns out that with around 13.5Mb free, I
      could upload a picture of around 2430000 pixels. This seems to be
      equivalent to roughly 5.5 bytes per pixel at least for the picture I was
      testing with.
      Simon Stewart.

      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:4125ce66$0 $568$e4fe514c@n ews.xs4all.nl.. .[color=blue]
      >
      > Hi Simon,
      >
      > I think you have to estimate how much memory is needed for your jpg to[/color]
      store[color=blue]
      > it in memory with truecolor.
      > jps is a heavily compressed format, so your 500K filesize doesn't say a[/color]
      lot.[color=blue]
      > You need to use the pixels. (width times height)
      >
      > example:
      > If your jpg is 2000X2000 pixels, that is 4.000.000 pixels.
      > If stored truecolor you need (i think)
      > 1 byte R
      > 1 byte G
      > 1 byte B
      > 1 byte alpha channel (transparancy)
      >
      > So that is 4.000.000 times 4 bytes is around 16 megs.
      >
      > (Note: I am unsure if PHP will want to allocate all that memory when it
      > creates an image based on a JPG. I could be possible to use only a part,
      > but I expect PHP to want to load it all in memory.)
      >
      > Solution is simple: Try to increase the memory allocated to PHP in php.ini
      > to get around this problem. Or use smaller images.
      >
      > Regards,
      > Erwin Moller
      >
      >
      >[/color]


      Comment

      Working...