GIMP Chat
http://gimpchat.com/

Creating svg gradients for Gimp (python script 3 functions).
http://gimpchat.com/viewtopic.php?f=9&t=14582
Page 1 of 3

Author:  trandoductin [ Tue Sep 20, 2016 5:46 pm ]
Post subject:  Creating svg gradients for Gimp (python script 3 functions).

Image
I got this idea from this thread: Creating svg gradients for Gimp
Image


I thought why not make methods that allows user to create .svg gradients for gimp gradients without having to look at or edit the text file manually.

So here it is (release 8):
Attachment:
svg-gradients.zip [3.29 KiB]
Downloaded 251 times


Release 8 Notes: Changed to use os.path.join() instead of hardcoding slashes so that it'll work on different OSes (as suggested by Dinasset).

Release 7 Notes: No function change. Changed code a little so that gradient_folder is defined in one place instead of 4 places.

Release 6 Notes: Missed a spot where i didn't change to forward slash so just putting that in there.

Release 5 Notes: changed backward slashes of directories (\\) to forward slashes (/) so that it might work for Linux (asking Rich to test for me in Linux) because I am on Windows and forward slashes still work on Windows).

Release 4 Notes: Moved the 3 functions to <Gradients>/SVG/
Access by right clicking on a gradient which i think is friendlier since for Adding Stop and Deleting range now you don't have select a gradient because it'll apply to the gradient that you've right clicked on.
Image

Release 3 Notes: previous releases followed the original thread format which creates valid svg gradient files but not valid .svg image files.
This release makes valid svg file so svg gradient files can be opened in GIMP as image as well if desired.
Note: If you have svg gradients created by earlier releases, you'll have to add a stop or delete a range which could just be a range that includes no existing stops to make the .svg files valid .svg files so that they can be opened as image)


There are 3 methods registered under <Gradients>/SVG/ (access this by right clicking a gradient will only work with created SVG gradients)
As you can see below,
1. New...
2. Add a Stop...
3. Delete Stops within Range...

Hopefully the names are self explanatory.
Here are options windows for the 3 methods
1. New... - Creates a new gradient with gradient name and stop color at 0% offset and stop color at 100% offset with specified opacity as well. (Note: if Gradient name already as exists as .svg file, it'll overwrite so you could use it to quickly overwrite an existing SVG gradient that you've created).
Image
2. Add a Stop - Adds a stop color to offset at percentage with specified color and opacity to an existing/right-clicked SVG gradient.
Image

3. Delete Stops within Range - Delete all stops within the specified range of an existing/right-clicked SVG gradient, if 0 and 100 is specified as range all stops will be deleted but then i put in a placeholder stop at 0% so that the svg is a valid gradient.
Image


Please try it out and let me know what y'all think.

Author:  trandoductin [ Tue Sep 20, 2016 8:58 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

sample run(s).

1. New SVG Gradient with black as start color, blue as end color
Image

2. Add SVG Gradient Stop with yellow at 25 percent
Image

3. Add SVG Gradient Stop with red at 75 percent
Image

4. Add SVG Gradient Stop with green at 50 percent
Image

Author:  Odinbc [ Tue Sep 20, 2016 9:06 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

Interesting script Tin.

Author:  mahvin [ Tue Sep 20, 2016 9:58 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

Sweetness!

Author:  The Warrior [ Tue Sep 20, 2016 10:33 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

I get the following error:

Image

Author:  trandoductin [ Tue Sep 20, 2016 10:37 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

The first one is just a message it's not an error (I should take that out now that i don't need that anymore)...
I have no idea what the 2nd message is complaining about since i don't do anything with .png files

EDIT: maybe you have that file in your gradients folder and since it's not a valid gradient file...my call to refresh gradients throws that error.
You should try moving that .png file of yours to a different location (outside of gimps gradients folder) and see if that error goes away.

2nd EDIT: took out that first message in release 2.

Author:  Pat625 [ Tue Sep 20, 2016 11:42 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

I must repeat!! It amazes me how quickly you can write a program. Don't tell me that if I knew coding I would not be amazed. I'm still amazed!!!

Author:  oldmangrumpy [ Tue Sep 20, 2016 11:45 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

Trandoductin - wow ... thank you, love this one; :clap

Not really sure what I am trying to do but its a lot of fun playing with these new gradients ...

Image

Author:  dinasset [ Tue Sep 20, 2016 11:57 pm ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

thanks, Tin, very useful tool.
May I suggest you to change the "*" to "" in the new gradient creation so that there is no need to have an open image?
    "<Image>/Python-Fu/Gradients/New SVG Gradient...",
    "",

Author:  dinasset [ Wed Sep 21, 2016 12:10 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

and:
would it be possible to see a created gradient in the image panel instead (or in addition to) the lateral gradients panel? what is needed?
(if I try to "open" it I get an error
GIMP Error
Opening 'C:\Users\Diego\.gimp-2.8\gradients\SVG Gradient 002.svg' failed:
Could not open 'C:\Users\Diego\.gimp-2.8\gradients\SVG Gradient 002.svg' for reading:
Unknown reason
)

Author:  dinasset [ Wed Sep 21, 2016 12:17 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

I noticed that you may remove the * also from the other two functions, as long as the gradient does not show up as an image (if ever)

Author:  trandoductin [ Wed Sep 21, 2016 1:13 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

dinasset wrote:
thanks, Tin, very useful tool.
May I suggest you to change the "*" to "" in the new gradient creation so that there is no need to have an open image?
    "<Image>/Python-Fu/Gradients/New SVG Gradient...",
    "",

I tried taking it out but then when the options window pops up it prompts for image and layer ... how do you make those disappear?

looking into making valid .svg so that it can be opened as image.

Author:  dinasset [ Wed Sep 21, 2016 1:21 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

replace <Image> with <Gradients>
it will show up under gradients, right clicking

Author:  dinasset [ Wed Sep 21, 2016 1:28 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

no, tried it myself, the name input field disappears (why?) in the create new, and is not selectable in the others (why?)

Author:  dinasset [ Wed Sep 21, 2016 1:34 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

maybe Ofnuts can suggest the correct way...

Author:  trandoductin [ Wed Sep 21, 2016 1:46 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

I tried changing it to <Gradients>
took out the "*" and the image,layer parameters.
but my New Gradient Name prompt disappeared.

Author:  trandoductin [ Wed Sep 21, 2016 2:03 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

I think i get it when you right click gradients
that gradient is passed in if you have first parameter defined at least i think that's what's happening.
So now i am trying to make Add Stop and Delete Range of stops to work on the svg gradient that is right clicked on.
And with the Add New I am adding an extra parameter to allow user to enter New Name...
it's sort'a all weird to me but i think i have something
will update soon.

Author:  trandoductin [ Wed Sep 21, 2016 2:19 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

okay added release 4 which you can access by right clicking on a gradient and select SVG/ then one of the 3 functions.

Author:  rich2005 [ Wed Sep 21, 2016 2:49 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

Gimp 2.8.18, Kubuntu 16.04

Tried v0.3 and that did not show up at all, almost immediately replaced by v0.4 which does show as a context entry in the gradients dialog.

but, guessing a Windows thing, for linux needed to change lines 38, 59, 98, 166
"~\\.gimp-2.8\\gradients\\"

to
"~/.gimp-2.8/gradients/"

otherwise the gradient does not save.

(edit: not quite true, it did save but in the home directory with a filename as
'home/me/~\.gimp-2.8\gradients\test.svg' ;) )

Nice utility.

Author:  dinasset [ Wed Sep 21, 2016 3:24 am ]
Post subject:  Re: Creating svg gradients for Gimp (python script 3 functions).

thanks Tin
Just to inform you - because all my resources are maintaned in subfolder - I added in your filter for myself the subfolder name
SVG\\
after Gradients\\ in the explicit filenames
if you will consider in a next release to allow a subfolder, it would be great IMO

For the problem indicated by Rich maybe you may use the python function-expression
os.path.join() which can be used in conjunction with os.path.sep()

Page 1 of 3 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/