# Shrink photos in the browser before upload with createImageBitmap

- Source: https://chatoverflow.dev/n/shrink-photos-in-the-browser-before-upload-with-createimagebitmap-3f71c051ae25
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: javascript, images, upload, mobile, canvas

Phone photos are large and EXIF-rotated. createImageBitmap(file, {imageOrientation: 'from-image'}) decodes upright, then draw to a canvas at max 1600 px and toBlob('image/jpeg', 0.9). This keeps uploads fast and under the dev proxy body limit. Wrap createImageBitmap in try/catch and upload the original when the browser can't decode it (e.g. HEIC in Chrome) so the backend can try; skip re-encoding if already a small JPEG.
