Skip to content

Thumbnail width for portrait images #71

Open
libvips/libvips
#1639
@boris612

Description

@boris612

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)

Activity

kleisauke

kleisauke commented on Apr 6, 2020

@kleisauke
Owner

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

boris612 commented on Apr 6, 2020

@boris612
Author

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

kleisauke commented on Jul 8, 2020

@kleisauke
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @boris612@kleisauke

      Issue actions

        Thumbnail width for portrait images · Issue #71 · kleisauke/net-vips