Skip to content

Fill opaque exports behind a circle so JPEG corners stay white - #105

Closed
bfs2021 wants to merge 1 commit into
imerljak:mainfrom
bfs2021:fix/circle-jpeg-background
Closed

bfs2021 wants to merge 1 commit into
imerljak:mainfrom
bfs2021:fix/circle-jpeg-background

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 3, 2026

Copy link
Copy Markdown

Problem

Exporting a shape="circle" crop as JPEG produces black corners. Fixes #103.

Root cause

applyExportEffects skipped the automatic white background when the shape was circle, assuming the fill would repaint the masked corners. It would not: withBackground paints the fill behind the already-masked image (fillRect then drawImage), so only the area outside the circle is filled. Without it, JPEG drops the alpha channel and the transparent corners turn black.

Fix

Opaque formats now always get a background — fillColor if given, #fff otherwise — regardless of shape, by dropping the && shape === 'rect' condition. PNG/WebP keep transparent corners unless fillColor is set, and since the fill is applied after the mask, the circle stays intact.

Testing

  • Rewrote the assertion that codified the old behaviour into the regression the issue asks for: a circular JPEG now gets a #fff fill applied after the clip (mask runs first), while a circular PNG keeps its transparent corners with no default fill.
  • Ran the regression against the unfixed source first (red: 1 failed), then the full suite with the fix: 219 passed, 5 skipped. The only failing suite, tests/ssr/ssr-import.test.ts (spawnSync npm ENOENT), fails identically on a clean checkout in this Windows environment and is unrelated to the change.
  • tsc --noEmit, eslint and prettier clean on the touched files.

applyExportEffects skipped the automatic white background when the shape
was circle, assuming the fill would repaint the masked corners. It would
not: the fill goes behind the already-masked image, so only the area
outside the circle is filled. Without it, JPEG drops the alpha channel and
the transparent corners turn black (imerljak#103). Opaque formats now always get a
background — fillColor if given, #fff otherwise — regardless of shape;
PNG and WebP keep transparent corners unless a fillColor is set.
@imerljak

imerljak commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Already covered by #106.

@imerljak imerljak closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Circular JPEG exports have black corners

2 participants