Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crop image so fits exactly in max width and max height

See original GitHub issue

[REQUIRED] Step 2: Extension name

This feature request is for extension: storage-resize-images

What feature would you like to see?

Current behavior as in the documentation:

For example, say that you specify a max width of 200px and a max height of 100px. You upload an image that is 480px wide by 640px high, which means a 0.75 aspect ratio. The final resized image will be 75px wide by 100px high to maintain the aspect ratio while also being at or under both of your maximum specified dimensions.

Using that example parameters, I would like a final resized image of the exact size of max width and max height (200 x 100) instead of 75px x 100px. In that case, in order to maintain the aspect ratio, the image would be cropped.

How would you use it?

Is a common behaviour to show thumbnails (i.e. 56x56) in a list. It’s aesthetically better cropping the image instead of making it fit completely in that size.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

magoarcanocommented, May 22, 2020

Thanks. It’s just adding a new parameter fit at config.ts. And changing function resize at index.ts in line 157, puting fit instead of 'inside' so it can use that parameter.

return sharp(originalFile)
    .resize(parseInt(width, 10), parseInt(height, 10), { fit: "inside" })

I would make a pull request with the change, but I don’t get where in the code the user can choose that parameter (the screen that firebase shows in order to configure the extension), and the process of doing everything would take me much longer for this small change, in comparison with you guys.

jhuleattcommented, Sep 29, 2020

Hi @magoarcano! Thanks for the feature request. Given the huge array of configuration options that sharp provides, and our desire to keep the parameters for this extension limited to a small set of essential config, we’re not able to add this feature.

However, we have published Cloud Functions sample code here that should be easy to customize to your exact needs. I hope that helps with your use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Scale and Crop Images with CSS object-fit
Learn how to use the CSS object-fit property to scale and crop images ... This image has an original width of 1200px and...
Read more >
Image being cropped when max-width is active - Stack Overflow
Try update your css with below code. CSS .wp-image-490 { width: 100%; /* Newly added */ max-height: 200px; max-width: 350px; }.
Read more >
Resize Images Proportionally While Keeping The Aspect Ratio
Use max-width: 100% to limit the size but allow smaller image sizes, use width: 100% to always scale the image to fit the...
Read more >
How to Auto-Resize the Image to fit an HTML Container
Example of resizing an image using the object-fit property:​​ The max-height property sets the maximum height of an element, and the max-width property...
Read more >
C37: Using CSS max-width and height to fit images | WAI - W3C
This is done by using CSS max-width and height property techniques that adapt to the available space and keep the original dimensions of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found