Basically what I'm seeing is when I create an SVG image with partially transparent png images inside, if I set the image opacity or a parent of the image's opacity, the transparent portions of the image are turned to black and then the opacity is applied.
When the SVG is viewed in the browser (inline) the transparent portions are NOT turned black (as expected) but when run through convert, they become black (and then gray after the opacity is applied).
A sample SVG that exhibits this behavior:
<svg width="800" height="600">
<image width="800" height="600" opacity="0.5" xlink:href="http://upload.wikimedia.org/wikipedia/c ... g"></image>
</svg>
And I'm running it through convert like: `convert svg:test.svg png:bad.png`
I'm using convert 6.8.7-0
I figure that I'm missing something in terms of alpha channels or whatnot...
Ideas?
Transparent areas of SVG layer being filled in by black
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Transparent areas of SVG layer being filled in by black
just a wild guess, but try
Code: Select all
convert svg:test.svg PNG32:bad.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Transparent areas of SVG layer being filled in by black
I'm not sure what you are asking. You are getting black, but shouldn't be? I don't get any opaque black. I'm on IM v6.8.7-0, Inkscape 0.48 (the current version), on Windows 7.
I'm not an SVG expert, but I think you need the xmlns:xlink header. I'm having problems linking to the remote file, so I "wget" it. My SVG is now:
And the following commands work:
t0.png is opaque with a white background. t1.png has transparency: the green shape is 50% opaque; the background is fully-transparent black.
Note that if you make t1.png opaque, you will get black.
I'm not an SVG expert, but I think you need the xmlns:xlink header. I'm having problems linking to the remote file, so I "wget" it. My SVG is now:
Code: Select all
<svg
xmlns:svg="http://www.w3.org/2000/svg" version="1.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="800" height="600">
<image x="1" y="1" width="800" height="600" opacity="0.5" xlink:href="Triple-Spiral-4turns_green_transparent.png"></image>
</svg>
Code: Select all
convert -verbose test.svg t0.png
convert -verbose -background none test.svg t1.png
Note that if you make t1.png opaque, you will get black.
snibgo's IM pages: im.snibgo.com
Re: Transparent areas of SVG layer being filled in by black
So the original image (the png) is transparent with green spirals (no white, no black).
If I do not set the opacity on the image element and run it through `convert -background none bad.svg bad.png`, I get the same as the original png, transparent background, fully opaque green spiral.
If I do set the opacity (say to 0.5), I basically get the original image with the transparent portions turned black and then the entire image set to 50% opacity. So black background with green spiral and the background + spiral all at 50% opacity.
I guess what I'm looking for is to have the image element have a 50% transparency for the green pixels and not have any black pixels added.
If I put the same SVG in my browser (chrome/firefox/whatever), I get the expected outcome. Surely IM can render the same output...
If I do not set the opacity on the image element and run it through `convert -background none bad.svg bad.png`, I get the same as the original png, transparent background, fully opaque green spiral.
If I do set the opacity (say to 0.5), I basically get the original image with the transparent portions turned black and then the entire image set to 50% opacity. So black background with green spiral and the background + spiral all at 50% opacity.
I guess what I'm looking for is to have the image element have a 50% transparency for the green pixels and not have any black pixels added.
If I put the same SVG in my browser (chrome/firefox/whatever), I get the expected outcome. Surely IM can render the same output...
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Transparent areas of SVG layer being filled in by black
That's not entirely correct. The png has two colors: fully opaque green, and fully transparent black. I can see this with Gimp, or with:joekarl wrote:So the original image (the png) is transparent with green spirals (no white, no black).
Code: Select all
convert Triple-Spiral-4turns_green_transparent.png -unique-colors txt:
Ok. I get something different. I get (t1.png) semi-transparent green and fully-transparent black, which I think is what you want.joekarl wrote:If I do set the opacity (say to 0.5), I basically get the original image with the transparent portions turned black and then the entire image set to 50% opacity. So black background with green spiral and the background + spiral all at 50% opacity.
I'm on IM v6.8.7-0, Inkscape 0.48 (the current version), on Windows 7. What are you using?
EDIT: I should add: I suppose this is part of a larger project. If you just want to resize the png image and modify transparency, there are much easier methods:
Code: Select all
convert Triple-Spiral-4turns_green_transparent.png -resize 800x600! -channel A -evaluate multiply 0.5 t2.png
snibgo's IM pages: im.snibgo.com