Skip to content

Commit 1ea65cf

Browse files
alxhotelstyfle
andauthored
fix(image): handle image imports with high aspect ratio (vercel#40563)
## Bug - [x] Related issues linked using `fixes vercel#40562` fixes vercel#40562 - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: Steven <[email protected]>
1 parent ff1a182 commit 1ea65cf

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

packages/next/build/webpack/loaders/next-image-loader.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ function nextImageLoader(content) {
3535
// Shrink the image's largest dimension
3636
if (imageSize.width >= imageSize.height) {
3737
blurWidth = BLUR_IMG_SIZE
38-
blurHeight = Math.round(
39-
(imageSize.height / imageSize.width) * BLUR_IMG_SIZE
38+
blurHeight = Math.max(
39+
Math.round((imageSize.height / imageSize.width) * BLUR_IMG_SIZE),
40+
1
4041
)
4142
} else {
42-
blurWidth = Math.round(
43-
(imageSize.width / imageSize.height) * BLUR_IMG_SIZE
43+
blurWidth = Math.max(
44+
Math.round((imageSize.width / imageSize.height) * BLUR_IMG_SIZE),
45+
1
4446
)
4547
blurHeight = BLUR_IMG_SIZE
4648
}

test/integration/image-future/default/pages/static-img.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import testGIF from '../public/test.gif'
1111
import testBMP from '../public/test.bmp'
1212
import testICO from '../public/test.ico'
1313
import widePNG from '../public/wide.png'
14+
import tallPNG from '../components/tall.png'
15+
import superWidePNG from '../public/super-wide.png'
1416

1517
import TallImage from '../components/TallImage'
1618

@@ -40,6 +42,22 @@ const Page = () => {
4042
<Image id="blur-jpg" src={testJPG} placeholder="blur" />
4143
<Image id="blur-webp" src={testWEBP} placeholder="blur" />
4244
<Image id="blur-avif" src={testAVIF} placeholder="blur" />
45+
<Image id="blur-wide" src={widePNG} placeholder="blur" />
46+
<Image id="blur-tall" src={tallPNG} placeholder="blur" />
47+
<Image
48+
id="blur-super-wide"
49+
src={superWidePNG}
50+
placeholder="blur"
51+
width={72}
52+
height={16}
53+
/>
54+
<Image
55+
id="blur-super-tall"
56+
src={superWidePNG}
57+
placeholder="blur"
58+
width={16}
59+
height={72}
60+
/>
4361
<br />
4462
<Image id="static-svg" src={testSVG} />
4563
<Image id="static-gif" src={testGIF} />
Loading

0 commit comments

Comments
 (0)