Skip to content

Commit

Permalink
Fix blurry images (volto17) (#6637)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini authored Jan 31, 2025
1 parent d05192c commit bd2403d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions news/6637.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display the appropriately sized image to eliminate blurring from upsizing smaller images in the `srcSet` generation. @giuliaghisini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`renders a Lead Image block Sidebar component 1`] = `
height={400}
sizes="188px"
src="/image.png/@@images/image-1200.png"
srcSet="/image.png/@@images/image-400.png 400w"
srcSet="/image.png/@@images/image-400.png 400w, /image.png/@@images/image-1200.png 400w"
width={400}
/>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/components/theme/Image/Image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ export default function Image({
attrs.className = cx(className, { responsive });

if (!isSvg && image.scales && Object.keys(image.scales).length > 0) {
const sortedScales = Object.values(image.scales).sort((a, b) => {
const sortedScales = Object.values({
...image.scales,
original: {
download: `${image.download}`,
width: image.width,
height: image.height,
},
}).sort((a, b) => {
if (a.width > b.width) return 1;
else if (a.width < b.width) return -1;
else return 0;
Expand Down
10 changes: 5 additions & 5 deletions src/components/theme/Image/__snapshots__/Image.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`renders an image component from a catalog brain 1`] = `
fetchpriority="high"
height={400}
src="/image/@@images/image.png"
srcSet="/image/@@images/image-400.png 400w"
srcSet="/image/@@images/image-400.png 400w, /image/@@images/image.png 400w"
width={400}
/>
`;
Expand All @@ -19,7 +19,7 @@ exports[`renders an image component from a catalog brain using \`preview_image_l
fetchpriority="high"
height={400}
src="/image.png/@@images/image.png"
srcSet="/image.png/@@images/image-400.png 400w"
srcSet="/image.png/@@images/image-400.png 400w, /image.png/@@images/image.png 400w"
width={400}
/>
`;
Expand All @@ -40,7 +40,7 @@ exports[`renders an image component with fetchpriority high 1`] = `
fetchpriority="high"
height={400}
src="/image/@@images/image.png"
srcSet="/image/@@images/image-400.png 400w"
srcSet="/image/@@images/image-400.png 400w, /image/@@images/image.png 400w"
width={400}
/>
`;
Expand All @@ -53,7 +53,7 @@ exports[`renders an image component with lazy loading 1`] = `
height={400}
loading="lazy"
src="/image/@@images/image.png"
srcSet="/image/@@images/image-400.png 400w"
srcSet="/image/@@images/image-400.png 400w, /image/@@images/image.png 400w"
width={400}
/>
`;
Expand All @@ -65,7 +65,7 @@ exports[`renders an image component with responsive class 1`] = `
fetchpriority="high"
height={400}
src="/image/@@images/image-1200.png"
srcSet="/image/@@images/image-400.png 400w"
srcSet="/image/@@images/image-400.png 400w, /image/@@images/image-1200.png 400w"
width={400}
/>
`;

0 comments on commit bd2403d

Please sign in to comment.