From 4b6d96ff5a494d67b60faeae1b4d7c8b9d22125a Mon Sep 17 00:00:00 2001 From: Alex Prokop Date: Wed, 3 Jan 2018 12:10:51 +0000 Subject: [PATCH 1/2] prevent outputting contentful image url with dimensions greater than 4000 --- .../gatsby-source-contentful/src/extend-node-type.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-contentful/src/extend-node-type.js b/packages/gatsby-source-contentful/src/extend-node-type.js index 40fc085fa4aa8..ca20c21fece6d 100644 --- a/packages/gatsby-source-contentful/src/extend-node-type.js +++ b/packages/gatsby-source-contentful/src/extend-node-type.js @@ -10,6 +10,7 @@ const { const qs = require(`qs`) const base64Img = require(`base64-img`) const _ = require(`lodash`) +const maxContentfulImageSize = 4000 const ImageFormatType = new GraphQLEnumType({ name: `ContentfulImageFormat`, @@ -130,6 +131,7 @@ const resolveResponsiveResolution = (image, options) => { // If we're cropping, calculate the specified aspect ratio. if (options.height) { + options.height = Math.min(options.height, maxContentfulImageSize) desiredAspectRatio = options.width / options.height } @@ -155,7 +157,7 @@ const resolveResponsiveResolution = (image, options) => { sizes = sizes.map(Math.round) // Filter out sizes larger than the image's width. - const filteredSizes = sizes.filter(size => size < width) + const filteredSizes = sizes.filter(size => size < width && size < maxContentfulImageSize) // Sort sizes for prettiness. const sortedSizes = _.sortBy(filteredSizes) @@ -222,6 +224,7 @@ const resolveResponsiveSizes = (image, options) => { // If we're cropping, calculate the specified aspect ratio. if (options.maxHeight) { + options.maxHeight = Math.min(options.maxHeight, maxContentfulImageSize) desiredAspectRatio = options.maxWidth / options.maxHeight } @@ -248,7 +251,7 @@ const resolveResponsiveSizes = (image, options) => { sizes = sizes.map(Math.round) // Filter out sizes larger than the image's maxWidth. - const filteredSizes = sizes.filter(size => size < width) + const filteredSizes = sizes.filter(size => size < width && size < maxContentfulImageSize) // Add the original image to ensure the largest image possible // is available for small images. @@ -295,6 +298,8 @@ const resolveResize = (image, options) => { // If the user selected a height (so cropping) and fit option // is not set, we'll set our defaults if (options.height) { + options.height = Math.min(options.height, maxContentfulImageSize) + if (!options.resizingBehavior) { options.resizingBehavior = `fill` } From 48472fd202d883bb8c41b43fe91c97765fbf4fba Mon Sep 17 00:00:00 2001 From: Alex Prokop Date: Wed, 3 Jan 2018 12:24:04 +0000 Subject: [PATCH 2/2] corrected less than error --- packages/gatsby-source-contentful/src/extend-node-type.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-contentful/src/extend-node-type.js b/packages/gatsby-source-contentful/src/extend-node-type.js index ca20c21fece6d..aab218b12e5d4 100644 --- a/packages/gatsby-source-contentful/src/extend-node-type.js +++ b/packages/gatsby-source-contentful/src/extend-node-type.js @@ -157,7 +157,7 @@ const resolveResponsiveResolution = (image, options) => { sizes = sizes.map(Math.round) // Filter out sizes larger than the image's width. - const filteredSizes = sizes.filter(size => size < width && size < maxContentfulImageSize) + const filteredSizes = sizes.filter(size => size < width && size <= maxContentfulImageSize) // Sort sizes for prettiness. const sortedSizes = _.sortBy(filteredSizes) @@ -251,7 +251,7 @@ const resolveResponsiveSizes = (image, options) => { sizes = sizes.map(Math.round) // Filter out sizes larger than the image's maxWidth. - const filteredSizes = sizes.filter(size => size < width && size < maxContentfulImageSize) + const filteredSizes = sizes.filter(size => size < width && size <= maxContentfulImageSize) // Add the original image to ensure the largest image possible // is available for small images.