It is currently Thu Jul 04, 2024 4:31 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 5:46 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
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.

_________________
TinT


Last edited by trandoductin on Wed Sep 21, 2016 2:23 pm, edited 8 times in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 8:58 pm  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
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

_________________
TinT


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 9:06 pm  (#3) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
Interesting script Tin.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 9:58 pm  (#4) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
Sweetness!

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 10:33 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jun 02, 2013
Posts: 2075
I get the following error:

Image

_________________
Image


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 10:37 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
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.

_________________
TinT


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 11:42 pm  (#7) 
Offline
GimpChat Member

Joined: May 12, 2015
Posts: 4694
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!!!


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 11:45 pm  (#8) 
Offline
Global Moderator
User avatar

Joined: Oct 02, 2014
Posts: 4514
Location: Sydney Australia
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

_________________
Image

Respect should be offered freely but hard earned


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Tue Sep 20, 2016 11:57 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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...",
    "",

_________________
"Where am I ?"


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 12:10 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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
)

_________________
"Where am I ?"


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 12:17 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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)

_________________
"Where am I ?"


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 1:13 am  (#12) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
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.

_________________
TinT


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 1:21 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
replace <Image> with <Gradients>
it will show up under gradients, right clicking

_________________
"Where am I ?"


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 1:28 am  (#14) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
no, tried it myself, the name input field disappears (why?) in the create new, and is not selectable in the others (why?)

_________________
"Where am I ?"


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 1:34 am  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
maybe Ofnuts can suggest the correct way...

_________________
"Where am I ?"


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 1:46 am  (#16) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
I tried changing it to <Gradients>
took out the "*" and the image,layer parameters.
but my New Gradient Name prompt disappeared.

_________________
TinT


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 2:03 am  (#17) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
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.

_________________
TinT


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 2:19 am  (#18) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
okay added release 4 which you can access by right clicking on a gradient and select SVG/ then one of the 3 functions.

_________________
TinT


Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 2:49 am  (#19) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2438
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.

_________________
Image


Last edited by rich2005 on Wed Sep 21, 2016 4:49 am, edited 2 times in total.

Top
 Post subject: Re: Creating svg gradients for Gimp (python script 3 functions).
PostPosted: Wed Sep 21, 2016 3:24 am  (#20) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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()

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Eager to learn how to draw pixel functions in GIMP python

2

No new posts Attachment(s) Scripting GEGL functions

52

No new posts Attachment(s) Learning to do first Python script

6

No new posts .py script not showing under Python-Fu

3

No new posts Attachment(s) My first Python Script for Gimp

7


cron

* Login  



Powered by phpBB3 © phpBB Group