Is there a way to get the size of an image after resizing?
See original GitHub issueDoes Sharp offer a simple way to get the size of an image after it has been resized?
Here’s roughly what I’m trying to accomplish:
const image = sharp(filepath);
// do other stuff with `image`
const thumbnail = image.clone().resize({height: THUMBNAIL_HEIGHT, fit: "inside"});
I’m using the inside fit option to automatically determine the correct width for the resized image. I thought Sharp#metadata()
might be useful but then I read this line in the docs:
It does not include operations, such as resize, to be applied to the output image.
Does Sharp support what I am trying to accomplish?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Get actual image size, after resizing it - javascript
function getImageDimensions(path,callback ){ var img = new Image(); img.onload = function(){ callback({ width : img.width, height : img.height }); ...
Read more >How to resize your images quickly and easily | ZDNET
Locate the W x H x Resolution menu at the top of the screen. Then, click on the left drop-down and click W...
Read more >How to Resize and Make Images Larger without Losing Quality
Open the file in Photshop, click on “image size, un-check “Resample image”, then start adjusting the pixel size under width until you reach...
Read more >How to Resize an Image [from Any Device] - Alphr
1. Open one of your favorite browsers and visit TinyWow.com. 2. Hover your mouse to the Image tab and click Resize Image Dimension...
Read more >How to Resize an Image | Digital Trends
1. Right-click on the image and select Open With followed by Photos. 2. Click the Three-Dot button located in the app’s top-right corner....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @rawpixel-vincent, I adapted your example with an async variant.
The size can then be accessed at
info.size
and the buffer is available atdata.buffer
.Hope this helps someone else.
@Enchiridion The call to
toBuffer()
(ortoFile
, orpipe
) triggers the pipeline and starts the calculations. If you need the output dimensions before the output is generated then you’ll have to calculate these in your own code.