Using image shrink with large files


I have a site where users can upload images to decorate their pages. As I can’t control what they’ll try to upload and I’m trying to keep the storage usage down I’ve added the image shrink parameter to the widget (with a value of ‘1600x1600 80%’). I noticed that some large files are still being uploaded, so I checked the docs again and see that it says the shrink is not applied “if the original resolution / target resolution ratio falls behind 2.0”.

Is there any way to force the shrink to happen in these scenarios? I understand that I could add a validator to set a max file size, though ideally I wouldn’t need to get the users to go away and resize the images elsewhere before upload.


Hi @nickeday

There’s no way to avoid the limitations of the shrink – it works if the resolution of the original image is two or more times larger than the desired resolution. Talking about large files, what file size are you referring to? Are those larger than 10 MB?

Hey @Alex, thanks for the quick response. I’ve realised I was being dense and misunderstanding the instructions! I’d read it as not working if the the resolution is two or more times larger :expressionless:

I was seeing images ~20Mb being uploaded so I suppose with my desired resolution of 1600x1600, it’s possible the images could be higher resolution than that, but still less than 2x the resolution and so aren’t being shrunk. Either that or they’re being uploaded from social media?

There are three cases when the image shrink doesn’t work.

  • When a client browser does not support all the required APIs.
  • When images are uploaded from social media or URLs.
  • If the original resolution/target resolution ratio falls behind 2.0. For example, you can not shrink a 2560x1560px (4 MP) image to 1600x1600px (2.5 MP) while this works with a 2448x3264px (8 MP) original. The reason we implemented this limit is to preserve an optimal balance between a decline in quality and drop in file size.

Also, there is one thing that is not documented yet. Widget 3.6.2+ uploads files in the multipart mode if the file size is 10 MB or larger. Previously, this value was 25 MB. Images uploaded in the multipart mode are not shrunk hence if an image is larger than 10 MB it won’t be shrunk even if it matches other terms. If your use case requires shrinking larger images, you can increase the minimum file size for multipart uploading with this option

UPLOADCARE_MULTIPART_MUN_SIZE = 25 * 1024 * 1024 // set to 25 MB

Perfect, thanks @Alex. I’ll make use of that latter option too.

1 Like

Glad to help! I have to mention that the single-part uploads are not accelerated, so increasing the min size for multipart uploads could lower the uploading speed. We’re going to fix this issue in further updates.

Cool, thanks. I’m quite happy to forego some speed for lowering my storage usage for now!