It is currently Tue Aug 25, 2026 2:12 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: script-fu access to alignment tool?
PostPosted: Thu Jul 26, 2018 11:24 pm  (#1) 
Offline
GimpChat Member

Joined: Jul 26, 2018
Posts: 9
Hello. I'm trying to write a script to automatically mirror a given start image in a selected direction.

I'm an experienced programmer, but script-fu is a HUGE pain!

After having wrestled with poor documentation, parenthetical nightmares, and counterintuitive behavior [why do I get a LIST of one return value, which I then have to car out to treat it as whatever it should be?], I've got the logic for interpreting the direction SF-OPTION, copying the original, doubling the canvas in the proper direction, pasting it back in, flipping it in the right direction, and I'm at the point where I want to apply the alignment tool to place the new floating selection in the right position before anchoring it. Gripes about how hard this language is to work with aside...

The procedure browser doesn't seem to include a reference to the alignment tool. :/

How can I script the alignment tool function, to easily place my selection in the right location before I anchor it? I want it bottom, top, left, or right aligned with the edge of the image, and centered along the other axis. Do I have to read the location and manually calculate a translation based on the size of the image? Seems grossly inelegant, when there's already an alignment tool...


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: script-fu access to alignment tool?
PostPosted: Fri Jul 27, 2018 2:10 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
You can/should use Python....

See http://www.gimp.org/docs/python/index.html

Some examples here: http://sourceforge.net/projects/gimp-to ... s/scripts/

And no, not all tools in the UI have direct equivalents in the API, so you may have to compute some positions (which is is quite simple, see "arrange-layers" in the script collection above).

To do your thing it can be easier/faster to make a new layer with what you want to replicate, and then make copies of that layer as needed. Script do not need to mimic what you do with the UI.

_________________
Image


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Fri Jul 27, 2018 2:50 pm  (#3) 
Offline
GimpChat Member

Joined: Jul 26, 2018
Posts: 9
I already spent a whole day working on it and have it 90% done this way. Quite a waste to start all over when all I need to do is position the new layer. I'll definitely consider python for the next one, because it behaves more like a sane language. But I can't see starting this one over.

How exactly does doing it on a new layer make it easier/faster? Wouldn't it just be the same functions operating on a different object?

I suppose I can probably use gimp-drawable-offset to place it where I need it to be, but is that relative to where it's already placed, or to the image? Which point on the object is the offset computed with? The center? A corner?


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Fri Jul 27, 2018 5:39 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
gimp_drawable_offset is not the function you are looking for :)

When writing a scriptn, you have two things to master: 1) the Gimp API, and 2) the language. The Gimp API is essentially the same (python-fu can use all the API of script-fu). Python is light-years ahead of scheme in usability. Switching languages now would take one hour, and save you hours of debugging. Many of the often-used function of the API have equivalent object -methods. For instance to duplicate a layer along a diagonal:

for i in range(1,11,1):
    copy=layer.copy()    # make a copy (for use in same image)
    image.add_layer(copy,0)  # insert at top of layers stack
    copy.set_offsets(i*20,i*20)   # shift top left corner (this is the function you are looking for)
                                   # it could also be written, using the common Script-fu/python-fu API:
                                   # pdb.gimp_layer_set_offsets(copy,i*20,i*20)

_________________
Image


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Fri Jul 27, 2018 11:21 pm  (#5) 
Offline
GimpChat Member

Joined: Jul 26, 2018
Posts: 9
ofnuts wrote:
gimp_drawable_offset is not the function you are looking for :)

When writing a scriptn, you have two things to master: 1) the Gimp API, and 2) the language. The Gimp API is essentially the same (python-fu can use all the API of script-fu). Python is light-years ahead of scheme in usability. Switching languages now would take one hour, and save you hours of debugging. Many of the often-used function of the API have equivalent object -methods. For instance to duplicate a layer along a diagonal:


I'm fully with you about python being a better language, and I probably would have done it that way in the first place if I had a clue about how bad the scheme dialect would be. I didn't know if I'd have to compile it that way, or what, and I have a python environment installed for other reasons already, but it was a pain to get working right.

What I don't get is why you seem so dead-set on convincing me to re-do it in python and so reluctant to directly answer my questions.

So, if I re-write my script in python, will you actually help me figure out the last bit and accomplish my goal?


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Sat Jul 28, 2018 12:50 am  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4528
Location: Canada
GIMP comes with its own python so you don't have to install anything.
You can start scripting right away without having to set anything up other than any text editor.
I say you should use python as well. Doing math in python is simple because it reads just like other languages or in school. Once you have a script that does nothing running adding what logics or steps or the core of the work should take you like 1hr or less.
Python has resources that you could look up to do anything .. with scheme not so much.
I have done scheme before python and now I refuse to start a script in scheme.

_________________
TinT


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Sat Jul 28, 2018 2:05 am  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
lordcayleth wrote:
What I don't get is why you seem so dead-set on convincing me to re-do it in python and so reluctant to directly answer my questions.

So, if I re-write my script in python, will you actually help me figure out the last bit and accomplish my goal?


I think I answered most of your questions... except the one about getting a one-item list but then it is too script-fu specific.

If you write code in Python I can definitely help/comment on it.

And I suddenly remember that I have done something close to what you want: see ofn-symmetries here.

_________________
Image


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Thu Aug 02, 2018 3:54 am  (#8) 
Offline
GimpChat Member

Joined: Jul 26, 2018
Posts: 9
That's not what I want at all. :/

Starting image [X], apply script. Choose between up, down, left, right, and get one of:

[Y]
[X] (up. Y is vertical flip of X)

[X]
[Y] (down. Y is vertical flip of X)

[X][Y] (right. Y is horizontal flip of X)

[Y][X] (left. Y is horizontal flip of X)


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Thu Aug 02, 2018 10:56 am  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
lordcayleth wrote:
That's not what I want at all. :/

Starting image [X], apply script. Choose between up, down, left, right, and get one of:

[Y]
[X] (up. Y is vertical flip of X)

[X]
[Y] (down. Y is vertical flip of X)

[X][Y] (right. Y is horizontal flip of X)

[Y][X] (left. Y is horizontal flip of X)


I didn't say it is exactly what you want. But if you don't cut things, it gets close enough, and is a good starting point for your own Python script.

_________________
Image


Top
 Post subject: Re: script-fu access to alignment tool?
PostPosted: Thu Aug 02, 2018 4:50 pm  (#10) 
Offline
GimpChat Member

Joined: Jul 26, 2018
Posts: 9
I can't modify your code because I don't understand how it works.

I dread having to learn a whole other language and code the whole thing over again.

I think it's going to be easier to just do it manually.


Top
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group