Convert images into brushes via script
#1
Posted 25 January 2012 - 04:41 PM
is it possible to convert a folder of pictures into brushes (.gih) via commandline or script?
like this:
<pseudo>
for image in folder:
open image
#would be cool, but not crucial
duplicate layer end shift hue a notch # 5 times or so
save image as <imagename>.gih (set spacing to 50 or whatever)
close image
</pseudo>
If this is possible, can someone give me a push in the right direction as where to start (will it be commandline, or a script you run from inside gimp, etc.).
I know some python but I never did something with/to gimp scriptingwise.
Thanks a lot!
knekke
#2
Posted 25 January 2012 - 08:22 PM
knekke, on 25 January 2012 - 04:41 PM, said:
is it possible to convert a folder of pictures into brushes (.gih) via commandline or script?
like this:
<pseudo>
for image in folder:
open image
#would be cool, but not crucial
duplicate layer end shift hue a notch # 5 times or so
save image as <imagename>.gih (set spacing to 50 or whatever)
close image
</pseudo>
If this is possible, can someone give me a push in the right direction as where to start (will it be commandline, or a script you run from inside gimp, etc.).
I know some python but I never did something with/to gimp scriptingwise.
Thanks a lot!
knekke
#3
Posted 25 January 2012 - 09:52 PM
As I understand GIH is the only option to have a fixed brush color.
Thanks
#5
Posted 27 January 2012 - 12:46 AM
If you want to convert an image to a brush, then all you have to do is save it as a {Brush name}.gih file and put it in your brushes folder located under your {user profile}/.gimp2.0/brushes directory (note the dot in front of the gimp folder name; this folder is also hidden so just type the path in the explorer bar if you have hidden files not viewable (Windows default unfortunately but it can be made visible).
#6
Posted 27 January 2012 - 07:19 AM
I got pretty far with that by now using python, but I am stuck at the final step.
How do i use:
pdb.file_gih_save() ???????
It says in the docs that the last attribute should be a STRINGARRAY, but what shall I put there? I always get 'invalid syntax'.
I can't use the normal pdb.gimp_file_save(), because the files saved this way are corrupt.
Please help me Obi-wan....
#7
Posted 27 January 2012 - 08:22 AM
knekke, on 27 January 2012 - 07:19 AM, said:
I got pretty far with that by now using python, but I am stuck at the final step.
How do i use:
pdb.file_gih_save() ???????
It says in the docs that the last attribute should be a STRINGARRAY, but what shall I put there? I always get 'invalid syntax'.
I can't use the normal pdb.gimp_file_save(), because the files saved this way are corrupt.
Please help me Obi-wan....
incremental angular random velocity pressure xtilt ytilt
(the values you find in dropdowns in the "ranks" section of the save dialog for GIH)
This post has been edited by ofnuts: 27 January 2012 - 08:24 AM
#8
Posted 27 January 2012 - 09:18 AM
#9
Posted 27 January 2012 - 02:55 PM
A final question: Is it possible to run scripts from inside gimp without registering them as a plugin? That would be awesome....
from gimpfu import *
import os
def python_genBrush():
rawtreepath = "<directory holding the pics>"
rawtreefiles = []
for i in os.listdir(rawtreepath):
if i.split('.')[-1] == "tif":
rawtreefiles.append(i)
counter = 0
while counter < len(rawtreefiles):
imagefile = os.path.join(rawtreepath,rawtreefiles[counter])
pdb.gimp_file_load(imagefile, imagefile)
img = gimp.image_list()[0]
namebase = '.'.join(imagefile.split('.')[:-2])
for i in range(1,5):
layer = pdb.gimp_file_load_layer(img, os.path.join(rawtreepath,rawtreefiles[counter+i]))
pdb.gimp_image_add_layer(img,layer,i)
pdb.gimp_hue_saturation(layer,0,i*-9,i,0)
descr = rawtreefiles[counter].split('.')[-2]
width = pdb.gimp_image_width(img)
height = pdb.gimp_image_height(img)
layer = img.active_layer
ranks = [5]
sel = ["incremental"]
fileoutname = "<brushes floder>"+descr+'.gih'
pdb.file_gih_save(img, layer, fileoutname, fileoutname, 50, descr, width, height, 1, 1, 1, ranks,1,sel)
pdb.gimp_image_delete(img)
counter = counter+5
#10
Posted 27 January 2012 - 09:07 PM
knekke, on 27 January 2012 - 02:55 PM, said:
A final question: Is it possible to run scripts from inside gimp without registering them as a plugin? That would be awesome....
Registration is not much of a problem. But of that bothers you, it should be possible, in the python console, to import any python you wrote and run it. But you'll have to find a way to tell you script what image to use (if you have more than one loaded), what layer is relevant, etc.... all things that come for free after registration.
PS: this:
width = pdb.gimp_image_width(img) height = pdb.gimp_image_height(img) .... pdb.file_gih_save(img, layer, fileoutname, fileoutname, 50, descr, width, height, 1, 1, 1, ranks,1,sel)
can be replaced by:
pdb.file_gih_save(img, layer, fileoutname, fileoutname, 50, descr, img.width, img.height, 1, 1, 1, ranks,1,sel)
#11
Posted 30 January 2012 - 07:54 AM
Thanks!!

Help












