question-mark
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.

.resize() with .max() still crops the image

See original GitHub issue

Sorry to bother you again, dunno - maybe its something on my side. Given an image - for example this one

image

I would like to resize it to max 100x100 which means the resulting image should fit within those bounds while maintaing the aspect ratio (no cropping). Here’s my call:

sharp(file).resize(100, 100).max().toBuffer(function(err, buffer) {
});

And the image I get is this one (resized and cropped to 57x100):

image

Shouldn’t sharp simply resize input image to 57x100 without any cropping?

Thanks.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
pierreinglebertcommented, May 23, 2014

Hmmm, I tried on an OSX Mav with sharp 0.4.1, libvips 7.38 and both node 0.10/0.11. Here’s what i get out

var sharp = require('sharp');
var fs = require('fs');

sharp('f2bc5c0e-e1ec-11e3-844f-28e9fded8f8b.png').resize(100, 100).max().toBuffer(function(err, buffer) {
  fs.writeFileSync('out.jpg', buffer);
});

What’s your platform ?

1reaction
idecommented, May 23, 2014

@pierreinglebert: I get the same results as you with that image, though I do see unexpected cropping with a different image. Perhaps Github is reencoding attachments and that changes something.

Here is a source image I can use to repro: https://mega.co.nz/#!UUNSCJxB!lBzVsklJX0VqtsOTYPi7NhGeOoZrqywMwPqUuLoMTIs

This is what the unexpected cropping looks like (100x100, max): out2

My setup:

$ sw_vers -productVersion
10.9.3  # Mavericks

$ node --version
v0.10.27

$ npm list
...
├─┬ sharp@0.4.1

$ brew info vips
vips: stable 7.38.5
http://www.vips.ecs.soton.ac.uk/
/usr/local/Cellar/vips/7.38.5 (188 files, 13M) *
  Built from source with: --with-webp, --with-graphicsmagick
From: https://github.com/homebrew/homebrew-science/commits/master/vips.rb
==> Dependencies
Build: pkg-config ✔
Required: fontconfig ✔, gettext ✔, glib ✔
Recommended: libpng ✔, jpeg ✔, orc ✔, libtiff ✔, fftw ✔, little-cms ✔, pango ✔, libexif ✔
Optional: openslide ✘, imagemagick ✔, graphicsmagick ✔, openexr ✘, cfitsio ✘, webp ✔
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically Resizing and Cropping Images - Cloudinary
Learn how to use different resize and crop modes together with various gravity options to transform images dynamically.
Read more >
Advanced cropping, resizing, resampling - Adobe Support
This document explains in detail how cropping, resizing, and resampling images affects image resolution and pixel dimensions in Adobe ...
Read more >
Pillow crop images keeping the ratio having a max width and ...
I need to crop something using Pillow, by keeping the ratio, and max_height or max_width. Some images can have a bigger width or...
Read more >
How to resize an image in HTML? - ImageKit.io
You can use the object-fit CSS property on the img element to specify how the image should be resized & cropped to fit...
Read more >
Resize Images Proportionally While Keeping The Aspect Ratio
We can resize images proportionally with HTML image tags or CSS background ... Use max-width: 100% to limit the size but allow smaller...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found