Inkscape.org
Beyond the Basics Auto adjust fill colors to palette
  1. #1
    schulzki schulzki @schulzki

    Hi, I would like to reuse a set of icons I created, but they have to be adjusted colorwise to match the customer's CI.

    So I am looking for a way to (auto) map fill colors of shapes to a fixed set of colors. Something like "find the nearest color (in terms of RGB proximity) from the current palette" or so.

    Is there a way to achieve this in inkscape?

  2. #2
    Tyler Durden Tyler Durden @TylerDurden

    Fully automatic... maybe not.  

    There is a color replace extension, where you can enter the hex of the new color and all instances of the old color will be updated.

    How many colors are involved? Trade colors are commonly limited to a handful.

  3. #3
    schulzki schulzki @schulzki

    Yes, I started with "replace color..." extension and it also works on grouped elements which is very useful in this case. I just thought there might be something more sophisticated, so I can get a quick impression without the repetitive work for each color.

    Number of colors is also a good point, it really varies.  In this case I can use an extended palette of 8 colors + shades, but sometimes I am restricted to 5 or even 3. 

    I started getting familiar with the new extension api just recently, so if there is nothing like this it might be a good idea for a next project 😊

  4. #4
    Tyler Durden Tyler Durden @TylerDurden

    Another extension that might be of interest: https://inkscape.org/~jeko/%E2%98%85color-swap

  5. #5
    Tyler Durden Tyler Durden @TylerDurden

    There is also a "Color Harmony) extension in the Mightyscape collection that generates palettes, but also applies a generated palette to selected objects. There might be a hack possible to use a specific palette for experimentation.

  6. #6
    schulzki schulzki @schulzki

    Color harmony looks super interesting! I didn't figure out how to use it yet, but a color wheel extension is something I always wanted in Inkscape. Plus it really might be a good source as starting point for my icon use case!

    Do you know if there is any doc/tutorial on how to use it? There seem to be not much on any of the mighytscape extensions...

    There are lots of great extensions out there, but they are hard to find sometimes. Hope the majority will find their way to the extension manager by the time. 

     

  7. #7
    inklinea inklinea @inklinea⛰️

    If you are able to write python code. There is a function in the middle of this script https://mike632t.wordpress.com/2019/02/23/finding-the-closest-matching-named-colour-in-python/

    def _get_closest_colour

    It works using a hex value and a list of colours

    There are also a couple of links at the top of the script to stackoverflow

  8. #8
    Tyler Durden Tyler Durden @TylerDurden

    I'm not sure the save palette and magic colors work in the Harmony extension... I can't get them to work. 😕

  9. #9
    inklinea inklinea @inklinea⛰️

    I think the Harmony extension generates a palette based on selected objects ? 

    I had a look at wikipedia https://en.wikipedia.org/wiki/Color_difference

    It was simpler to try to write something from scratch - this should work - does require PIL ( which should be included with Inkscape 1.1+ on Windows  - and most Linuxes )

    https://gitlab.com/inklinea/indexed-colour

     

  10. #10
    inklinea inklinea @inklinea⛰️

    However, for small palettes - the result is not that great.

  11. #11
    Tyler Durden Tyler Durden @TylerDurden

    Yes, the Harmony works to generate the colors, but the two tabs to save the generated palette and colorize other objects don't do anything here.

  12. #12
    inklinea inklinea @inklinea⛰️
    *

       # Save tab
        # ========
        def save_palette(self, palette):
            # TODO: implement
            # if not hasattr(self.palette, 'name'):
            #     if type(file_w) in [str, unicode]:
            #         self.palette.name = basename(file_w)
            #     else:
            #         self.palette.name='Colors'
            pass


        # Colorize tab
        # ============

        def colorize(self):
            # TODO: implement
            pass

     

    That part of the code might explain why - but I can see the logic - create a group off canvas with a specific label and <rect> which each contain a colour. Then loop through to export to a .gpl palette.

    [ Edit - that comment about not working great for small palettes, was in reference to what I wrote, not colour harmony ! ]

    Colour Harmony does something different - generates complimentary colours rather than just extracting all colours from the objects. 

     

  13. #13
    Tyler Durden Tyler Durden @TylerDurden

    The new extension is nice. 👌

    (Watch out for objects vanishing if the live preview is toggled a few times.)

  14. #14
    schulzki schulzki @schulzki
    inklinea

    # TODO: implement

     

    love that 😂 but I admit it's also in my code regulary, I like coding top down.

    I think color harmony is super useful and should be completed or even better extended, it would be perfect if it had a graphic interface like https://color.adobe.com/de/create/color-wheel (but I am not familiar with gtk and dont know what effort this would be).

    I also agree that my icon coloring is a different use case and meanwhile I really would like to project that as an extension. 

    thanks @tyler durden and @inklinea for all your helpful links!

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Auto adjust fill colors to palette