From fb2354d2cc33a4eb10edd22e3f5a72b0e46681ba Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sun, 22 Feb 2026 17:30:30 +0100 Subject: [PATCH] feat: Add aspect ratio support to imgproxy loader and apply 16:9 aspect ratio to featured images across blog posts and recent posts. --- app/[locale]/blog/[slug]/page.tsx | 2 +- components/blog/PostNavigation.tsx | 4 ++-- components/home/RecentPosts.tsx | 2 +- lib/imgproxy-loader.ts | 27 ++++++++++++++++++++++++--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/[locale]/blog/[slug]/page.tsx b/app/[locale]/blog/[slug]/page.tsx index 112ca652..8b628c9b 100644 --- a/app/[locale]/blog/[slug]/page.tsx +++ b/app/[locale]/blog/[slug]/page.tsx @@ -76,7 +76,7 @@ export default async function BlogPost({ params }: BlogPostProps) {
{post.frontmatter.title} ) : (
@@ -82,7 +82,7 @@ export default function PostNavigation({ {next.frontmatter.featuredImage ? (
) : (
diff --git a/components/home/RecentPosts.tsx b/components/home/RecentPosts.tsx index 578d6ea8..da4117fb 100644 --- a/components/home/RecentPosts.tsx +++ b/components/home/RecentPosts.tsx @@ -43,7 +43,7 @@ export default async function RecentPosts({ locale }: RecentPostsProps) { {post.frontmatter.featuredImage && (
{post.frontmatter.title} 0) { + calculatedHeight = Math.round(width * (arH / arW)); + resizingType = 'fill'; // Must use fill to allow imgproxy to crop + } + } + url.searchParams.delete('ar'); + } + + if (customGravity || aspectRatio) { cleanSrc = src.startsWith('http') ? url.href : url.pathname + url.search; } } catch (e) { @@ -41,10 +61,11 @@ export default function imgproxyLoader({ } // We use the width provided by Next.js for responsive images - // Height is set to 0 to maintain aspect ratio + // Height is calculated from aspect ratio if provided, otherwise 0 to maintain aspect ratio return getImgproxyUrl(cleanSrc, { width, - resizing_type: 'fit', + height: calculatedHeight, + resizing_type: resizingType, gravity, }); }