Skip to content

Commit f1ace29

Browse files
imakidawardpeet
andauthored
fix(gatsby-plugin-sharp): return correct height (#25150)
Co-authored-by: Ward Peeters <[email protected]>
1 parent e9e40e9 commit f1ace29

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,38 +789,38 @@ Array [
789789
Object {
790790
"args": Object {
791791
"fit": "inside",
792-
"height": 50,
792+
"height": 34,
793793
"toFormat": "png",
794794
"width": 50,
795795
},
796-
"outputPath": "d9f78/test.png",
796+
"outputPath": "45628/test.png",
797797
},
798798
Object {
799799
"args": Object {
800800
"fit": "inside",
801-
"height": 100,
801+
"height": 68,
802802
"toFormat": "png",
803803
"width": 100,
804804
},
805-
"outputPath": "997ba/test.png",
805+
"outputPath": "52a18/test.png",
806806
},
807807
Object {
808808
"args": Object {
809809
"fit": "inside",
810-
"height": 200,
810+
"height": 136,
811811
"toFormat": "png",
812812
"width": 200,
813813
},
814-
"outputPath": "6ad4e/test.png",
814+
"outputPath": "279d8/test.png",
815815
},
816816
Object {
817817
"args": Object {
818818
"fit": "inside",
819-
"height": 281,
819+
"height": 191,
820820
"toFormat": "png",
821821
"width": 281,
822822
},
823-
"outputPath": "7aa47/test.png",
823+
"outputPath": "24238/test.png",
824824
},
825825
],
826826
"pluginOptions": Object {

packages/gatsby-plugin-sharp/src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,13 @@ async function fluid({ file, args = {}, reporter, cache }) {
544544
}
545545

546546
if (options.maxWidth !== undefined && options.maxHeight !== undefined) {
547-
arrrgs.height = Math.round(size * (options.maxHeight / options.maxWidth))
547+
if (options.fit === sharp.fit.inside) {
548+
arrrgs.height = Math.round(size * (maxHeight / maxWidth))
549+
} else {
550+
arrrgs.height = Math.round(
551+
size * (options.maxHeight / options.maxWidth)
552+
)
553+
}
548554
}
549555

550556
return arrrgs

0 commit comments

Comments
 (0)