You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When resizing a very lengthy image to a square using fit: 'contain' to place it resized in the square, it is instead behaving like fit: 'inside' and not respecting the requested output size in one dimension.
Reproducable in sharp 0.29.2. It definitely worked as expected in 0.27.0.
What are the steps to reproduce?
resize a JPEG image to a square with a size in-between the largest and the smallest edge of the original image, using fit: 'contain' (Example: input file 1px width, 850px height, resize to 100x100) -> Result image has 100px height, but only 1px width and no letterboxing occurred as expected
What is the expected behaviour?
Result image should respect 'contain' behavior, and be letterboxed to match the target width and height.
Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
constsharp=require('sharp');constassert=require('assert');/** * input file is a jpg with 1px x 850px * expected output is a jpg with 100px x 100px */constINPUT='./1px.jpg';constOUTPUT='./1px-thumb.jpg';(async()=>{constimage=awaitsharp(INPUT);constmetaInput=awaitsharp(INPUT).metadata();assert.strictEqual(metaInput.height,850,'input height is 850px');assert.strictEqual(metaInput.width,1,'input width is 1px');image.resize(100,100,{fit: 'contain',background: {r: 255,g: 255,b: 255,alpha: 1},});image.jpeg({quality: 85,chromaSubsampling: '4:2:0',progressive: true,});awaitimage.toFile(OUTPUT);constmetaOutput=awaitsharp(OUTPUT).metadata();assert.strictEqual(metaOutput.height,100,'output height is 100px');assert.strictEqual(metaOutput.width,100,'output width is 100px');})();
Error:
AssertionError [ERR_ASSERTION]: output width is 100px
at ...:27:10 {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: 1,
expected: 100,
operator: 'strictEqual'
}
Are you able to provide a sample image that helps explain the problem?
When resizing a very lengthy image to a square using
fit: 'contain'
to place it resized in the square, it is instead behaving likefit: 'inside'
and not respecting the requested output size in one dimension.Reproducable in sharp 0.29.2. It definitely worked as expected in 0.27.0.
What are the steps to reproduce?
fit: 'contain'
(Example: input file 1px width, 850px height, resize to 100x100) -> Result image has 100px height, but only 1px width and no letterboxing occurred as expectedWhat is the expected behaviour?
Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
Error:
Are you able to provide a sample image that helps explain the problem?
https://user-images.githubusercontent.com/770621/139036263-ad9d9d1d-b19c-45ac-b99b-22d93c4b5755.jpg
(barely visible, because it is only 1px wide:)
What is the output of running
npx envinfo --binaries --system
?also happens on the CI server with
The text was updated successfully, but these errors were encountered: