Your script looks a lot like my ofn-tiles script (not to be confused with ofn-layer-tiles : that you can at least use as an example.
I asked myself the same question 8 years ago, and I went with Python, and I'm glad I did. Python is a lot easier to learn (and closer to C/C++). It also has a lot more uses outside of Gimp. Finding help with Python itself is easy.
In Gimp, the Python API is a superset of the script-fu one (all the pdb.* function are direct mapping of the script-fu functions). In additiion:
To load your image, just do:
The second parameter is what is used in error messages, it can sometimes be different from the "technical" file name (resolve links, case, added default extension...).
If you are in the Python-fu console, you can obtain the currently open image using:
(of course if you have more than one image gimp.Image_list() is an array with several elements. To locate your image you can just print it:
One big advantage of Python is that script-fu is limited to a tiny core and there is very little you can do outside of the Gimp API. WIth Python you can use a much broader runtime (function to parse strings, manage files, etc...) and you can also use (after installing them) modules from the very extensive Python libraries.
To make a loop with x,y, stepping the X by 20 and the Y by 10:
For complicated loops, in Python can you can also use a "generator":
The big advantage of the generator technique being that in your main code you have no nested loops, so you can easily break out of the whole thing. Another thing you will like is the for/else construct, where the else clause is executed only oif the loop runs to its end (no break).
For hints to debug your Python code in Windows, see https://www.gimp-forum.net/Thread-Debugg...in-Windows.
I asked myself the same question 8 years ago, and I went with Python, and I'm glad I did. Python is a lot easier to learn (and closer to C/C++). It also has a lot more uses outside of Gimp. Finding help with Python itself is easy.
In Gimp, the Python API is a superset of the script-fu one (all the pdb.* function are direct mapping of the script-fu functions). In additiion:
- in Python you deal with objects, and these objects have attributes and methods that will replace the plain API and make your code more readable:
Code:
if layer.visible
# vs
if pdb.gimp_item_get_visible(layer):
- there are additional functions to efficiently deal with pixels (pixels are converted to Python arrays)
To load your image, just do:
Code:
image = pdb.gimp_file_load('/tmp/sample.png','/tmp/sample.png')
The second parameter is what is used in error messages, it can sometimes be different from the "technical" file name (resolve links, case, added default extension...).
If you are in the Python-fu console, you can obtain the currently open image using:
Code:
image = gimp.Image_list()[0]
(of course if you have more than one image gimp.Image_list() is an array with several elements. To locate your image you can just print it:
Code:
images = gimp.Image_list()
print images
image=images[2] # Pick your image
One big advantage of Python is that script-fu is limited to a tiny core and there is very little you can do outside of the Gimp API. WIth Python you can use a much broader runtime (function to parse strings, manage files, etc...) and you can also use (after installing them) modules from the very extensive Python libraries.
To make a loop with x,y, stepping the X by 20 and the Y by 10:
Code:
for x in range(0,200,20):
for y in range(0,200,10):
print x,y
For complicated loops, in Python can you can also use a "generator":
Code:
# The generator
def iterateXY(sizeX,sizeY):
for x in range(0,200,sizeX):
for y in range(0,200,sizeY):
yield x,y
# Using it.
# This is a one-level loop, even though it iterates all the x,y pairs.
for x,y in iterateXY(40,80):
print "%3d, %3d" % (x,y)
The big advantage of the generator technique being that in your main code you have no nested loops, so you can easily break out of the whole thing. Another thing you will like is the for/else construct, where the else clause is executed only oif the loop runs to its end (no break).
For hints to debug your Python code in Windows, see https://www.gimp-forum.net/Thread-Debugg...in-Windows.