Created
May 19, 2025 18:32
-
-
Save anatooly/96413aea3b1bd223f87522e6a1c3677c to your computer and use it in GitHub Desktop.
get-background-image-url.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const assetPrefix = process.env.NEXT_PUBLIC_ASSET_PREFIX || ""; | |
| export const ALLOWED_WIDTHS = [16, 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840] as const; | |
| export type AllowedWidth = (typeof ALLOWED_WIDTHS)[number]; | |
| export const getBackgroundImageUrl = (path: string, width: AllowedWidth = 1920, quality = 75) => { | |
| const encodedUrl = encodeURIComponent(path); | |
| return `${assetPrefix}/_next/image?url=${encodedUrl}&w=${width}&q=${quality}`; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment