[GH-ISSUE #2701] [Issue]: PNG card export blanks non-PNG avatars (JPG/WebP/GIF/AVIF) with a 1x1 transparent image #1345

Closed
opened 2026-10-21 05:31:53 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2701

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Exporting a character as a PNG card discards the avatar image for any non-PNG avatar (JPG/WebP/GIF/AVIF), substituting a blank 1×1 transparent PNG. So a character whose avatar isn't a PNG loses its image entirely on export, breaking export and any export→import round-trip.

Expected behavior

Exporting a character as a PNG card should embed the character's actual avatar image (transcoding to PNG if needed), so the exported card displays the right picture.

Actual behavior

The PNG card builder embeds the card JSON into a PNG, but for the base image it only handles a PNG-source avatar; for a non-PNG avatar (JPG/WebP/GIF/AVIF) it falls back to a blank 1×1 transparent PNG instead of transcoding the real image. The exported .png card therefore has the correct embedded character data but a blank/empty picture — total image loss.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • The PNG card export path (buildCharacterCardPng / the export route — routes/characters.routes.ts and/or the client export in BotBrowserView.tsx/card export util) embeds the tEXt chara chunk but uses a blank 1×1 transparent PNG as the base image when the source avatar is not already a PNG (no transcode of JPG/WebP/GIF/AVIF).

Steps to reproduce

  1. Import or set a character whose avatar is a .jpg/.webp/.gif/.avif.
  2. Export the character as a PNG card.
  3. The exported .png shows a blank/transparent image (the data is intact, the picture is gone). Re-importing yields a character with no avatar image.

Suggested fix

Transcode the avatar to PNG (e.g. via sharp, already a dependency) before embedding, so the real image is preserved in the exported card regardless of source format — rather than substituting a blank 1×1 PNG.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of import/export round-trips. Many Chub/Janny avatars are WebP/JPG, so this commonly blanks the image on export. Part of a set of import/export fidelity issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2701 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Exporting a character as a PNG card discards the avatar image for any **non-PNG** avatar (JPG/WebP/GIF/AVIF), substituting a blank 1×1 transparent PNG. So a character whose avatar isn't a PNG loses its image entirely on export, breaking export and any export→import round-trip. ## Expected behavior Exporting a character as a PNG card should embed the character's actual avatar image (transcoding to PNG if needed), so the exported card displays the right picture. ## Actual behavior The PNG card builder embeds the card JSON into a PNG, but for the base image it only handles a PNG-source avatar; for a non-PNG avatar (JPG/WebP/GIF/AVIF) it falls back to a blank 1×1 transparent PNG instead of transcoding the real image. The exported `.png` card therefore has the correct embedded character data but a blank/empty picture — total image loss. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - The PNG card export path (`buildCharacterCardPng` / the export route — `routes/characters.routes.ts` and/or the client export in `BotBrowserView.tsx`/card export util) embeds the tEXt `chara` chunk but uses a blank 1×1 transparent PNG as the base image when the source avatar is not already a PNG (no transcode of JPG/WebP/GIF/AVIF). ## Steps to reproduce 1. Import or set a character whose avatar is a `.jpg`/`.webp`/`.gif`/`.avif`. 2. Export the character as a PNG card. 3. The exported `.png` shows a blank/transparent image (the data is intact, the picture is gone). Re-importing yields a character with no avatar image. ## Suggested fix Transcode the avatar to PNG (e.g. via `sharp`, already a dependency) before embedding, so the real image is preserved in the exported card regardless of source format — rather than substituting a blank 1×1 PNG. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of import/export round-trips. Many Chub/Janny avatars are WebP/JPG, so this commonly blanks the image on export. Part of a set of import/export fidelity issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@kolacheee commented on GitHub (Jun 21, 2026):

Veracity self-review — correction / clarification
Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it.

Clarification on exact location (verified against the working tree): The defect is solely in the SERVER route GET /:id/export-png in packages/server/src/routes/characters.routes.ts (handler at lines 738-774; the bug is line 756: pngBuffer = imageInfo?.mimeType === "image/png" ? avatarBuffer : createMinimalPng();). Because isAllowedImageBuffer (security.ts:82-121) reports the avatar's true format, any non-PNG avatar takes the createMinimalPng() branch (a real 1x1 transparent PNG, defined at line 1188-1210), while injectTextChunk still embeds the chara data (line 768) — so the card has correct data but a blank picture. This route is the "Export as PNG card" / "compatible-png" action triggered from packages/client/src/components/characters/CharacterEditor.tsx:791.

The Code trace in this issue should drop the "buildCharacterCardPng ... and/or the client export in BotBrowserView.tsx/card export util" wording, because it is misleading: (1) there is NO function named buildCharacterCardPng on the server (grep returns zero hits there); (2) the only buildCharacterCardPng lives in the CLIENT at packages/client/src/components/bot-browser/BotBrowserView.tsx:2958 (used at line 2742 for Bot Browser cards), and it is already CORRECT — it draws the avatar to a canvas and calls canvas.toBlob(..., "image/png") (lines 2967-2974), which transcodes any browser-decodable format to PNG. Pointing a fixer there risks editing correct code or hunting for a server function that doesn't exist. The fix belongs only in the server route.

Suggested patch (server only): transcode non-PNG buffers with the already-bundled sharp (server dependency ^0.34.5, already loaded via await import("sharp") in 5+ files), keeping the existing try/catch so a transcode failure still falls back to createMinimalPng():

const imageInfo = isAllowedImageBuffer(avatarBuffer, extname(filename));
pngBuffer = imageInfo?.mimeType === "image/png"
  ? avatarBuffer
  : await (await import("sharp")).default(avatarBuffer).png().toBuffer();

No new top-level imports are needed.

<!-- gh-comment-id:4761102364 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Veracity self-review — correction / clarification** > _Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it._ Clarification on exact location (verified against the working tree): The defect is solely in the SERVER route `GET /:id/export-png` in `packages/server/src/routes/characters.routes.ts` (handler at lines 738-774; the bug is line 756: `pngBuffer = imageInfo?.mimeType === "image/png" ? avatarBuffer : createMinimalPng();`). Because `isAllowedImageBuffer` (security.ts:82-121) reports the avatar's true format, any non-PNG avatar takes the `createMinimalPng()` branch (a real 1x1 transparent PNG, defined at line 1188-1210), while `injectTextChunk` still embeds the `chara` data (line 768) — so the card has correct data but a blank picture. This route is the "Export as PNG card" / "compatible-png" action triggered from `packages/client/src/components/characters/CharacterEditor.tsx:791`. The Code trace in this issue should drop the "`buildCharacterCardPng` ... and/or the client export in `BotBrowserView.tsx`/card export util" wording, because it is misleading: (1) there is NO function named `buildCharacterCardPng` on the server (grep returns zero hits there); (2) the only `buildCharacterCardPng` lives in the CLIENT at `packages/client/src/components/bot-browser/BotBrowserView.tsx:2958` (used at line 2742 for Bot Browser cards), and it is already CORRECT — it draws the avatar to a canvas and calls `canvas.toBlob(..., "image/png")` (lines 2967-2974), which transcodes any browser-decodable format to PNG. Pointing a fixer there risks editing correct code or hunting for a server function that doesn't exist. The fix belongs only in the server route. Suggested patch (server only): transcode non-PNG buffers with the already-bundled `sharp` (server dependency `^0.34.5`, already loaded via `await import("sharp")` in 5+ files), keeping the existing try/catch so a transcode failure still falls back to `createMinimalPng()`: ```ts const imageInfo = isAllowedImageBuffer(avatarBuffer, extname(filename)); pngBuffer = imageInfo?.mimeType === "image/png" ? avatarBuffer : await (await import("sharp")).default(avatarBuffer).png().toBuffer(); ``` No new top-level imports are needed.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Fixed on the issue sweep branch: server PNG card export now keeps PNG avatars as-is, transcodes valid non-PNG avatar buffers through sharp before injecting the card metadata, and only falls back to the minimal PNG for invalid/unreadable/transcode-failed avatars. Final pnpm validation is intentionally deferred until the full sweep is complete.

<!-- gh-comment-id:4761567714 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed on the issue sweep branch: server PNG card export now keeps PNG avatars as-is, transcodes valid non-PNG avatar buffers through sharp before injecting the card metadata, and only falls back to the minimal PNG for invalid/unreadable/transcode-failed avatars. Final pnpm validation is intentionally deferred until the full sweep is complete.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1345
No description provided.