sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Extend to a specified width and height in single operation without knowing the prior width or height

Open twilson90 opened this issue 1 year ago • 1 comments

It appears extend() only allows inputs of left, right, top and bottom, but it would be really convenient if there was a way to extend an image to a specified width or height without having to calculate the images width or height and using the differences in extend(), or using toBuffer on the image and creating a new image using composite(), both of which require async operations.

Is this already a feature? If not it would be nice.

twilson90 avatar Jun 07 '24 11:06 twilson90

If you only want to extend along one axis ("letterbox") then .resize({ width, height, fit: 'inside' }) kind of does this.

Otherwise, yes, you'll need to calculate this using the metadata. Although it is async, the metadata() call is usually very fast as it does not decode any pixel data.

lovell avatar Jun 07 '24 14:06 lovell

I hope this information helped. Please feel free to re-open with more details if further assistance is required.

lovell avatar Jul 02 '24 08:07 lovell