Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: update image resizer edge function for consistent image handling
Brad Barbin81c53e463aa4
diff --git a/packages/database/supabase/functions/image-resizer/index.ts b/packages/database/supabase/functions/image-resizer/index.tsindex 8185f620d5..9b4ce1bba2 100644--- a/packages/database/supabase/functions/image-resizer/index.ts+++ b/packages/database/supabase/functions/image-resizer/index.ts@@ -2,6 +2,7 @@ import { serve } from "https://deno.land/[email protected]/http/server.ts";import {ImageMagick,initializeImageMagick,+ MagickFormat,MagickGeometry,} from "npm:@imagemagick/[email protected]";@@ -37,15 +38,26 @@ serve(async (req: Request) => {const bytes = new Uint8Array(arrayBuffer);const result = await ImageMagick.read(bytes, (img) => {+ // First convert to PNG to ensure consistent handling+ img.format = MagickFormat.Png;+const width = img.width;const height = img.height;if (targetHeight) {const targetHeightInt = parseInt(targetHeight, 10);+ // Ensure we have valid dimensions+ if (isNaN(targetHeightInt) || targetHeightInt <= 0) {+ throw new Error("Invalid target height");+ }+const ratio = img.width / img.height;const targetWidthInt = Math.round(targetHeightInt * ratio);++ // Add quality settings for resizeimg.resize(targetWidthInt, targetHeightInt);+ img.quality = 90;} else {// Calculate the size for croppingconst size = Math.min(width, height);@@ -54,13 +66,19 @@ serve(async (req: Request) => {const x = Math.floor((width - size) / 2);const y = Math.floor((height - size) / 2);- // Crop to square- img.crop(new MagickGeometry(x, y, size, size));+ // Crop to square with explicit geometry+ const cropGeometry = new MagickGeometry(x, y, size, size);+ cropGeometry.ignoreAspectRatio = true;+ img.crop(cropGeometry);- // Resize to 400x400+ // Resize with quality settingsimg.resize(300, 300);+ img.quality = 90;}+ // Strip metadata to reduce size+ img.strip();+return img.write((data) => data);});@@ -69,11 +87,12 @@ serve(async (req: Request) => {...corsHeaders,"Content-Type": "image/png","Content-Length": result.length.toString(),+ "Cache-Control": "public, max-age=31536000",},});} catch (err) {- console.error(err);- return new Response(JSON.stringify(err), {+ console.error("Image processing error:", err);+ return new Response(JSON.stringify({ error: err.message }), {headers: { ...corsHeaders, "Content-Type": "application/json" },status: 500,});