Skip to content

Commit f65b058

Browse files
Try updating image handling
1 parent ecce2e1 commit f65b058

2 files changed

Lines changed: 40 additions & 16 deletions

File tree

astro.config.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ export default defineConfig({
1717
}),
1818
site: 'https://whiskey.fm',
1919
image: {
20-
remotePatterns: [{ protocol: 'https' }]
20+
remotePatterns: [
21+
{
22+
protocol: 'https',
23+
hostname: '**'
24+
},
25+
{
26+
protocol: 'http',
27+
hostname: '**'
28+
}
29+
]
2130
},
2231
integrations: [db(), preact(), sitemap()],
2332
// These were specific redirects we needed for our podcast, if you do not have any routes to redirect, you can safely remove this.

src/lib/image-utils.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,41 @@
22
export function getOptimizedImageUrl(
33
originalUrl: string | null | undefined,
44
width: number = 160,
5-
height: number = 160
5+
height: number = 160,
6+
quality: number = 75, // Lower quality for AVIF since it's more efficient
7+
format: 'avif' | 'webp' | 'auto' = 'avif'
68
): string {
79
if (!originalUrl) {
810
return '/images/www.png';
911
}
1012

11-
try {
12-
// Use Astro's image service endpoint
13-
// This works because Astro creates /_image endpoints when image service is configured
14-
const params = new URLSearchParams({
15-
href: originalUrl,
16-
w: width.toString(),
17-
h: height.toString(),
18-
f: 'webp', // Format
19-
q: '85' // Quality
20-
});
21-
22-
return `/_image?${params}`;
23-
} catch (error) {
24-
console.error('Error generating optimized image URL:', error);
13+
// In development, return original URL
14+
if (import.meta.env.DEV) {
2515
return originalUrl;
2616
}
17+
18+
// In production on Vercel, use Vercel's Image Optimization API with AVIF
19+
const params = new URLSearchParams({
20+
url: originalUrl,
21+
w: width.toString(),
22+
h: height.toString(),
23+
q: quality.toString(),
24+
f: format, // Force AVIF format (smallest file size)
25+
});
26+
27+
return `/_vercel/image?${params}`;
2728
}
29+
30+
// Helper for generating multiple format URLs
31+
export function getImageUrls(originalUrl: string | null | undefined) {
32+
if (!originalUrl) {
33+
const fallback = '/images/www.png';
34+
return { avif: fallback, webp: fallback, fallback };
35+
}
36+
37+
return {
38+
avif: getOptimizedImageUrl(originalUrl, 160, 160, 75, 'avif'),
39+
webp: getOptimizedImageUrl(originalUrl, 160, 160, 85, 'webp'),
40+
fallback: originalUrl
41+
};
42+
}

0 commit comments

Comments
 (0)