pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

change default background color

Open sunwoo76 opened this issue 1 year ago • 1 comments

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!

sunwoo76 avatar Sep 02 '24 23:09 sunwoo76

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?

jcupitt avatar Sep 03 '24 03:09 jcupitt