Skip to content

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.

fix: image upload logic order

Brad Barbinb2228d4df357
diff --git a/packages/database/supabase/functions/image-resizer/index.ts b/packages/database/supabase/functions/image-resizer/index.ts
index 0d154cd477..c62ac18833 100644
--- a/packages/database/supabase/functions/image-resizer/index.ts
+++ b/packages/database/supabase/functions/image-resizer/index.ts
@@ -47,17 +47,28 @@ serve(async (req: Request) => {
const width = img.width;
const height = img.height;
- if (contained) {
+ if (targetHeight) {
+ console.log("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 resize
+ img.resize(targetWidthInt, targetHeightInt);
+ img.quality = 90;
+ } else if (contained) {
console.log("contained");
// Calculate size with 10% padding
const padding = 0.1; // 10% padding
const maxDimension = Math.max(width, height);
const sizeWithPadding = Math.ceil(maxDimension * (1 + 2 * padding));
- // Calculate offsets to center the image with padding
- const x = Math.floor((sizeWithPadding - width) / 2);
- const y = Math.floor((sizeWithPadding - height) / 2);
-
// Create geometry for the centered image with padding
const containedGeometry = new MagickGeometry(
0,
@@ -76,21 +87,6 @@ serve(async (req: Request) => {
resizeGeometry.ignoreAspectRatio = true;
img.resize(resizeGeometry);
img.quality = 90;
- } else if (targetHeight) {
- console.log("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 resize
- img.resize(targetWidthInt, targetHeightInt);
- img.quality = 90;
} else {
console.log("default");
// Calculate the size for cropping