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: images for pdf preview

Brad Barbin684a80a3b20a
diff --git a/apps/erp/app/components/ItemThumnailUpload.tsx b/apps/erp/app/components/ItemThumnailUpload.tsx
index 686cfb2d98..970cb5affb 100644
--- a/apps/erp/app/components/ItemThumnailUpload.tsx
+++ b/apps/erp/app/components/ItemThumnailUpload.tsx
@@ -86,8 +86,15 @@ export function ItemThumbnailUpload({
body: formData,
}
);
+
+ // Get content type from response to determine if it's JPG or PNG
+ const contentType =
+ response.headers.get("Content-Type") || "image/png";
+ const isJpg = contentType.includes("image/jpeg");
+ const fileExtension = isJpg ? "jpg" : "png";
+
const blob = new Blob([await response.arrayBuffer()], {
- type: "image/png",
+ type: contentType,
});
const reader = new FileReader();
@@ -99,9 +106,9 @@ export function ItemThumbnailUpload({
};
reader.readAsDataURL(blob);
- const fileName = `${nanoid()}.png`;
+ const fileName = `${nanoid()}.${fileExtension}`;
const thumbnailFile = new File([blob], fileName, {
- type: "image/png",
+ type: contentType,
});
const { data, error } = await carbon.storage
@@ -135,7 +142,8 @@ export function ItemThumbnailUpload({
setThumbnailPath(getPrivateUrl(data.path));
toast.success("Thumbnail uploaded");
}
- } catch {
+ } catch (error) {
+ console.error("Image processing error:", error);
toast.error("Failed to resize image");
}
}
@@ -158,7 +166,12 @@ export function ItemThumbnailUpload({
)}
<HStack className="absolute bottom-2 right-2">
{thumbnailPath && (
- <Button variant="secondary" size="sm" onClick={onFileRemove}>
+ <Button
+ variant="secondary"
+ className="bg-card opacity-100"
+ size="sm"
+ onClick={onFileRemove}
+ >
Remove
</Button>
)}
@@ -166,6 +179,7 @@ export function ItemThumbnailUpload({
accept="image/*"
variant="secondary"
size="sm"
+ className="bg-card opacity-100"
onChange={onFileChange}
>
Upload
diff --git a/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx b/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx
index 0f63e67b53..4f6e3eaf62 100644
--- a/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx
+++ b/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx
@@ -21,7 +21,6 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
const fileExtension = avatarFile.name.substring(
avatarFile.name.lastIndexOf(".") + 1
);
-
const formData = new FormData();
formData.append("file", avatarFile);
@@ -38,9 +37,14 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
throw new Error("Failed to resize image");
}
+ // Get content type from response to determine if it's JPG or PNG
+ const contentType = response.headers.get("Content-Type") || "image/png";
+ const isJpg = contentType.includes("image/jpeg");
+ const outputExtension = isJpg ? "jpg" : "png";
+
const blob = await response.blob();
- const resizedFile = new File([blob], `${user.id}.${fileExtension}`, {
- type: "image/png",
+ const resizedFile = new File([blob], `${user.id}.${outputExtension}`, {
+ type: contentType,
});
avatarFile = resizedFile;
diff --git a/apps/erp/app/modules/shared/shared.service.ts b/apps/erp/app/modules/shared/shared.service.ts
index 8f4fef2aa4..16529287cc 100644
--- a/apps/erp/app/modules/shared/shared.service.ts
+++ b/apps/erp/app/modules/shared/shared.service.ts
@@ -33,7 +33,15 @@ export async function getBase64ImageFromSupabase(
const arrayBuffer = await data.arrayBuffer();
const base64String = arrayBufferToBase64(arrayBuffer);
- return `data:image/png;base64,${base64String}`;
+
+ // Determine the mime type based on file extension
+ const fileExtension = path.split(".").pop()?.toLowerCase();
+ const mimeType =
+ fileExtension === "jpg" || fileExtension === "jpeg"
+ ? "image/jpeg"
+ : "image/png";
+
+ return `data:${mimeType};base64,${base64String}`;
}
export async function getCountries(client: SupabaseClient<Database>) {
diff --git a/packages/database/supabase/functions/image-resizer/index.ts b/packages/database/supabase/functions/image-resizer/index.ts
index 59ffdbcfd6..c033ff87a4 100644
--- a/packages/database/supabase/functions/image-resizer/index.ts
+++ b/packages/database/supabase/functions/image-resizer/index.ts
@@ -201,11 +201,12 @@ serve(async (req: Request) => {
);
containedGeometry.ignoreAspectRatio = true;
- img.extent(
- containedGeometry,
- Gravity.Center,
- new MagickColor("transparent")
- );
+ // Use white background for JPG files, transparent for others
+ const backgroundColor = isJpgFile
+ ? new MagickColor("white")
+ : new MagickColor("transparent");
+
+ img.extent(containedGeometry, Gravity.Center, backgroundColor);
console.log("Resizing to 300x300");
const resizeGeometry = new MagickGeometry(300, 300);
@@ -312,11 +313,13 @@ serve(async (req: Request) => {
// Simple contained mode for fallback
const size = 300;
const canvas = new MagickGeometry(0, 0, size, size);
- img.extent(
- canvas,
- Gravity.Center,
- new MagickColor("transparent")
- );
+
+ // Use white background for JPG files, transparent for others
+ const backgroundColor = isJpgFile
+ ? new MagickColor("white")
+ : new MagickColor("transparent");
+
+ img.extent(canvas, Gravity.Center, backgroundColor);
} else {
// Simple resize to 300x300
img.resize(300, 300);