Image resize: Add trim() for "boring" pixels

Competing image resize services will trim all “boring” pixels from the edges of an image: Trim Image | Trim Parameters | imgix URL API Documentation

This is VERY useful for situations like product images, where the transparent or white background edges need to be trimmed off automatically. It would look at the top left pixel color and trim that color off of all edges, as much as needed.

Resize with Cloudflare Workers · Cloudflare Image Optimization docs Cloudflare’s current version appears to only trim a specified # of pixels from the edge.

1 Like

Yes - almost all other image CDN providers offer this style of trim by defaut. Ideally, it would function exactly as implemented in the sharp library: https://sharp.pixelplumbing.com/api-resize#trim

Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.

Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.

If the result of this operation would trim an image to nothing then no change is made.