Transparency opacity alpha with Color Extensions Grayscale

Post questions on how to use or achieve an effect in Inkscape.
ChrisLo
Posts: 14
Joined: Fri Feb 10, 2012 8:11 am

Transparency opacity alpha with Color Extensions Grayscale

Postby ChrisLo » Fri Feb 10, 2012 9:18 am

I do the following on color vector logos and images to make a nice white or black colored version (depending on background) with transparency / opacity / alpha of the paths set to Luminance of the previous color (dark paths should become opaque, light paths transparent - see example):
  • selecting all paths > Extensions > Color > Grayscale: getting Luminance.
  • selecting all paths > Extensions > Color > Negative: inverting Luminance.
  • select every path and changing the opacity to the RGB-value: dark colors now get transparent, light colors remain opaque.
  • selecting all paths and coloring them white (for dark background) or black (for light background).

If the Paths are simple this is ok, but is there an easy way to automate this (macro/filter/extension)?
I have no coding experience, but looking in the \share\extensions\ folder and in the py files I guess only the RGB values can be calculated? I found no extension that changes the opacity value. Is this possible and can some experienced user help me?

Image

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Transparency opacity alpha with Color Extensions Graysca

Postby v1nce » Mon Feb 13, 2012 10:21 am

Filters/Filter editor => new filter => add new fx :color matrix ; choose luminance to alpha
apply the filter on all shapes

ChrisLo
Posts: 14
Joined: Fri Feb 10, 2012 8:11 am

Re: Transparency opacity alpha with Color Extensions Graysca

Postby ChrisLo » Tue Feb 14, 2012 4:07 am

This filter was known to me: Color Matrix > Luminance to Alpha.
Howewer the result is not the same; this filter only allows to get black transparency by filter. Neither the color nor the transparency can be adjusted manually.
If possible, I guess only a color extension will be able to do the same as my manual workflow. See confrontation.
Image

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Transparency opacity alpha with Color Extensions Graysca

Postby v1nce » Fri Feb 17, 2012 6:37 am

copy the line below in a new file and save it as whateveryouwant.svg
it will contains two filters

1) "withslider" filter

select your shapes.
go to Filters/filter editor.
check "withslider".
in the filter designer, you can click one of the last two rows (see image) then you'll get a slider to set the hue or the saturation
it should behave well for primary color (red,green,blue)

if you can't get the exact color you need, you can set it directly in the matrix (see right part of image)

2) "simple" filter

the simple filter contains a matrix like this
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
-0.2125 -0.7154 -0.07 0 1 => with 0,0,0 in the last column we'll get black

this last column should be filled with your rgb values
eg
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
-0.2125 -0.7154 -0.07 0 1 => full red

0 0 0 0 1
0 0 0 0 1
0 0 0 0 0
-0.2125 -0.7154 -0.07 0 1 => yellow (red+green)


lines to be saved as SVG
============================

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="500" height="500" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1">
<defs>
<filter inkscape:label="simple">
<feColorMatrix
values="0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
-0.2125 -0.7154 -0.07 0 1 "
/>
<feComposite
in2="SourceGraphic"
operator="in" />
</filter>

<filter inkscape:label="withslider">
<feColorMatrix
values="0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
-0.2125 -0.7154 -0.07 0 1 "
result="result1" />
<feComposite
in2="SourceGraphic"
operator="in" />
<feColorMatrix
type="hueRotate"
values="0" />
<feColorMatrix
type="saturate"
values="1" />
</filter>
</defs>
</svg>

====================
end of file

http://img23.imageshack.us/img23/5127/coloryq.jpg

ChrisLo
Posts: 14
Joined: Fri Feb 10, 2012 8:11 am

Re: Transparency opacity alpha with Color Extensions Graysca

Postby ChrisLo » Sun Feb 19, 2012 11:01 am

Wow, Merci!
Great filter code example. Edited it for extended colors and for using with filter menu.
Here the code to download on pastebin (also as attachement). Hope this is ok for you v1nce ;-)

Now for perfection: Filters can be removed; but can they also be applied to the objects like extensions (changing really the object)?
Attachments
transp-color-filters.svg
(2.18 KiB) Downloaded 231 times

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Transparency opacity alpha with Color Extensions Graysca

Postby v1nce » Mon Feb 20, 2012 9:45 am

ChrisLo wrote:
Here the code to download on pastebin (also as attachement). Hope this is ok for you v1nce ;-)



no problem. I should have done it myself (if I wasn't so lazy)

So bad Inkscape doesn't support feComponentTransfer, this could have been better


Return to “Help with using Inkscape”