imagecreatefromjpeg problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve park

    imagecreatefromjpeg problem

    Hi everyone,

    this is one of those "inherited from someone else" projects that I'm having
    problems with and was wondering if someone could help me out.

    Our setup:

    Redhat Linux
    Apache 2.0.46
    PHP 4.3.2
    GD 1.8.4

    We have a php-based setup that allows users to upload images and then some
    back-end stuff that stores the original image and creates a thumbnail image.
    I've just noticed that large images, say 1500x1500 or larger, give the
    resize script some problems. We're using Shiege Iseng's resize class
    (http://kentung.f2o.org/scripts/thumbnail/).

    The error is coming when the class calls the imagecreatefrom jpeg() function,
    and the specific error is

    Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to
    allocate 8652 bytes) in <servername>/resize.php on line 51

    The image itself is 2163x2957x24bpp at 300 dpi and is 3 megs on disk and
    18.31 MB in memory, according to IrfanView.

    If I use IrfanView to reduce the image to, say, 1400x1800 or so then the
    resize script has no problems, so I guess there really IS a memory issue.
    ;-)

    I'm wondering:

    1. will the problem go away if I upgrade to GD 2.x?
    2. will the problem go away if I upgrade to PHP 5?

    It's doubtful that I'll be able to upgrade PHP or GD, though ...

    So, first of all, has anyone run into a problem like this? Second, what are
    my options? One big constraint is that the preferred solution is to let
    users upload images to whatever size they want, so setting a 1500x1500
    restriction before they upload isn't going to work.

    Thanks!




  • Peter van Schie

    #2
    Re: imagecreatefrom jpeg problem

    steve park wrote:[color=blue]
    >
    >
    > The error is coming when the class calls the imagecreatefrom jpeg() function,
    > and the specific error is
    >
    > Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to
    > allocate 8652 bytes) in <servername>/resize.php on line 51[/color]

    Hi Steve,

    You could try to get around this by adding a line like:

    ini_set("memory _limit","30M");

    at the top of your script.
    Upgrading PHP or GD won't solve this problem. It's just a sign that the
    resize script is pretty inefficient with memory. ;)
    HTH.

    --

    Comment

    • Andy Hassall

      #3
      Re: imagecreatefrom jpeg problem

      On 13 Jul 2005 18:12:10 -0400, spark@cc.gatech .edu (steve park) wrote:
      [color=blue]
      >We have a php-based setup that allows users to upload images and then some
      >back-end stuff that stores the original image and creates a thumbnail image.
      >I've just noticed that large images, say 1500x1500 or larger, give the
      >resize script some problems. We're using Shiege Iseng's resize class
      >(http://kentung.f2o.org/scripts/thumbnail/).
      >
      >The error is coming when the class calls the imagecreatefrom jpeg() function,
      >and the specific error is
      >
      > Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to
      >allocate 8652 bytes) in <servername>/resize.php on line 51
      >
      >The image itself is 2163x2957x24bpp at 300 dpi and is 3 megs on disk and
      >18.31 MB in memory, according to IrfanView.[/color]

      Can you simply raise the value of memory_limit?

      It's there to stop runaway scripts eating memory, but in this case you know
      you need that memory for a short time to do the processing.
      [color=blue]
      >I'm wondering:
      >
      >1. will the problem go away if I upgrade to GD 2.x?
      >2. will the problem go away if I upgrade to PHP 5?[/color]

      Wouldn't have thought so - you're using the memory, and so memory_limit is
      working as advertised.

      --
      Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
      <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

      Comment

      • chotiwallah

        #4
        Re: imagecreatefrom jpeg problem

        i had the same problem once: i got around by NOT using true color
        images, which reduces the needed memory tremendously (using
        imagecreate, not imagecreatetrue color)

        2 problems with that: 1st you might already be running out of memory
        just opening the uploaded image and 2nd you'd have to try if the
        quality is still sufficient for the thumbs.

        micha

        Comment

        • Andy Hassall

          #5
          Re: imagecreatefrom jpeg problem

          On 13 Jul 2005 18:12:10 -0400, spark@cc.gatech .edu (steve park) wrote:
          [color=blue]
          >Second, what are my options?[/color]

          Another option worth mentioning is running ImageMagick instead. As an external
          process, it's not subject to PHP's memory limits. And it can be faster as well.

          The downside is it needs you to run an external process (or load the
          ImageMagick PHP extension).

          --
          Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
          <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

          Comment

          • steve park

            #6
            Re: imagecreatefrom jpeg problem

            > Another option worth mentioning is running ImageMagick instead. As an external[color=blue]
            >process, it's not subject to PHP's memory limits. And it can be faster as well.[/color]

            turns out that doing something like

            ini_set( "memory_lim it", "200M" );

            has fixed the problem.

            Thanks!



            steve



            Comment

            Working...