Description
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 commentedon Apr 6, 2020
This is a known issue in libvips. See libvips/libvips#709 for a future possible enhancement.
Indeed, you can set the target resize height to
VIPS_MAX_COORD
(which is currently10000000
) to prevent reduction or enlargement in the vertical axis and vice versa for the target resize width (that's whatvipsthumbnail
does).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 commentedon 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.Default height to VIPS_MAX_COORD for vips_thumbnail
Default height to VIPS_MAX_COORD for vips_thumbnail
kleisauke commentedon Jul 8, 2020
See libvips/libvips#1639 for a draft that changes the
vips_thumbnail
into a resize based on a specific axis. Any feedback is welcome!