From 504c8951572e9c24c858c31f80f83d77795721bd Mon Sep 17 00:00:00 2001 From: jamey Date: Mon, 16 Feb 2026 17:48:03 +0000 Subject: [PATCH] cap gallery image width to max available variant Gallery was hardcoding 1200px width, breaking for images with smaller source dimensions where only 400/800 variants exist. Co-Authored-By: Claude Opus 4.6 --- lib/simpleshop_theme_web/live/shop/product_show.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/simpleshop_theme_web/live/shop/product_show.ex b/lib/simpleshop_theme_web/live/shop/product_show.ex index e7e8d63..813108a 100644 --- a/lib/simpleshop_theme_web/live/shop/product_show.ex +++ b/lib/simpleshop_theme_web/live/shop/product_show.ex @@ -2,6 +2,7 @@ defmodule SimpleshopThemeWeb.Shop.ProductShow do use SimpleshopThemeWeb, :live_view alias SimpleshopTheme.Cart + alias SimpleshopTheme.Images.Optimizer alias SimpleshopTheme.Products alias SimpleshopTheme.Products.{Product, ProductImage} @@ -23,7 +24,13 @@ defmodule SimpleshopThemeWeb.Shop.ProductShow do (product.images || []) |> Enum.sort_by(& &1.position) |> Enum.map(fn img -> - %{url: ProductImage.direct_url(img, 1200), color: img.color} + width = + case ProductImage.source_width(img) do + nil -> 1200 + sw -> Enum.max(Optimizer.applicable_widths(sw)) + end + + %{url: ProductImage.url(img, width), color: img.color} end) |> Enum.reject(fn img -> is_nil(img.url) end)