Skip to content

Commit

Permalink
fix(image cdn): do not pass aspect ratio in with image args
Browse files Browse the repository at this point in the history
  • Loading branch information
veryspry committed Mar 17, 2022
1 parent 5f77ea0 commit 43b3167
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ describe(`gatsbyImageData`, () => {

expect(parsedSrcSet[0].src).toEqual(
`/_gatsby/image/${base64Encode(portraitSource.url)}/${base64Encode(
`w=300&h=481&fit=crop&ar=1.333333333&fm=avif&q=75`
`w=300&h=225&fm=avif&q=75`
)}/${portraitSource.basename}.avif`
)
expect(parsedSrcSet[0].descriptor).toEqual(`1x`)

expect(parsedSrcSet[1].src).toEqual(
`/_gatsby/image/${base64Encode(portraitSource.url)}/${base64Encode(
`w=600&h=962&fit=crop&ar=1.333333333&fm=avif&q=75`
`w=600&h=450&fm=avif&q=75`
)}/${portraitSource.basename}.avif`
)
expect(parsedSrcSet[1].descriptor).toEqual(`2x`)
Expand All @@ -127,14 +127,14 @@ describe(`gatsbyImageData`, () => {

expect(parsedSrcSet[0].src).toEqual(
`/_gatsby/image/${base64Encode(portraitSource.url)}/${base64Encode(
`w=300&h=481&fit=crop&crop=entropy&ar=1.333333333&fm=avif&q=75`
`w=300&h=225&fit=crop&crop=entropy&fm=avif&q=75`
)}/${portraitSource.basename}.avif`
)
expect(parsedSrcSet[0].descriptor).toEqual(`1x`)

expect(parsedSrcSet[1].src).toEqual(
`/_gatsby/image/${base64Encode(portraitSource.url)}/${base64Encode(
`w=600&h=962&fit=crop&crop=entropy&ar=1.333333333&fm=avif&q=75`
`w=600&h=450&fit=crop&crop=entropy&fm=avif&q=75`
)}/${portraitSource.basename}.avif`
)
expect(parsedSrcSet[1].descriptor).toEqual(`2x`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export async function gatsbyImageResolver(
fit: args.fit as ImageFit,
contentDigest: source.internal.contentDigest,
quality: args.quality as number,
aspectRatio: args.aspectRatio as number,
},
actions
)
Expand All @@ -192,7 +191,6 @@ export async function gatsbyImageResolver(
format,
cropFocus: args.cropFocus,
quality: args.quality as number,
aspectRatio: args.aspectRatio as number,
})}/${encodeURIComponent(
path.basename(source.filename, path.extname(source.filename))
)}.${format}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export function dispatchLocalImageServiceJob(
fit,
contentDigest,
quality,
aspectRatio,
}: {
url: string
extension: string
Expand All @@ -80,7 +79,6 @@ export function dispatchLocalImageServiceJob(
fit: ImageFit
contentDigest: string
quality: number
aspectRatio: number
},
actions: Actions
): void {
Expand All @@ -98,7 +96,7 @@ export function dispatchLocalImageServiceJob(
outputDir: path.join(
global.__GATSBY?.root || process.cwd(),
...publicUrl.filter(Boolean),
generateImageArgs({ width, height, format, quality, aspectRatio })
generateImageArgs({ width, height, format, quality })
),
args: {
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ export function generateImageArgs({
format,
cropFocus,
quality,
aspectRatio,
}: WidthOrHeight & {
format: string
cropFocus?: ImageCropFocus | Array<ImageCropFocus>
quality: number
aspectRatio: number
}): string {
const args: Array<string> = []
if (width) {
Expand All @@ -48,13 +46,6 @@ export function generateImageArgs({
`crop=${Array.isArray(cropFocus) ? cropFocus.join(`,`) : cropFocus}`
)
}
if (aspectRatio) {
// crop must be set for aspectRatio to work
if (!cropFocus) {
args.push(`fit=crop`)
}
args.push(`ar=${aspectRatio}`)
}
args.push(`fm=${format}`)
args.push(`q=${quality}`)

Expand Down

0 comments on commit 43b3167

Please sign in to comment.