Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent outputting contentful image url with dimensions greater than 4000px #3398

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand All @@ -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.
Expand Down Expand Up @@ -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`
}
Expand Down