Skip to content

Conversation

@joelochlann
Copy link
Member

@joelochlann joelochlann commented Jan 29, 2026

Depends on #4608, currently diffed to that branch

how to test

  • run npm run test:integration and see the large image tests now pass
  • deploy to test and look at the logging for images coming in. check:
    • How much to they get resized to?
    • How many attempts does it take?
    • Do we ever run out of attempts?
    • What is the CPU and memory usage of the lambda?

@joelochlann joelochlann requested a review from a team as a code owner January 29, 2026 10:08
// We use sqrt because scaling affects both dimensions
const sizeRatio = MAX_IMAGE_SIZE_BYTES / imageBytes.length;
// Be conservative: target 80% of max size to account for compression variance
let scaleFactor = Math.sqrt(sizeRatio * 0.8);
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to think through if this square root thing is actually right... 🤔

You have a 4x4 image = 16 pixels = (let's pretend one byte per pixel, uncompressed) = 16 bytes
You want to halve the size to 8 bytes
If you simply halve the width & height to 2x2, you'll get 4 pixels = 4 times smaller than 16 bytes

Whereas if you scale width & height by 1/sqrt(2) you get:
about 2.8 * 2.8 = 7.84 = about 8

OK I get it!

@joelochlann joelochlann added the feature Departmental tracking: work on a new feature label Jan 29, 2026
@paperboyo
Copy link
Contributor

Brute force seems the only way to ensure they will fall below certain filesize indeed. Sharp is a good choice (based on Vips) if lambda can haz any.

Without either reading about model behaviour with different resolution/compression and other characteristics (eg. does transparency even matter?) or doing a lot of tests, it’s impossible to know what are the best compromises (better larger and more compressed or the other way around? fine to bake transparency into JPEGs or is transparency taken seriously? etc).

One thing I can’t think wouldn’t be sensible is to convert everything to sRGB (this, I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants