I'm using the functions provided in the GD Library to generate thumbnails and preview images for larger files that are uploaded to my server.

Everything works fine except when JPG files are too big. For instance, I have a 1mb JPG file that produces a "500: Internal Server Error" message.

I thought maybe it was the JPG formatting. I tried saving this image in baseline-standard, baseline-optimized, and progressive. The result was the same on every format.

Then, I thought maybe that the image was corrupt, so I opened up photoshop and created a 360dpi image, drew random shapes, and saved it as a new baseline JPG. This file errored in the same way.

I think that when a file gets too big it causes GD to crash and send back the error message. Files about 600k worked. It's only when they get a bit larger, that I receive this problem.

Does the GD library specify the exact pixel dimensions it can process? If so, is there a way I can increase the maximum image size that it can handle? Do I need to find a different library that can handle large files?

    UPDATE:

    I went through some images I had and uploaded them one at a time: 600k, 700k, 800k, 900k, 1mb, 1.1mb. I was surprised that all of these files uploaded successfully.

    Then, it hit me. The resolution is the problem. JPG files have pixel dimensions, but they also have resolutions. Because the photo I tried to upload was 360dpi, it caused the crash.

    Is there a GD function that can change the resolution of an image from 360dpi to 72dpi?

      Update:

      I made two copies of one file. Both had the same pixel dimensions, but different resolutions (72dpi and 300pdi). They both cause an error.

      so....

      I don't think the file size itself is NOT causing the error. I tried a flat black JPG (about 50k) and it still errored on the server because the pixel dimensions were too large. (i think this is why)

      So, if the GD function copyResized() is not working on images with a large pixel area, does this mean the server is timing out before the operation can complete?

        OK, my server is sizing images all the way up to 4million pixels. (This would be a square image 2000x2000 pixels).

        I still cannot figure out if it's a server thing, or if its a restriction of the GD library.

          Write a Reply...