Automatic height using Vips::thumbnail()?
Hi, I've only recent started using this library in a project.
I'm using the thumbnail method, which is incredibly fast, however, I haven't found a way of generating a thumbnail with a given width, and and an automatically generated height.
As a workaround I'm doing:
$originalImage = Vips::newFromFile($tempFullPath . '.' . $imageFormat);
$aspectRatio = $originalImage->width / $originalImage->height;
$height = 250 / $aspectRatio;
$image = Vips::thumbnail($tempFullPath . '.' . $imageFormat, 250, ['height' => $height]);
$image->writeToFile($tempFullPath . '_thumb.jpg');
But surely there's a better way isn't there ??
Hello, you can just give a large value for height, and then size will be constrained by the width. Or vice-versa, of course.
@kleisauke is proposing adding something to make this more obvious, but it's not gone in yet.
You can see the logic the command-line vipsthumbnail program uses to parse geometry strings here:
https://github.com/jcupitt/libvips/blob/master/tools/vipsthumbnail.c#L303