Skip to content

Compress large images for form submissions - #772

Open
icycoldveins wants to merge 8 commits into
developfrom
769-compress-image-uploads
Open

icycoldveins wants to merge 8 commits into
developfrom
769-compress-image-uploads

Conversation

@icycoldveins

@icycoldveins icycoldveins commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request

Change Summary

  • Compress images over 5 MB before upload in the Add a Site and Suggest an Edit forms
  • Downscale to a maximum 2048px dimension and re-encode as JPEG, stepping down quality and dimensions until the file fits
  • Stop rejecting large files in the dropzone so the compressed image is what gets uploaded
  • Keep animated GIFs untouched to preserve their frames
  • Fix the image field update so the uploaded image key is stored in the form's images field
  • Add a desktop Cypress spec that drops a 20 MB PNG and asserts the uploaded image is JPEG and under 5 MB

Change Reason

Images over 5 MB were rejected by the uploader, so the form submission went through without the selected image. Users should be able to pick an image of any size and let the app handle the compression.

Related Issue: #769

field.onChange from useController takes a single value, so passing ('images', [data]) set the field to the string 'images' and the resolved schema rejected every submission that included an image.
Photos over 5 MB were rejected by the dropzone, so the resource forms silently submitted without an image. Downscale to 2048px and re-encode as JPEG (quality steps, then dimension steps) until the file fits, for both the Add a Site and Suggest an Edit forms. Animated GIFs pass through untouched.
Generates a 20 MB noisy PNG, drops it into the Add a Site form, and asserts the signed upload request switches to image/jpeg and the resource is submitted with the uploaded image key.
Compression runs silently, and the extra copy just cluttered the dropzone. The uploader now shows only the accepted formats and the selected filename.
Hand-rolled canvas decode/resize/quality-stepping duplicated what a
maintained library already solves, and ran entirely on the main thread.
browser-image-compression gives the same behavior (downscale to 2048px,
JPEG output, skip GIFs/already-small files) plus Web Worker offloading
for free, at a fraction of the code.

@nathanktruong nathanktruong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented with a recommendation for a simpler implementation, ahead of this Saturday's walk!

Apart from the image compression strategy - removing the maxSize restriction and fixing the bug with onSuccess look good to me.

Comment thread package.json Outdated
browser-image-compression is unmaintained. Its last release was in March 2023. compressorjs is maintained, MIT licensed, and covers the same resize and JPEG conversion needs for image uploads.
No module imports formatFileSize, so the util is dead code. Removing it keeps the utils folder limited to code that has callers.
…-uploads

# Conflicts:
#	package.json
#	pnpm-lock.yaml
@icycoldveins
icycoldveins marked this pull request as ready for review October 20, 2026 22:58
@AnilKumar3494
AnilKumar3494 self-requested a review October 21, 2026 12:45

This branch was successfully deployed

1 active deployment
test — b6e36592 Deployed Oct 20, 2026 by icycoldveins via build / build #2429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants