From f1ace29f71bb2b9c25a2538f4fe2d8c8ebc89f9a Mon Sep 17 00:00:00 2001 From: imakida Date: Sun, 19 Jul 2020 09:00:31 -1000 Subject: [PATCH] fix(gatsby-plugin-sharp): return correct height (#25150) Co-authored-by: Ward Peeters --- .../src/__tests__/__snapshots__/index.js.snap | 16 ++++++++-------- packages/gatsby-plugin-sharp/src/index.js | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap b/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap index ec2715d39962b..54fc2a65accb1 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap +++ b/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap @@ -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 { diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 0e89278068769..bbac61224b1f1 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -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