Gimptalk - Premier Gimp Community: Convert images into brushes via script - Gimptalk - Premier Gimp Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Convert images into brushes via script

#1 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 25 January 2012 - 04:41 PM

Hej,
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
0

#2 User is offline   ofnuts 

  • Moderator GT
  • Group: Moderators
  • Posts: 1,234
  • Joined: 17-October 10
  • LocationLooking over your shoulder :)

Posted 25 January 2012 - 08:22 PM

View Postknekke, on 25 January 2012 - 04:41 PM, said:

Hej,
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
I don't understand what you try to do... the GIH is supposed to contain several images, and your pseudo code would create one GIH for every input image.
010011110110011001101110011101010111010001110011
0

#3 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 25 January 2012 - 09:52 PM

You understand absolute correctly. One brush for every file (if possible with some layers of different hue).
As I understand GIH is the only option to have a fixed brush color.
Thanks
0

#4 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 26 January 2012 - 11:32 AM

anyone?
0

#5 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,403
  • Joined: 19-November 07

Posted 27 January 2012 - 12:46 AM

GIMP Image Hoses (gih) brushes can have multiple colors such as the ones by Silvertayl: http://www.gimptalk....-by-silvertayl/

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). :)
0

#6 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 27 January 2012 - 07:19 AM

Thanks lyleik. I actually know that. I need to figure out how to do it via script, because I will have a whole bunch of Images to convert.
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....
0

#7 User is offline   ofnuts 

  • Moderator GT
  • Group: Moderators
  • Posts: 1,234
  • Joined: 17-October 10
  • LocationLooking over your shoulder :)

Posted 27 January 2012 - 08:22 AM

View Postknekke, on 27 January 2012 - 07:19 AM, said:

Thanks lyleik. I actually know that. I need to figure out how to do it via script, because I will have a whole bunch of Images to convert.
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....
A very cursory look at the source code says to try:
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

010011110110011001101110011101010111010001110011
0

#8 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 27 January 2012 - 09:18 AM

got it working, thanks. Will post some code here when it is finished
0

#9 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 27 January 2012 - 02:55 PM

So I have it working finally. Code is down below, if someone needs to do sth like this (it is very specialized to my current task though and would need some modification)
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

0

#10 User is offline   ofnuts 

  • Moderator GT
  • Group: Moderators
  • Posts: 1,234
  • Joined: 17-October 10
  • LocationLooking over your shoulder :)

Posted 27 January 2012 - 09:07 PM

View Postknekke, on 27 January 2012 - 02:55 PM, said:

So I have it working finally. Code is down below, if someone needs to do sth like this (it is very specialized to my current task though and would need some modification)
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)

010011110110011001101110011101010111010001110011
0

#11 User is offline   knekke 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 25-January 12

Posted 30 January 2012 - 07:54 AM

Good to know, I will bear that in mind when I have to script gimp again.
Thanks!!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic