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

fix(image): handle image imports with high aspect ratio #40563

Merged
merged 5 commits into from Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/next/build/webpack/loaders/next-image-loader.js
Expand Up @@ -35,12 +35,14 @@ function nextImageLoader(content) {
// Shrink the image's largest dimension
if (imageSize.width >= imageSize.height) {
blurWidth = BLUR_IMG_SIZE
blurHeight = Math.round(
(imageSize.height / imageSize.width) * BLUR_IMG_SIZE
blurHeight = Math.max(
Math.round((imageSize.height / imageSize.width) * BLUR_IMG_SIZE),
1
)
} else {
blurWidth = Math.round(
(imageSize.width / imageSize.height) * BLUR_IMG_SIZE
blurWidth = Math.max(
Math.round((imageSize.width / imageSize.height) * BLUR_IMG_SIZE),
1
)
blurHeight = BLUR_IMG_SIZE
}
Expand Down
18 changes: 18 additions & 0 deletions test/integration/image-future/default/pages/static-img.js
Expand Up @@ -11,6 +11,8 @@ import testGIF from '../public/test.gif'
import testBMP from '../public/test.bmp'
import testICO from '../public/test.ico'
import widePNG from '../public/wide.png'
import tallPNG from '../components/tall.png'
import superWidePNG from '../public/super-wide.png'

import TallImage from '../components/TallImage'

Expand Down Expand Up @@ -40,6 +42,22 @@ const Page = () => {
<Image id="blur-jpg" src={testJPG} placeholder="blur" />
<Image id="blur-webp" src={testWEBP} placeholder="blur" />
<Image id="blur-avif" src={testAVIF} placeholder="blur" />
<Image id="blur-wide" src={widePNG} placeholder="blur" />
<Image id="blur-tall" src={tallPNG} placeholder="blur" />
<Image
id="blur-super-wide"
src={superWidePNG}
placeholder="blur"
width={72}
height={16}
/>
<Image
id="blur-super-tall"
src={superWidePNG}
placeholder="blur"
width={16}
height={72}
/>
<br />
<Image id="static-svg" src={testSVG} />
<Image id="static-gif" src={testGIF} />
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.