Skip to content

Commit

Permalink
Service images additionally as AVIF
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Hurnaus committed Dec 6, 2023
1 parent c8a15cf commit 767c995
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 36 deletions.
96 changes: 60 additions & 36 deletions app/components/activity-teaser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,80 @@ export const ActivityTeaserComponent = ({
cloudinaryImageName,
altText,
}: ActivityTeaserComponentProps) => {
const avifSrcSet = `
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.AVIF,
CloudinaryImageDensity.SINGLE,
undefined,
256
)} 1x,
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.DOUBLE,
undefined,
256
)} 2x,
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.TRIPLE,
undefined,
256
)} 3x`;

const webpSrcSet = `
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.SINGLE,
undefined,
256
)} 1x,
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.SINGLE,
undefined,
256
)} 1x,
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.DOUBLE,
undefined,
256
)} 2x,
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.DOUBLE,
undefined,
256
)} 2x,
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.TRIPLE,
undefined,
256
)} 3x`;
cloudinaryImageName,
CloudinaryImageFormat.WEBP,
CloudinaryImageDensity.TRIPLE,
undefined,
256
)} 3x`;

const jpgSrcSet = `
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.JPG,
CloudinaryImageDensity.SINGLE,
undefined,
256
)} 1x,
cloudinaryImageName,
CloudinaryImageFormat.JPG,
CloudinaryImageDensity.SINGLE,
undefined,
256
)} 1x,
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.JPG,
CloudinaryImageDensity.DOUBLE,
undefined,
256
)} 2x,
cloudinaryImageName,
CloudinaryImageFormat.JPG,
CloudinaryImageDensity.DOUBLE,
undefined,
256
)} 2x,
${CloudinaryImageRequestHelper.getImageUrl(
cloudinaryImageName,
CloudinaryImageFormat.JPG,
CloudinaryImageDensity.TRIPLE,
undefined,
256
)} 3x`;
cloudinaryImageName,
CloudinaryImageFormat.JPG,
CloudinaryImageDensity.TRIPLE,
undefined,
256
)} 3x`;

return (
<header className="h-96 flex-none basis-full rounded-xl px-2 sm:basis-1/2 lg:basis-1/3 2xl:basis-1/4">
<div className="flex flex-col">
<picture>
<source type="image/avif" srcSet={avifSrcSet}></source>
<source type="image/webp" srcSet={webpSrcSet}></source>
<source type="image/jpg" srcSet={jpgSrcSet}></source>
<img
Expand Down
1 change: 1 addition & 0 deletions app/helper/CloudinaryImageRequestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum CloudinaryImageDensity {
export enum CloudinaryImageFormat {
JPG = "jpg",
WEBP = "webp",
AVIF = "avif"
}

export class CloudinaryImageRequestHelper {
Expand Down

1 comment on commit 767c995

@vercel
Copy link

@vercel vercel bot commented on 767c995 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.