Allowed memory size of 268435456 bytes exhausted

I have backlight 3.1.3 installed and have been uploading files to various albums. I have a few files that I can’t upload and which give the error:

“The photo could not be uploaded: Unexpected error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in ImageResizer.php on line 52”

When this happens, the file is in a group (of 12 or so) being uploaded together. I try just that file by itself and it still fails. From today, one file was 15MB and one was 21MB. I have been uploading larger files without any problem, so I don’t think it’s file size.

The upload appears to be working fine, and it’s only at the very end, when it got to 100%, that the error appears

All of the JPEGs were saved by Photoshop. I can’t think of anything remarkable or different about the files that fail.

Any clues why this failure occurs? Is there a workaround I could try?

Many thanks

Hi @joannsnover, the issue here is that your PHP installation is configured to provide a maximum of 32MB of memory for each page call. Resizing converts images to bitmaps during processing, which requires significantly more memory than the equivalent JPEGs.
I suggest increasing the memory limit to 128MB or more. How you do that will depend on your host. Can you see if there is a way of configuring that in your host’s control panel?

Also, those file sizes are very large and probably much larger than needed for images shown on the web. I would only use such large files if I was providing high resolution for download or for sale. Exporting images at lower size and quality may help avoid hitting memory limits.

Ben, thanks for the information. My host is Bluehost and I just checked the php.ini in the site’s directory and it’s set for 128MB (it already was):

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M

I am intending to license my images, so I am uploading full size JPEGs that are scaled down and watermarked for display, but need to be the size they are.

Bluehost’s help file says it isn’t recommended to increase the limit beyond 128MB (but it doesn’t say what will happen if you do :slight_smile: )

Any suggestions? I can, if it’s only a few files, create downsized versions that Backlight can process, but it’s tough that I can’t predict from the file size what will work and what won’t. Either way I think it’d be helpful to document limits like this to avoid problems with anyone wanting to use Backlight to handle image licensing

The number in the error message, 268435456, corresponds to 32MB. (32 x 1024 x 1024 x 8)
so it looks like the setting you’re seeing isn’t being applied. The actual value being used can be seen by clicking on PHP Info on the main Backlight landing page. Look for Memory Limit.
That page will also tell you the file locations of the php.ini file(s) that have been read, which may indicate it’s been set up elsewhere. Another place where it may have been set is is in the .htaccess files at the top of your site or within the backlight directory.

The risk of allocating too high a limit is that for a memory-hungry site, that too many users will cause an impact on the available memory for other applications and sites on that server. Normal web usage should not use anything near to that limit. Image processing upon upload is likely the most memory-intensive task that Backlight performs, and that can only be done by the admin user.

This isn’t my thread, but I don’t understand your calculation of 32MB being equal to 32x1024x1024x8. That looks to me like 256MB, not 32MB.

I looked at Backlight’s PHP info table and it says 256M in both columns (Local Value & Master Value)

PHP version is 7.3.23

In case it helps, here’s last night’s part of the error log

[23-Oct-2020 00:12:25 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32768 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 00:16:20 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32768 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 02:56:51 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 03:05:50 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 03:13:40 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 03:49:48 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32768 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 03:58:50 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 40960 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 03:59:19 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 40960 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 03:59:19 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 36864 bytes) in Unknown on line 0
[23-Oct-2020 03:59:31 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32768 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 04:00:22 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 40960 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 04:00:22 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 36864 bytes) in Unknown on line 0
[23-Oct-2020 04:06:23 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32768 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 04:06:50 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 36864 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 04:07:43 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 40960 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 04:08:59 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 36864 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52
[23-Oct-2020 04:26:42 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 24576 bytes) in /home4/digitdt6/public_html/blog/backlight/modules/module-publisher/application/helpers/ImageResizer.php on line 52

You forgot the 8 bits to a byte. It’s 256 mega bits. Divide by 8 to get 32 MB

The error message is referring to bytes, not bits.

You’re right.

Ben is, I think, one of the developers, so perhaps he can say if the error log & message are wrong (i.e. it should say bits) or if they really need 256MB memory to handle re-sizing a 20MB JPEG.

If the latter, then there’s a big issue with using Backlight to upload licensable (full size) files.

I saw in the PHP info that ImageMagick is being used and my previous site (using some now unsupported plugins) used that too for watermarking and making smaller versions of uploaded full size images. It was fine with a 128MB memory_limit in that environment

Hi Jo Ann,

I’d like to try to see if I can duplicate this. I assume you’re using Backlight Publisher to upload the images? What are sizes of the images being created? Are you having Backlight create renditions for purchase? What size?
Anything special about the file names of the images that are failing? Do they all use letters, numbers, underscores, or hyphens? No spaces, decimal points, commas or special characters?

Rod, I am using Backlight Publisher and the images which fail are large-ish (12-21 MB JPEGS), but they aren’t the largest images. In other words, many larger ones have worked fine

The file names are letters (mixed case) with hyphens and underscores in many. The only period is in the .jpg extension. As an example (this one worked) MM-buoy line in vivid lake 130819_0038.jpg is typical. There are spaces. I never use other characters to minimize problems with older-style file systems.

To get Backlight to give me the uploaded size for purchase, I’ve said 9999 x 9999 pixels is the size to create and that appears to give me “originals” (I just tried to find where I’d set that, but I couldn’t. I know it’s somewhere, but I’ve no clue whether this is an album, gallery, page, cart or other attribute; you can tell I’m still really struggling with the organization. As an aside, it would be great if one could search the documentation).

You can look at the masters and photos-for-purchase for one album in this screenshot from my FTP software; I think the items for purchase are unchanged from the masters if you look at file sizes

The images for display are 2000 x 1500, in case that matters. If it helps, I can put some of the failing images online so you can use them to debug (assuming it’d fail in all uses, just in my setup)

the 9999x9999 size can be set in the album template in the Cart Add-on under Generate Photos for Purchase.
I’m assuming that the images you’re uploading are at least that large. I don’t really know how Backlight Publisher is resizing images or if it’s capable of enlarging.
Are any of the images you’re uploading smaller than 9999px on the long side?

Thanks for the locator on where to find the purchase size settings.

None of my images are as big (on either edge) as 9999 pixels and given the sizes match the originals, I’m fairly certain that there’s no enlarging going on.

What I want to happen is for the files I upload to be the files for purchase, but there didn’t seem to be any other way to get a “leave this as is” result.

With the exception of the handful of files that fail, I’m able to get what I’m after, even though the interface - specifying the largest possible pixel dimensions - is rather indirect.

Well this is embarrassing. My original calculation was incorrect. That figure is indeed 256MB. I had treated the number as bits, not bytes.

:slight_smile:

So I started looking at pixel dimensions instead of JPEG file size to see if that might be a reason for the ones that fail. Could that be a factor in why things fail? I have several square images 5616 x 5616 pixels and even when they are 11MB or so, they fail

I just tried to upload a test file - 5616 x 5616 pixels saved at JPEG level 4 (very low) - it was 1.9MB in size. It failed.

Not sure what the threshold is, but I think it’s not file size. Given that nothing is being enlarged to meet the 9999 x 9999 purchase size I specified (in the ones that succeed) I’m still puzzled as to why this might be.

I did two more test files at 5400 x 5400 (failed) and 5000 x 5000 (succeeded)

I really don’t want to downsize my images, so is there a possibility of a fix for this?

The memory requirement is indeed determined by the size in pixels. The resizer reads the JPEG into a single bitmap and uses that single bitmap to generate the resized images.

You said above that your images for display are 2000 x 1500. Do you have any higher images, such as for download or purchase? If that’s the highest then you shouldn’t be losing any visual quality by starting off with renditions smaller than ~5000x.

What version of PHP is your site running? If you’re still on version 5.x then upgrading to the highest available version of 7.x may alleviate some of the memory overhead.

My images available for licensing are all large and I don’t want to change their size; just to create a smaller watermarked display size for the galleries. And then to be able to license the original images as and when a buyer needs one.

If I switch over to Lightroom (not my preference but I have it) can I avoid this issue with difficulties generating the display sizes?

If you read the

give it a try with a test album. See what happens. As long as you don’t have “Master Images” set to Yes in Backlight > Settings > Publisher > Publish Master Renditions from Lightroom, then Lightroom would be generating the renditions rather than Backlight.

Ben,

I’m getting the same error trying to upload full sized images via Backlight Publisher. Out of four images, only one was uploaded. I tried it with a template that had cart renditions created at 9999 x 9999 and and also another album with the same images using template that was creating renditions closer to the actual size of the images, 7360 x 7360.

Each album uploaded only one image, and it was the same image. The only real difference was that one image was cropped to a pano rather than the full 3:2 ratio.

I had no problems publishing the same images using the template with cart renditions set at 9999 x 9999 Lightroom.