h2non / bimg

Go package for fast high-level image processing powered by libvips C library
https://pkg.go.dev/github.com/h2non/bimg?tab=doc
MIT License
2.69k stars 337 forks source link

Fit given dimensions without enlarge and keep aspect ratio #257

Open dmzkrsk opened 6 years ago

dmzkrsk commented 6 years ago

Probably related to #93

I have a 178x31 image and I want to fit it in 1000x20 box I expect that it will be shrinked down to 114x20 pixels

I apply options

{Width: 1000, Height: 20, Embed: true}

And recieve 1000x20 image (it's upscaled to 1000x174 and then cropped)

If both Width and Height are larger than my image

{Width: 1000, Height: 50, Embed: true}

I get correct 178x31 original image

Chaning math.Min to math.Max in resizer.go:456 produces correct aspect ratios and sizes, but final image get padded to requested Width/Height

Removing Embed and call to normalizeOperation gives me correct results

Anything wrong here?

dmzkrsk commented 6 years ago

PR sent