-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support resize without preserving aspect ratio #192
Conversation
2 similar comments
Hi @jsongHBO @bkw @blowsie, as requestors of #118 are you able to help test @skedastik's great work on the feature you need? |
Great work, @skedastik ! |
Thanks, @bkw. |
I just noticed I was a bit behind on my checkout of libvips. rebuilding with 7.42 now, will report back if it makes a difference. |
I can still reproduce it with this: var sharp = require('sharp'),
request = require('request'),
resizer = sharp().ignoreAspectRatio().resize(256,256);
request('http://i.imgur.com/dLKxTCk.jpg')
.pipe(resizer)
.pipe(sharp().metadata(console.log)); This gives the following output for me:
Strange but true: Adding .gamma() produces the correct height of 256... |
Curiouser and curioser. Reproduced on my system. Looking into it... |
Quick thought: possibly related to the use of gamma correction preventing JPEG shrink-on-load. |
2 similar comments
I can confirm that for me it works as expected now. Thanks for the quick response, @skedastik ! |
assert.strictEqual(320, info.height); | ||
done(); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to add a couple of tests for upscaling width but downscaling height and vice versa?
More unit tests: done! |
Add support for ignoreAspectRatio option when resizing
Fantastic, thank you Alaric. This will be included in the forthcoming v0.10.0 release. |
Goal
Add an
ignoreAspectRatio
method to support resizing of images to arbitrary aspect ratios, as requested in #118.Behavior
Fixed width and height:
Fixed width (leaving height unchanged):
Fixed height (leaving width unchanged):
sharp's behavior is otherwise unchanged.
Code paths affected
IGNORE_ASPECT
factor
,shrink
, andresidual
.CalculateShrink
CalculateResidual
xresidual
andyresidual
to computesigma
for pre-affine-reduction Gaussian blur (see Progress on #118 (ignore aspect ratio) #191).Sharp.prototype.ignoreAspectRatio
this.options.canvas
to "ignore_aspect"