Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG Output does not support transparency #4088

Open
1 task done
manuel5975p opened this issue May 7, 2024 · 4 comments · May be fixed by #4251
Open
1 task done

PNG Output does not support transparency #4088

manuel5975p opened this issue May 7, 2024 · 4 comments · May be fixed by #4251
Labels
bug Something isn't working png Related to PNG export.

Comments

@manuel5975p
Copy link

Description

Synopsis

Setting no background results in a transparent svg, but opaquely white png.

Example

#lorem(20)

Results in

SVG

transparent


PNG

transparent

Reproduction URL

No response

Operating system

Web app, Linux

Typst version

  • I am using the latest version of Typst
@manuel5975p manuel5975p added the bug Something isn't working label May 7, 2024
@Enivex Enivex added the png Related to PNG export. label May 7, 2024
@benlubas
Copy link

benlubas commented May 24, 2024

So, this works:

diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs
index e145a820..a3b72022 100644
--- a/crates/typst-cli/src/compile.rs
+++ b/crates/typst-cli/src/compile.rs
@@ -331,7 +331,7 @@ fn export_image_page(
 ) -> StrResult<()> {
     match fmt {
         ImageExportFormat::Png => {
-            let pixmap = typst_render::render(frame, command.ppi / 72.0, Color::WHITE);
+            let pixmap = typst_render::render(frame, command.ppi / 72.0, Color::WHITE.with_alpha(0.));
             let buf = pixmap
                 .encode_png()
                 .map_err(|err| eco_format!("failed to encode PNG file ({err})"))?;

it lets me produce an image like this:

test

by running typst compile test.typ test.png.

With this change, #set page(fill: white) will return the white background with no issues.

It does change a default though, I'm not sure what people (maintainers) think about that?

@laurmaedje
Copy link
Member

There was some discussion about this on the Discord, starting with this message: https://discord.com/channels/1054443721975922748/1088371867913572452/1237388946946658304

@benlubas
Copy link

@laurmaedje thanks, am I correct in that this

I wonder if it would make sense to get the color for the png background from the #page.fill property? And just keep white if its not there?

is the preferred solution then? and someone said they would work on it and then disappeared for a bit?

I might just try and do it myself if that's an acceptable solution

@benlubas
Copy link

Have something that appears to work, but it's a total shot in the dark from me b/c I've never worked on this project before. I will open a PR later tonight after I eat dinner.

@benlubas benlubas linked a pull request May 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working png Related to PNG export.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants