It is currently Wed Apr 24, 2024 2:19 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: How to add a bunch of Curves presets at once in Linux
PostPosted: Fri Sep 02, 2016 11:17 pm  (#1) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
I didn't realize that not everything in GIMP works as easily as installing scripts or brushes. So when I downloaded an archive of 100 custom Curves presets I thought I would just throw them in the appropriate folder and be done with it. Turns out that is not the case.

Gimp stores curves presets in a single file that it overwrites each time you save a new preset. So the first caveat of this tutorial is to make sure you save a copy of the original before you start this and then save a copy of the new version when you finish. That way if GIMP overrides your work you can redo it.

I found the settings file in;
~/.gimp-2.8/tool-options/

I assume it's the same for any 2.8 installation.

The file is;
gimp-curves-tool.settings

Again, I expect this to be the same for others. You'll recognize the file if you've saved any presets because they will show up by name in the file. If you don't have any presets saved yet you may have to do so before continuing. It's possible GIMP doesn't generate this file until you save a preset.

Of course, finding the file is the easy part. The hard part is figuring out how to get one hundred other files merged into the file. This is complicated by the fact that the author(s) of the presets I downloaded didn't bother including the preset names in the text of the files. So if I just copied the files as is they would show up in the Presets dropdown as just a very long list of presets with generic, auto-generated names. Good luck remembering if Saved Setting 27 is the preset you want or not.


Also, all the presets saved via the Curves dialog begin with;
(GimpCurvesConfig “filename”


None of the downloaded presets had that string. So I had to make sure to add that string to each of the new presets along with the file name. And this is why Linux is my OS of choice-- tasks like this are reasonably simple. Although it did take most of the day to find the necessary information and get it all to work as expected. :gaah :rofl

After much research and cussing, the bash script I came up with was this;
IFS=$'\n'; for f in *; do sed -i 2i'(GimpCurvesConfig "'$f'"' $f; sed -i '$i )' $f; done


Simple, huh? Don't worry, I'm going to break it down so hopefully even other hacks like me can understand it. Believe me, I'm no IT guru. I had to sort this all out. If I managed it, there's a reasonable chance if you're familiar with the Linux command line you can handle it too.

First;
IFS=$'\n'

This tells the script to only treat Newlines, what you get when you hit 'Enter' on the keyboard, (the \n) as name dividers. So spaces, hyphens, and underlines are treated as legitimate parts of file names. Otherwise, the script would read “warm sunny-day.txt” as “warm”, “sunny”, and “day” and try to read each as a separate file. That won't work.

;
is just a handy divider to break up the commands without having to go to a new line. Writing the whole script on one line makes it easier to see where you screwed up.

for f in *

This tells the script to keep looping as long as it finds the string '*'. Since '*' is a wildcard the script will run on every file in the directory. And 'f' is just a variable which takes whatever value the script finds when it searches for '*'. So 'f' becomes the next file name in the directory each time the loop repeats. You can narrow the field by using 'X*' if you only want to modify files with 'X' in the name. Also note that 'f' can be other letters. I used 'f' because it's a convenient stand-in for 'file' and it doesn't get confused with other letters needed elsewhere in the script.

do sed -i

This performs the 'sed' command. The -i flag tells sed to modify the file in place rather than writing the output to a new file. This is easier for me to keep track of. But it is potentially troublesome if you don't have backups of the files. Ask me how I know. :oops:

2i

Tells the script to insert the text before the second line of the file. Other options would be '2a' to Append the text after the second line or changing the number for a different target line. There's no apparent difference between 1a and 2i, or similar pairs. I simply picked the spot I knew would exist between an opening comment and the following data. Obviously, files from different sources may require a different setting here. So it's best to examine the presets before you start tweaking them. There are also other ways of specifying the insertion point. But this is simple and it works.

'(GimpCurvesConfig "'$f'"'

This defines the text to be inserted. Anything in single quotes gets written literally, including the double quotes. The $f tells the script to insert the file name it got from the very first step in the process. So this particular example writes
(GimpCurvesConfig “filename”
in each file in the directory. I just used the exact syntax GIMP uses to save presets in the Curves settings file.

$f

This tells sed in which file to insert the text. The $f means the text goes into the file we just pulled the name from. Otherwise you would specify an actual file name e.g. target.txt.

That completes the first part. Every file in the directory now has its name included as the second line of the text in the format shown just above. But if you're paying attention you noticed that I added an opening parenthesis to the text. So now I had to add a closing parenthesis to each file to keep the syntax in balance. That's the purpose of the second command in the script. You could do it as a whole separate script. It's just quicker to include it in this one.

The second command does exactly the same procedure. But since we are putting a different string in a different part of the text we need a different argument. And note that do does not get repeated, only sed -i;
'$i )' $f

This bit is confusing to look at. The quotes are essential because we need to insert the parenthesis. The $i tells sed to insert the text before the last line just like 2i told it to insert the text before the second line. It doesn't matter if the closing parenthesis is grouped with the existing parentheses or on a line all by itself so adding it just before the closing comment works fine. The $f stands in for the target file again.

done

This just tells the script to quit looping when the 'for' conditions are no longer met.

That one script takes us from this;
# GIMP curves tool settings

(time 0)
(channel value)
(curve
    (curve-type smooth)
    (n-points 17)
   (points **WHOLE BUNCHA NUMBERS**)
    (n-samples 256)
   (samples **WHOLE BUNCHA NUMBERS**))
Ditto for red channel
Ditto for green channel
Ditto for blue channel
Ditto for alpha channel

# end of curves tool settings


To this;
# GIMP curves tool settings
(GimpCurvesConfig "Alien"

(time 0)
(channel value)
(curve
    (curve-type smooth)
    (n-points 17)
   (points **WHOLE BUNCHA NUMBERS**)
    (n-samples 256)
   (samples **WHOLE BUNCHA NUMBERS**))
Ditto for red channel
Ditto for green channel
Ditto for blue channel
Ditto for alpha channel

)
# end of curves tool settings

I forget how to highlight text inside a code window. So I hope you can see the tiny difference. That little bit makes a huge functional difference.

I ran this script on a test folder full of copies of some of the presets I had downloaded. Sure enough, each preset now had its name included in the text. Then I copied and pasted one of the modified presets directly into the existing gimp-curves-tool.settings file with the presets I had saved via the Curves dialog. There was no danger of any issues since I could just as easily remove the modified text if it didn't work. But it did work. The modified preset showed up in the 'Presets' dropdown in the Colors>Curves dialog right along with the previously saved presets. So at least I knew the process worked and GIMP could read what I had created.

But that still left the apparently monumental task of getting all 100 presets into a single file that could then be pasted into the .settings file. Further hours of research led to a second script which solved the problem;;
IFS=$'\n'; for f in *; do cat *  > filename; done
Not quite as ugly as the first script.

do cat * >

This is the only new bit. This just takes the contents of a file and adds it to a new file. So each cycle of the loop adds a new file to filename. I don't know why it doesn't use the same $f syntax as sed. But if you try $f it will overwrite filename each cycle and the final version will just be a duplicate of the last file sampled.

I ran the second script on the test folder of presets and got a single .txt file (I used curves.txt for filename) with a handful of modified presets copied to it. I opened curves.txt in my text editor alongside the .settings file. Then I copied the text of curves.txt and pasted it into the .settings file. Lo and behold, when I opened GIMP I had seventeen shiny new presets in my Curves Presets menu.

Note that you could probably run the second script so that it wrote straight to the stock presets file. I don't know if cat * > overwrites anything on the first pass or not. The file you write to can be in any directory so long as you specify the path if you don't write to the same directory your terminal is in. So you could possibly eliminate the copy/paste portion of this technique by using the .settings file as the target for the 'cat' command. I did it the long way because A) I don't know if I could do it the short way for sure and B)) I wanted to make sure at each step that everything was okay before proceeding.

Almost forgot-- this script will read the target file as it loops through the directory. So you will see errors saying something along the lines of "target file is source file". This was considered a non-issue by the Linux gurus I read during my research. And my own success leads me to think they are right. But it seems like something you might want to know. This only happens if the target file is in the same directory as the source files. So the simple way to avoid it is to write the target in a different directory by adding the necessary path to the target file argument

Wait, seventeen? Haven't I been saying the archive came with 100 presets? Yes, I have been saying that. And, yes, the archive did come with 100 presets. Unfortunately, several of those presets did not follow the standard format. And each time GIMP came to one of these goofballs it hiccuped and stopped loading the rest of the file. Fortunately, the error message included the line number where it encountered the problem in the file. So I was able to go in and comment out the erroneous preset. Then I reopened GIMP to see where the next problem would come up. After several cycles of this I ceased getting error messages and GIMP accepted all the new presets. While I don't have quite the 100 I started with I certainly have more than I probably need. And they all have the names given them by their author(s). They even show up in alphabetical order.
Image

For the record, this is what a curve preset saved by GIMP looks like;
(GimpCurvesConfig "Lightning"
    (time 0)
    (channel value)
    (curve
        (curve-type smooth)
        (n-points 17)
        (points 34 **WHOLE BUNCHA NUMBERS**)
        (n-samples 256)
        (samples 256 **WHOLE BUNCHA NUMBERS**))
    (channel red)
    (curve
        (curve-type smooth)
        (n-points 17)
        (points 34 **WHOLE BUNCHA NUMBERS**)
        (n-samples 256)
        (samples 256 **WHOLE BUNCHA NUMBERS**))
    (channel green)
    (curve
        (curve-type smooth)
        (n-points 17)
        (points 34 **WHOLE BUNCHA NUMBERS**)
        (n-samples 256)
        (samples 256 **WHOLE BUNCHA NUMBERS**))
    (channel blue)
    (curve
        (curve-type smooth)
        (n-points 17)
        (points 34 **WHOLE BUNCHA NUMBERS**)
        (n-samples 256)
        (samples 256 **WHOLE BUNCHA NUMBERS**))
    (channel alpha)
    (curve
        (curve-type smooth)
        (n-points 17)
        (points 34 **WHOLE BUNCHA NUMBERS**)
        (n-samples 256)
        (samples 256 **WHOLE BUNCHA NUMBERS**)))


Whereas GIMP (at least my install) sees this as just a list of numbers despite what the comment would lead you to believe;;
# GIMP Curves File
0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 255 255
0 0 -1 0 -1 0 -1 0 -1 -1 -1 162 89 164 -1 255 -1 255 -1 255 -1 255 -1 255 -1 255 -1 255 -1 255 240 255 -1 255
0 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 -1 -1 134 -1 107 136 107 -1 114 -1 108 -1 94 -1 -1 -1 -1 -1 -1 255 255
0 0 -1 9 -1 9 -1 6 -1 0 -1 0 -1 0 -1 0 -1 110 140 107 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 255 246
0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 255 255


This is not the simplest process. And it is certainly not without a degree of risk. If you only have a few curves it's far easier to import them from the Curves dialog and then save them as favorites. However, if you happen to download an archive with a hundred presets you would be forever adding them to your favorites via the dialog. I actually had to run this process twice since I had another set of presets in a different folder. I could have copied them all to one folder and run this once. But the one set was small enough to serve as a nice test batch.

Another caveat. If you're familiar enough with Linux to even sort of grasp what you just read then you probably already know this as well. But there is the distinct possibility that you will not be able to simply copy & paste the scripts here into your shell and make them work as is. Different variants of Linux have different quirks. That's what took me so long to get this to work, figuring out how to change the code to suit my specific OS. These scripts don't use exotic commands. You just may have to figure out how your OS likes you to spell things.

I suppose that caveat also applies somewhat to different versions of GIMP. I don't know if Curves presets have always been stored in the same place or in the same file.

I also wonder if this technique can be applied to other .settings files. There are several in the same folder. But I have yet to peek at them. Maybe others will be more adventurous. And maybe others with more Linux prowess can tidy up what I've done here.

One last thing. Being such an unbearably generous guy I have attached the .txt file that resulted from all this. So if you don't run Linux, or aren't comfortable with the command line, or just like freebies you can simply copy & paste the contents into the appropriate file via any text editor. Assuming you have permission to write to the file, that is. I left in the goofballs that I commented out. Maybe somebody else can figure out how to make them work so they can be opened up again. This is the exact file running on my system. I know it loads without problems on my system. And I know the presets all do something on my system. I can offer no guarantee that it will do the same on your system.


Attachments:
File comment: This has the updated file for those who didn't download the original. It also has a patch with the seven presets that weren't in the first file. You do not need the patch with the updated file, only if you downloaded the first version. You could also replace the first version entirely with the new version. I made quite a few fixes to the spelling of the files so they appear neater in the menu.
PresetsUpdate.zip [285.47 KiB]
Downloaded 384 times

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Last edited by Sasquatch on Sat Sep 03, 2016 2:03 pm, edited 1 time 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: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 12:10 am  (#2) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13016
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
:wow
That sure was a mouth full.
:hehe

Thanks Sasquatch. :bigthup

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 12:16 am  (#3) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
Wallace wrote:
:wow
That sure was a mouth full.
:hehe

Thanks Sasquatch. :bigthup

Nah! I was still almost 50,000 characters shy of the post limit. :rofl

Thanks for being my first customer. Let me know how it works on your Windows box.

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 12:33 am  (#4) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13016
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
Sasquatch wrote:
Nah! I was still almost 50,000 characters shy of the post limit. :rofl

Thanks for being my first customer. Let me know how it works on your Windows box.

Shouldn't be any issues,
because I already know how to add curve presets to Gimp.
I just never really found it necessary to do so.
I also never went looking for curve presets and didn't think that anyone was doing that sort of thing.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 12:44 am  (#5) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
Wallace wrote:
Shouldn't be any issues,
because I already know how to add curve presets to Gimp.
I just never really found it necessary to do so.
I also never went looking for curve presets and didn't think that anyone was doing that sort of thing.

Is it fairly easy to add a bunch at once in Windows? I'm waiting for somebody to point out that I could have done all this with a keyboard shortcut or something. I imagine the Import function on the dialog could import a single file with multiple presets on it. But I don't know for sure. And that would still require creating that file.

Wait til you play with the curves in that file. It's amazing the differences between them. I'm probably going to collect more presets now. I didn't realize that was a thing either. I was just searching for gradients and such when I found curves to download, so I did. Now that I've seen what they can do I think I'm hooked.

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 12:52 am  (#6) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13016
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
Sasquatch wrote:
Is it fairly easy to add a bunch at once in Windows? I'm waiting for somebody to point out that I could have done all this with a keyboard shortcut or something. I imagine the Import function on the dialog could import a single file with multiple presets on it. But I don't know for sure. And that would still require creating that file.

Wait til you play with the curves in that file. It's amazing the differences between them. I'm probably going to collect more presets now. I didn't realize that was a thing either. I was just searching for gradients and such when I found curves to download, so I did. Now that I've seen what they can do I think I'm hooked.

Yeah!
There's a lot of uses for curves that most people tend to overlook.
I use curves on the alpha channel,
to help refine shadows and text sometimes.
its also good at adjusting blurred effect.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 12:56 am  (#7) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
Wallace wrote:
Yeah!
There's a lot of uses for curves that most people tend to overlook.
I use curves on the alpha channel,
to help refine shadows and text sometimes.
its also good at adjusting blurred effect.

Most of the curves in that file work on all the channels simultaneously. So you get a range of effects that is mind-altering.

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 4:15 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2246
Location: Poland
Thanks for sharing.
It works well in Windows - also for Gimp 2.9.5
Only one note;
There are two ways of recording curves - old will not show up in the list - but you can open it and add to favorites.


Attachments:
Curves file format.png
Curves file format.png [ 23.02 KiB | Viewed 8902 times ]
Curves preset-split view in G-2.9.png
Curves preset-split view in G-2.9.png [ 625.45 KiB | Viewed 8902 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 9:11 am  (#9) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
MareroQ wrote:
Thanks for sharing.
It works well in Windows - also for Gimp 2.9.5
Only one note;
There are two ways of recording curves - old will not show up in the list - but you can open it and add to favorites.

Glad it works on other systems. Good to know my efforts weren't wasted.

Only two of the curves in that file are mine and they came straight from the original .settings file. So I don't quite understand what you mean about recording them differently. Or is that why the few "bad" presets didn't work?

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 10:53 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2246
Location: Poland
There are curves in the file that have been commented out ("Corssprocess", "Elsamuko-autumn", "Elsamuko-blue", "Elsamuko-green", "Portra", "Provia", "Velvia", "X"-"X4") - they are in the old notation.
They will work if the store them in a new notation - open "old" save "new" (best individually before using your bash script).
Thank You again - now finally have the order of presets curves (and quick selection).

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 11:13 am  (#11) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
MareroQ wrote:
There are curves in the file that have been commented out ("Corssprocess", "Elsamuko-autumn", "Elsamuko-blue", "Elsamuko-green", "Portra", "Provia", "Velvia", "X"-"X4") - they are in the old notation.
They will work if the store them in a new notation - open "old" save "new" (best individually before using your bash script).
Thank You again - now finally have the order of presets curves (and quick selection).

Ah-hah! So I can open the files in question and save them in the new format so I can then include them in the main file. Fantastic. I might get to that soon. I'll update the file and also attach the new ones in a separate file so folks who already have the main file can just add the new one instead of replacing everything again. Thanks.

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Top
 Post subject: Re: How to add a bunch of Curves presets at once in Linux
PostPosted: Sat Sep 03, 2016 2:10 pm  (#12) 
Offline
GimpChat Member

Joined: Jul 17, 2016
Posts: 293
Location: Arlington, TX
Thanks to MareroQ's tip I was able to fix seven broken presets and add them to the original file. The new zip is attached to the original post. The zip contains the new file with all the presets functional and a patch with the seven fixed presets. The patch is there so those who downloaded the original don't have to reinstall it completely. They can just add the seven fixed presets to what they currently have. However, I did make a bunch of spelling corrections and other minor tweaks to the names of the presets in the main file. This was to make them look more professional in the menu. So if you want the corrected names you'll need the new file. Or you can fix the names as you see fit in your own file.

Again, the patch is NOT needed with the updated file.

_________________
Just a short while ago I was a complete idiot when it comes to GIMP. Today, after many hours of practice, reading, and watching tutorials, I am proud to say I am an incomplete idiot.

Image


Top
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Giveaway of the day — Abstract Curves 1.190 + Bonus Presets Pack

4

No new posts I did a bunch of different sounds but I liked this one the best so far

0

No new posts I Just dumped a bunch of Windows Binaries on Gimp Chat of my filters

0

No new posts Attachment(s) Creating text (layer?) presets/profile?

15

No new posts Attachment(s) Gimp 2.99's master branch broke all color presets for my plugins

2



* Login  



Powered by phpBB3 © phpBB Group