Hacker News new | ask | show | jobs
by kiwicopple 1279 days ago
> The blog post states "default mode maintains aspect ratio and the resize mode is fill", but the docs say that cover is the default mode.

The default resize mode is cover and the blog post had a typo. Fixed now, thanks!

> resize or crop

We crop by default since the default mode is cover.

> gravity

we will be adding crop with gravity soon.. currently the crop is always from the center

> requesting an image at a specific aspect ratio while not exceeding a maximum size.

I'll get back to you on this one - Inian had to get some sleep, it's very late (early) for him

1 comments

Thank you for following up. IMHO, object-fit is not the right model for server-side image manipulation, since its behavior is only specified when both width and height are supplied. I've also never seen a real world use case for stretching, squeezing, padding, or enlarging images on the server. That should be done on the client. I mentioned some of the same issues on the Cloudflare forum when they announced an image resizing product based on object-fit.

I believe all resizing operations a user might realistically want can be achieved with three parameters: width, height, and crop. Additional x and y parameters (floats between 0.0 and 1.0) could be used for setting the focal point of the crop box.

Examples:

  source.jpg?width=400
Iff source width is greater than 400px, scale down to 400px wide.

  source.jpg?height=300
Iff source height is greater than 300px, scale down to 300px high.

  source.jpg?width=400&height=300
Iff source width is greater than 400px or source height is greater than 300px, scale down to fit within a 400px by 300px box.

  source.jpg?width=400&height=300&crop=true
Crop source to a 4x3 aspect ratio. Iff result is larger than 400px by 300px, scale down.