Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): return correct height (#25150)
Browse files Browse the repository at this point in the history
Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
imakida and wardpeet committed Jul 19, 2020
1 parent e9e40e9 commit f1ace29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,38 +789,38 @@ Array [
Object {
"args": Object {
"fit": "inside",
"height": 50,
"height": 34,
"toFormat": "png",
"width": 50,
},
"outputPath": "d9f78/test.png",
"outputPath": "45628/test.png",
},
Object {
"args": Object {
"fit": "inside",
"height": 100,
"height": 68,
"toFormat": "png",
"width": 100,
},
"outputPath": "997ba/test.png",
"outputPath": "52a18/test.png",
},
Object {
"args": Object {
"fit": "inside",
"height": 200,
"height": 136,
"toFormat": "png",
"width": 200,
},
"outputPath": "6ad4e/test.png",
"outputPath": "279d8/test.png",
},
Object {
"args": Object {
"fit": "inside",
"height": 281,
"height": 191,
"toFormat": "png",
"width": 281,
},
"outputPath": "7aa47/test.png",
"outputPath": "24238/test.png",
},
],
"pluginOptions": Object {
Expand Down
8 changes: 7 additions & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,13 @@ async function fluid({ file, args = {}, reporter, cache }) {
}

if (options.maxWidth !== undefined && options.maxHeight !== undefined) {
arrrgs.height = Math.round(size * (options.maxHeight / options.maxWidth))
if (options.fit === sharp.fit.inside) {
arrrgs.height = Math.round(size * (maxHeight / maxWidth))
} else {
arrrgs.height = Math.round(
size * (options.maxHeight / options.maxWidth)
)
}
}

return arrrgs
Expand Down

0 comments on commit f1ace29

Please sign in to comment.