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

change default background color #501

Open
sunwoo76 opened this issue Sep 2, 2024 · 1 comment
Open

change default background color #501

sunwoo76 opened this issue Sep 2, 2024 · 1 comment

Comments

@sunwoo76
Copy link

sunwoo76 commented Sep 2, 2024

I have a simple code as below:

image = pyvips.Image.new_from_file("output22.svg")
image.write_to_file("output22.png")

The result always have RGB white colored background.

how can I save the svg file with transparent rgba background in png format?

Thanks!

@jcupitt
Copy link
Member

jcupitt commented Sep 3, 2024

Hello @sunwoo76,

The best way is to use an SVG file with a transparent background, of course. With this SVG:

lion

I can run:

vips copy lion.svg x.png

To make:

x

If your SVG file has a solid background, you can write some code to search for background pixels and make them transparent, but the quality may not be so good. It's hard to get the edges exactly right, and hard to always detect all the background.

Do you have a sample SVG? What quality level do you need?

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

No branches or pull requests

2 participants