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

Convert transparent svg to png #184

Closed
plepe opened this issue Aug 2, 2014 · 8 comments
Closed

Convert transparent svg to png #184

plepe opened this issue Aug 2, 2014 · 8 comments
Labels

Comments

@plepe
Copy link

plepe commented Aug 2, 2014

I'm trying to convert a SVG file with transparent background to PNG, but the outcome always has a white background. I'm using

with Image(filename="test.svg") as img:
    img.format = 'png'
    img.alpha_channel = True # useless, is True anyway
    img.background_color = Color('#0000') # useless, I can choose any color, result always has white background
    img.save(filename="test.png")

Please assist me.

@dahlia
Copy link
Collaborator

dahlia commented Aug 2, 2014

It seems due to ImageMagick’s poor support of SVG. Although I heard that it can be solved if ImageMagick is forced to use Inkscape as its SVG delegate (see delegates.xml), but I’m not sure about that.

@dahlia dahlia added the bug label Aug 2, 2014
@plepe
Copy link
Author

plepe commented Aug 2, 2014

You can do it with the ImageMagick command line utility:

convert -background transparent file.svg file.png

It's important to supply -background transparent prior to opening the file. So I thought, maybe I can open the file in Wand using Image(filename="test.svg", background=None) (or something similar), but unfortunately the background parameter is only accepted when creating images.

@dahlia dahlia closed this as completed in 950de77 Aug 2, 2014
@dahlia
Copy link
Collaborator

dahlia commented Aug 2, 2014

The bug is fixed in 0.3.8, a just released latest version.

@plepe
Copy link
Author

plepe commented Aug 2, 2014

Confirmed. Thanks a lot!

@vvsotnikov
Copy link

I have the same issue with Wand 0.6.1 and IM 6.9.10-23 with Inkscape delegate.

@BertrandBordage

This comment has been minimized.

@BertrandBordage

This comment has been minimized.

@BertrandBordage
Copy link

For reference, after multiple different types of attempts, I manage to get it working with:

from wand.color import Color
from wand.image import Image

with Image(filename=path, background=Color('transparent')) as image:
    …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants