Inkscape Community

Help Using Inkscape => Beyond the Basics => Topic started by: markymark on April 30, 2019, 01:20:17 PM

Title: How to get color at specified point? (extensions)
Post by: markymark on April 30, 2019, 01:20:17 PM
What is the function I call to get the color at a specific point? Something like color = getColor(x,y).
Title: Re: How to get color at specified point?
Post by: brynn on April 30, 2019, 02:03:21 PM
Welcome to the forum!

Is this a question about writing an extension?  I can't answer that directly, but this page on the Inkscape website tells a lot about writing extensions:  https://inkscape.org/develop/extensions/  Or someone else might know.
Title: Re: How to get color at specified point?
Post by: markymark on April 30, 2019, 06:14:12 PM
yes extensions. I can't seem to find what I'm looking for at the page you provided. Essentially I'm looking for a way to use the dropper tool but in code.
Title: Re: How to get color at specified point? (extensions)
Post by: brynn on April 30, 2019, 07:56:27 PM
Moini might know.  She'll be along before too long.  If not, or if she doesn't know, we can put you in contact with developers (who tend not to visit forums).  Or at least more advanced users.

Title: Re: How to get color at specified point? (extensions)
Post by: Moini on May 01, 2019, 10:05:37 AM
There is no such function call available. You would have to:

- Export to PNG in a suitable resolution
- Examine the corresponding pixel in the PNG in, e.g., imagemagick or PIL/pillow
Title: Re: How to get color at specified point? (extensions)
Post by: Lazur on May 01, 2019, 03:59:52 PM
Thinking out loud.

Extensions can modify specified colours of an object. You may apply a colormatrix on a raster image, edit steps of gradients -with a colormatrix- so guessing if it was about an object inside a selected area using that may work instead.

On the other hand, there is the tiled clones option and the spray and scatter tool which actually generates data based on underlying pixels.
Probably if you compiled your own version of inkscape you could modify some of those to add in new features?
Title: Re: How to get color at specified point? (extensions)
Post by: markymark on May 01, 2019, 09:53:22 PM
Basically I was following this tutorial  http://goinkscape.com/low-poly-art-tutorial-using-inkscape/ (http://goinkscape.com/low-poly-art-tutorial-using-inkscape/). The second part of the tutorial "2. COLOR THE POLYGONS", requires going through each individual triangle and using the dropper tool to get the color of the raster image under it. I was hoping to automate this process with an extension but it seems like the function I need doesn't exist at the moment.

Is there an easy way to export to png and use imagemagick via python functions?
Title: Re: How to get color at specified point? (extensions)
Post by: Moini on May 02, 2019, 08:43:38 AM
Ah. This is what I would do:

- use the spray tool to spray copies of a circle with unset fill, set to use the background color for the fill of the sprayed objects, onto the image you want to trace
- use the Delaunay method on the circles, in the mode of 'using the color of the objects'

Done.

This took me about 2 minutes to do:



Title: Re: How to get color at specified point? (extensions)
Post by: Moini on May 02, 2019, 08:44:44 AM
(Spray tool settings can be refined, too.)
Title: Re: How to get color at specified point? (extensions)
Post by: markymark on May 02, 2019, 11:14:07 AM
This worked for me. Thanks.