Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail width for portrait images #71

Open
boris612 opened this issue Apr 1, 2020 · 3 comments · May be fixed by libvips/libvips#1639
Open

Thumbnail width for portrait images #71

boris612 opened this issue Apr 1, 2020 · 3 comments · May be fixed by libvips/libvips#1639
Labels
question Further information is requested

Comments

@boris612
Copy link

boris612 commented Apr 1, 2020

ThumbnailImage method allows a user to specify only width, but it does not work correctly for portrait images (or it is not correctly documented)
For example, if you write the following code

var image = Image.NewFromFile(filename);
Image thumbnail = image.ThumbnailImage(300);

for the image with dimensions 600x900 then it would produce 200x300 thumbnail instead of 300x450.
It appears that it translates to vipsthumbnail.exe -s 300 instead to vipsthumbnail.exe -s 300x

A workaround is to calculate height or to give some large value for height
Image thumbnail = image.ThumbnailImage(300, height: a big enough number)

@kleisauke kleisauke added the question Further information is requested label Apr 6, 2020
@kleisauke
Copy link
Owner

kleisauke commented Apr 6, 2020

This is a known issue in libvips. See libvips/libvips#709 for a future possible enhancement.

A workaround is to calculate height or to give some large value for height
Image thumbnail = image.ThumbnailImage(300, height: a big enough number)

Indeed, you can set the target resize height to VIPS_MAX_COORD (which is currently 10000000) to prevent reduction or enlargement in the vertical axis and vice versa for the target resize width (that's what vipsthumbnail does).

var image = Image.NewFromFile(filename);
Image thumbnail = image.ThumbnailImage(300);

You could use Image.Thumbnail instead. Because the image has already been opened, it can't do any of the shrink tricks that makes thumbnailing fast. #64 might be relevant here.

@boris612
Copy link
Author

boris612 commented Apr 6, 2020

Thanks for the info, it solves the problem. Just a suggestion. Maybe you could write a similar note in the method summary, and/or define public constant VIPS_MAX_COORD and set default height value to it instead to null.

kleisauke added a commit to kleisauke/libvips that referenced this issue May 3, 2020
This is to prevent reduction in the vertical axis when the height is omitted.

See: kleisauke/net-vips#71.
kleisauke added a commit to kleisauke/libvips that referenced this issue May 3, 2020
This to prevent reduction in the vertical axis when the height is omitted.

See: kleisauke/net-vips#71.
@kleisauke
Copy link
Owner

See libvips/libvips#1639 for a draft that changes the vips_thumbnail into a resize based on a specific axis. Any feedback is welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants