1

Is there a quick way to apply an entire color palette to a linear gradient in Inkscape?

I built a custom .gpl file which is available along with the native palettes.

However, I can't see where I can assign an entire palette to a gradient. Is this possible? Without creating individual stops for each palette color? (there are 41 colors in my palette)

I'm running v1.1

Cheers

added 2021-08-02

Here's some python code to output formatted tags (as @Xrott's web tool will do):

# works for a list of rgb tuples with integer values

rgb_tup_lst =[(127, 0, 0), (138, 0, 0), (150, 0, 0)]
stops = [(n/len(rgb_tup_lst)) for n,i in enumerate(rgb_tup_lst)]
stops_rgb_lst =  list(zip(stops, rgb_tup_lst))
for s in stops_rgb_lst:
    print("<stop offset='{}' stop-color='rgb{}'/>".format(round(s[0],3), s[1]))

Then, can copy and past from your IDE and follow directions from @Xrott's answer...please be sure to still upvote their answer if you find my python code helpful.

1 Answer 1

4

This sounds like a job for a script. For every color in your .gpl file, output a line like this:

<stop offset="[i / (length - 1)]" stop-color="rgb([r], [g], [b])"/>

I created a quick little online tool to convert your .gpl file to SVG gradient-stops.

Then create a placeholder-gradient in Inkscape, save and open your file in a text-editor and replace the <stop>-tags inside the placeholder <linearGradient> with your generated stops.

Now you can reload your file and continue editing in Inkscape.

1
  • Nice! Thank-you. Your online tool and text editor approach works nice (and quick) for me. I'm intrigued by scripting directly, but I looked up the Inkscape wiki and it'd take me a bit longer to figure-out so didn't attempt (I've got good python skills, just haven't tried with Inkscape...yet). Cheers
    – CreekGeek
    Commented Aug 1, 2021 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.