Image resizing Edge Function runs out of memory

Does anyone have any recommendations on how to resize a 20MB image (reduce the total pixels and compress the the file) in an Edge Function? I'm asking because I created something using ImageMagick wasm but it only works on images that are already less than about 3MB, which isn't too helpful. If Edge Functions can't do it, I'm going to have to consider a third-party API but the round trip on 20MB images is going to be brutal and was hoping an Edge Function could handle it… I'm happy to share code but maybe someone knows of a recipe that solves this problem? TIA Ted Stresen-Reuter
6 Replies
Scott Steinlage
Scott Steinlage4mo ago
For a 3rd party: maybe cloudconvert. If not, a lambda might be something to look into. Lot's of mem to use there. More complex though..
Ankur
Ankur4mo ago
Try with https://github.com/lovell/sharp library - May be that works.
GitHub
GitHub - lovell/sharp: High performance Node.js image processing, t...
High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library. - lovell/sharp
tedmasterweb
tedmasterwebOP4mo ago
Apparently, Edge functions do not support multithreaded applications such as sharp… (I don't have the exact URL where I read that but I distinctly recall reading it on the Supabase documentation). If it did support sharp, however, that would be ideal. Thanks!
tedmasterweb
tedmasterwebOP4mo ago
Image Manipulation | Supabase Docs
How to optimize and transform images using Edge Functions.
tedmasterweb
tedmasterwebOP4mo ago
>Edge Functions currently doesn't support image processing libraries such as Sharp, which depend on native libraries. Only WASM-based libraries are supported.
tedmasterweb
tedmasterwebOP4mo ago
In the end I've abandoned this approach as Supabase states in their documentation that you can't really use Edge Functions for images larger than about 5MB. I've submitted a PR to their documentation to call out this limitation more clearly (and hopefully save some poor soul days of lost work): https://github.com/supabase/supabase/pull/36656
GitHub
Emphasize resource limit issues by tedsecretsource · Pull Request ...
Moved the caution on resource limit exceeded issues to the top of the document. Also added a little text to the introductory paragraph to call this out as a limitation. I have read the CONTRIBUTING...

Did you find this page helpful?