[solved] Changing transparent objects to colored

Post questions on how to use or achieve an effect in Inkscape.
perwin
Posts: 5
Joined: Mon Jul 24, 2017 3:02 am

[solved] Changing transparent objects to colored

Postby perwin » Mon Jul 24, 2017 7:03 am

Hello, I am looking for how I can achieve this effect with Inkscape - there must be a way.
I need to transform many semitransparent objects to other object which are not semitransparent, but have the same color when they were.

I think this image will explain what I mean:
opacity-rgb.png
opacity-rgb.png (59.38 KiB) Viewed 2440 times


From the object with the top value (eg. RGB(147, 102, 36) and 40% opacity) I want to get an object with the bottom value (RGB(212, 194, 167) and 100% opacity).

Is this possible with Inkscape?

Thank you very much.
Last edited by perwin on Fri Jul 28, 2017 8:11 pm, edited 1 time in total.

User avatar
Xav
Posts: 1125
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Changing transparent objects to colored

Postby Xav » Mon Jul 24, 2017 7:46 am

I'll ignore the fact that a translucent fill will look different depending on what colour is behind it, and assume that you're either working on a white background or that you've already taken that into account. In which case the simplest solution is to select the object, then use the :tool_dropper: tool and click on the middle of the same object. Make sure the "Pick" button is de-selected in the toolbar - if that's enabled it will pick the colour and alpha value, but if it's not it will set the colour to a 100% opaque version of the translucent one you can see.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

perwin
Posts: 5
Joined: Mon Jul 24, 2017 3:02 am

Re: Changing transparent objects to colored

Postby perwin » Mon Jul 24, 2017 4:22 pm

Of course it will look different depending on the background. It is great there is a manual tool for doing this.
But I was looking for an automated process - python extension maybe? Because I have file with thousands of small semitransparent object and I would like to make them 100% opaque.

This is what the extension would do:
opacity-rgb-2.png
opacity-rgb-2.png (45.39 KiB) Viewed 2396 times

When there are 2 or more overlapping objects, it would cut them to pieces with the final color the will have with 100% opacity.

Is this possible? I am not good in python so I don't know...

User avatar
Xav
Posts: 1125
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Changing transparent objects to colored

Postby Xav » Mon Jul 24, 2017 5:04 pm

You probably should have explicitly asked for an automated process in your first post, or said that it was thousands of objects rather than "many", which is a bit ambiguous.

To your question: is it possible with a Python extension? Probably, given a sufficiently capable programmer. Is it practical, however? Probably not.

The tricky bit isn't the opacity, it's the requirement to cut overlapping pieces into separate sections first. From the perspective of an extension author they would need to take into account the fact that the overlaps could be any arbitrary shapes, and there could be multiple overlaps to consider. What happens if there are gradients?

I presume you need the final shapes to accurately and precisely match the originals. If not (and if there aren't too many individual colours in the image), you might be able to achieve something by creating a bitmap copy of your image (Edit > Make a bitmap copy, or File > Export PNG image, then import the result into a new image) followed by tracing the bitmap using multiple scans (Path > Trace Bitmap). But that will result in each object being made up of a path with lots of nodes, not the simple smooth shapes you started with.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

Polygon
Posts: 310
Joined: Thu Dec 19, 2013 3:27 am

Re: Changing transparent objects to colored

Postby Polygon » Mon Jul 24, 2017 6:26 pm

When it´s just for image export the easiest way is to put a white plane behind/under all semi transparent objects and export to PNG - Done.
Opaque.png
Opaque.png (43.29 KiB) Viewed 2374 times


Cheers
P.

tylerdurden
Posts: 2109
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Changing transparent objects to colored

Postby tylerdurden » Mon Jul 24, 2017 10:01 pm

perwin wrote:...I have file with thousands of small semitransparent object and I would like to make them 100% opaque...


That's pretty challenging. What generated the original file? Is there an example you can share?
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

User avatar
Maestral
Posts: 934
Joined: Sat Aug 27, 2011 7:10 am

Re: Changing transparent objects to colored

Postby Maestral » Tue Jul 25, 2017 12:02 am

@ OP
Your posts are quite ambiguous and you haven`t even stated what do you need at the end - raster or vector?
Either way - you played with coloured glass pieces (vectors) and would like to turn them into wood, metal... (raster)

If you played with coloured glass and would like to have a nice vitrage but with a colour of overlapping pieces - you`ll have to cut the new ones and from the matching colour. Right? So... I`m in fact afraid of your answer.

On the other hand, if you`d like to have it all as wood, paper, metal... rasterize the whole thing and recolor (if even needed).

While not having a third hand, I`ll be glad to fill one of yours with some currency (of your choice) when you finish this all mighty Python extension ,)

Now, seriously - planning is a mother of all well-executed endeavours.
:tool_zoom: <<< click! - but, those with a cheaper tickets should go this way >>> :!:

perwin
Posts: 5
Joined: Mon Jul 24, 2017 3:02 am

Re: Changing transparent objects to colored

Postby perwin » Tue Jul 25, 2017 12:25 am

I will tell you more information: the file containing so many objects is a periodic table, imported from PDF containing everything in vector. My first problem was to ungroup everything (hundreds of groups), thanks god there is an extension called Deep Ungroup working under Windows.

At the end of the process I need vector too, so exporting to bitmap is not a good solution.

Anyway I have a lot expirience with programming (not python though), so maybe I will run out of other options and end with programming my own extension...

Xav wrote:The tricky bit isn't the opacity, it's the requirement to cut overlapping pieces into separate sections first.

Well it should not be so hard, because Inkscape has powerful tools for cutting various vector shapes which I would use.

Xav wrote:What happens if there are gradients?

In fact it is pretty easy to answer - one or more new gradients will be created, based on overlapping and transparency.

Lazur
Posts: 4580
Joined: Tue Jun 14, 2016 10:38 am

Re: Changing transparent objects to colored

Postby Lazur » Tue Jul 25, 2017 1:45 am

perwin wrote:
Xav wrote:What happens if there are gradients?

In fact it is pretty easy to answer - one or more new gradients will be created, based on overlapping and transparency.


Just wondering, two semi-transparent gradients overlaying would produce -many more gradients?

What if both were radial gradients.


Oh and what if there was a group somewhere with a fade to transparent masking.

User avatar
Xav
Posts: 1125
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Changing transparent objects to colored

Postby Xav » Tue Jul 25, 2017 2:37 am

As Lazur pointed out, converting overlapping translucent gradients into new (flattened) gradients is not a trivial task.

perwin wrote:
Xav wrote:The tricky bit isn't the opacity, it's the requirement to cut overlapping pieces into separate sections first.

Well it should not be so hard, because Inkscape has powerful tools for cutting various vector shapes which I would use.


AFAIK those tools aren't available within a Python extension, other than by having the extension run another copy of Inkscape as a background process.

Extensions are essentially external scripts which get passed the XML document, and return a modified XML document. So any boolean operations on your elements would need to be done in the Python environment (complex), or by calling a second instance of Inkscape as a command-line tool (probably complex in a different way). Plus you want the splitting done based on colour, not on the original shapes (again, this brings us back to the problem with gradients).

I don't mean to "rain on your parade", but I think you're underestimating what would be involved in creating a generic extension to do this. It might be practical to produce something more limited that would suit your needs for this specific file, but a general solution is likely to be extremely hard, if not impossible, to create.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

perwin
Posts: 5
Joined: Mon Jul 24, 2017 3:02 am

Re: Changing transparent objects to colored

Postby perwin » Tue Jul 25, 2017 10:07 pm

Xav wrote:It might be practical to produce something more limited that would suit your needs for this specific file, but a general solution is likely to be extremely hard, if not impossible, to create.

I suppose you are right, but still I believe it is possible. For my current needs it doesn't have to be an universal solution for all possible cases of overlapping and object shapes with gradients and another properties. I just have white background and single-colored objects with different opacity which don't overlay other objects, so the math behind that should be a lot simpler.

Anyway, this "flattening of transparent artwork" is offered by many commercial programs, eg. Adobe Indesign (https://helpx.adobe.com/indesign/using/flattening-transparent-artwork.html).
Image
I believe this is something Inkscape should offer too!

I just need to export PDF prepared for printing, where semitransparent object mustn't be contained. Next problem was all colors should be in CMYK color range, and that I currently solve by importing SVG file to Scribus and editing colors there. But Scribus doesn't offer this flattening too.

EDIT: Because I haven't found any other solution for solving this, I am currently working on simple extension which flattens all selected semitransparent objects, only using document's background color. It doesn't cut anything, it also doesn't solve problem of overlapping objects or gradients. It just changes opacity of selected objects to 100%, alpha to 255 and changes their color (and also their border's color) by this simple equation:
mixing-rgb-equation.png
mixing-rgb-equation.png (1.75 KiB) Viewed 2222 times

where (R, G and B are calculated separately) c1 is color of the object, o1 is opacity of the object (in %), a1 is alpha of the object (number 0 to 255) and c2 is color of the background (opacity of the background is taken always 100% so it is not in this equation).

User avatar
Xav
Posts: 1125
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Changing transparent objects to colored

Postby Xav » Wed Jul 26, 2017 2:27 am

The inDesign page you linked to is a little different from what you've asked for previously in this thread. It specifically indicates that more complex areas will be rasterised - which skips over all the issues of complex overlapping gradients. But if you're happy to accept raster elements in your output then you may as well just add an opaque background and export to a PNG anyway. I had presumed that you wanted a purely vector solution.

That's not to say that Inkscape couldn't do with some better options for doing boolean division of multiple overlapping objects, but that would only solve part of your problem.

Feel free to add a feature request to the Inkscape bugtracker for a full "flattening" feature, like the one in inDesign - although I suspect the nuances involved in making it a sufficiently general purpose tool will mean it's not likely to get much traction with the developers. You never know, though, one of them might relish the challenge.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

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

Re: Changing transparent objects to colored

Postby v1nce » Wed Jul 26, 2017 3:08 am

if you look carefully you see they cheat [*] when cutting the pieces : they dropped the pink tint that you should see through the wave

* : in fact this not cheating because there's no solution to mix a vertical and horizontal gradient. There would be a solution which would be compositing the gradient but then you step back to your start point which is you're cutting into pieces because you can't compose. The second solution is to go raster for the gradient composition and to use vectors for the shapes

User avatar
Maestral
Posts: 934
Joined: Sat Aug 27, 2011 7:10 am

Re: Changing transparent objects to colored

Postby Maestral » Wed Jul 26, 2017 5:16 am

perwin wrote:...
At the end of the process I need vector too, so exporting to bitmap is not a good solution.

Shall I add a forum signature: "Told you so!" ,)

Again, seriously - brace yourself for a CMYK gradients !
Image
:tool_zoom: <<< click! - but, those with a cheaper tickets should go this way >>> :!:

Lazur
Posts: 4580
Joined: Tue Jun 14, 2016 10:38 am

Re: Changing transparent objects to colored

Postby Lazur » Wed Jul 26, 2017 5:31 am

Maestral wrote:Image


Off topic:
Never ceases to amaze me how an rgb jpeg can showcase the visible colours outside the rgb gamut.

User avatar
Maestral
Posts: 934
Joined: Sat Aug 27, 2011 7:10 am

Re: Changing transparent objects to colored

Postby Maestral » Wed Jul 26, 2017 5:35 am

lol

p.s.
Those would be words of wisdom and comfort for this poor soul when he dives into cmyk gradients. But, hey! We all are so fortunate to have soooo supportive admin`s here ,)

p.p.s.
LOL
________________________________________________________________________________________________________
v you could not possible be more descriptive regarding the content of those minions..oh, no - wait - millions. ?! no, i mean billions. Right?
Last edited by Maestral on Wed Jul 26, 2017 8:33 am, edited 1 time in total.
:tool_zoom: <<< click! - but, those with a cheaper tickets should go this way >>> :!:

Lazur
Posts: 4580
Joined: Tue Jun 14, 2016 10:38 am

Re: Changing transparent objects to colored

Postby Lazur » Wed Jul 26, 2017 5:54 am

Off topic:
And in fact we are only 15 posts away from our 100000th post on the forum. Maybe worth a section at the feedback topics.

Sorry perwin for not being much of a help with this topic.

perwin
Posts: 5
Joined: Mon Jul 24, 2017 3:02 am

Re: Changing transparent objects to colored

Postby perwin » Wed Jul 26, 2017 6:02 am

Well thank you Xav and v1nce, I didn't read the page I reffered to completely so I didn't notice that they use rastering too.

Anyway, it took me about an hour to complete the extension I was talking about (it could have been a lot faster if I knew how to code extensions before). I called it "Simple Transparency Flattener" and it just modifies selected objects by changing their opacity to 100%, alpha to 255 and it calculates their new RGB values from previous and from document's background with the equation I posted before. It also sets document's alpha value to 255 and the background can be any color, not just white. The extension is located under Colors submenu, and when you click it you should see no difference in look of the objects.
So this problem is solved by now! :-)

inkscape_simple_transparency_flattener.zip
(2.07 KiB) Downloaded 37 times


Return to “Help with using Inkscape”

Who is online

Users browsing this forum: No registered users and 4 guests