Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
automate layer movement
#1
Hi

Referring to this post:

https://www.gimp-forum.net/Thread-Cut-sq...from-iamge

I use the method with the guides and 2 python scripts.

2 questions:

1. Is it possible to automate layer movement? The images all have the same size. The layer needs to be moved in order to fit the guides of size 150 px. Is there a plugin or script that can let me move a layer to a position by entering x,y values or something?



2. Is is possible for the ofn-export-layers to have {numUp0}.png appear automatically so that I don't need to enter it each time when i run gimp?


Attached Files Image(s)
   
Reply
#2
(02-27-2024, 01:02 AM)gimpygirl Wrote: Hi

Referring to this post:

https://www.gimp-forum.net/Thread-Cut-sq...from-iamge

I use the method with the guides and 2 python scripts.

2 questions:

1. Is it possible to automate layer movement? The images all have the same size. The layer needs to be moved in order to fit the guides of size 150 px. Is there a plugin or script that can let me move a layer to a position by entering x,y values or something?



2. Is is possible for the ofn-export-layers to have {numUp0}.png appear automatically so that I don't need to enter it each time when i run gimp?

What movement? If you use ofn-tiles, it will do the cut every 150px before the export if this is what you need. No need to move the layers?

You can edit the script, but then you are on your own. Search a line that looks like:

(PF_STRING,     'namePattern',  'Tile name',   '{imageName}-{column1:02d}-{row1:02d}.png'),

and replace the last string:

(PF_STRING,     'namePattern',  'Tile name',   ' {numUp0}.png'),
Reply
#3
(02-27-2024, 01:15 AM)Ofnuts Wrote:
(02-27-2024, 01:02 AM)gimpygirl Wrote: Hi

Referring to this post:

https://www.gimp-forum.net/Thread-Cut-sq...from-iamge

I use the method with the guides and 2 python scripts.

2 questions:

1. Is it possible to automate layer movement? The images all have the same size. The layer needs to be moved in order to fit the guides of size 150 px. Is there a plugin or script that can let me move a layer to a position by entering x,y values or something?



2. Is is possible for the ofn-export-layers to have {numUp0}.png appear automatically so that I don't need to enter it each time when i run gimp?

What movement? If you use ofn-tiles, it will do the cut every 150px before the export if this is what you need. No need to move the layers?

You can edit the script, but then you are on your own. Search a line that looks like:

(PF_STRING,     'namePattern',  'Tile name',   '{imageName}-{column1:02d}-{row1:02d}.png'),

and replace the last string:

(PF_STRING,     'namePattern',  'Tile name',   ' {numUp0}.png'),

See the link above for what plugins I use. I use guides and then movement is necessary. So my question is: can this movement be done by entering numbers instead of the mouse, since the movement is always the same.

So just edit it, save it and use it?

My file is attached
The layer "Geplaakte laag" needs to be moved to match the guides of 150 x 150 px
This is the movement I want to do by entering numbers and not by using the mouse for each same size image over and over again


Attached Files
.zip   wonder boy.zip (Size: 297.92 KB / Downloads: 12)
Reply
#4
Yes, just edit, save, and run. Since you are editing the part where the script describes its parameters to Gimp, you may have to restart GImp to see that chnage take effect (of other code changes, you just save an Gimp will run the new version. Edit with caution, Python is sensitive to line indentation, and some editors like to replace spaces by tabs and this messes u the code. So use a real code editor (Notepad++, UltraEdit,...), and not the Microsoft ones (Notepad, Wordpad...).

To move a layer in the script that would be layer.set_offsets(x,y) (if this is the only layer: image.layers[0].set_offsets(x,y), whee x and y are the new coordinates of the top left corner of the layer.
Reply
#5
Heed Ofnuts advice, he is the professional. Odd indentations, commas  missing or in wrong place and other things will stop your script.

Most plugins/scripts I need have already been done, I am a great believer in not re-inventing the wheel. Occasionally I might configure something for my own use, and not being an expert, I keep a bare-bones script for testing.

You can keep things simple. If you know that parameters do not change, tile size, drawing size, you can put straight in and avoid declaring variables. A Press-and-Go

Nothing clever just to see what works, no error trapping, just a linear process, Offset -> Crop -> Add Guides -> Tile

Attached, might get you started. Unzip, put in your plugins folder, It registers in the tools menu.

It is about time that Gimp had a proper macro system. It is on the list for maybe 10 years time Wink


Attached Files
.zip   testing.zip (Size: 529 bytes / Downloads: 68)
Reply
#6
Thanks a lot!
I think a new hobby has started! Heart
  •  Are there website that provide free scripts/plugins for GIMP (like a collection of scripts people made and share)? Or does this not exist?
  • what website do you recommend for learning about scripting and plugins (complete beginners)? Maybe there is a free ebook released?
  • Should I learn scripting or to make a plugin: what is the most usable and maybe best for a beginner?
  • this is official API? https://developer.gimp.org/api/2.0/libgimp/
  • some questions about the example script
  1. where does "pdb" come from?
  2. "timg" means the full image?
  3. how do you know the exact name of script/plugin to use in the code like "script_fu_grid_guides" and "python_fu_ofn_guillotine_layer" ? It seems it startswith "script_fu" or "python_fu" always but where to find the exact name?
  4. what is a "tdrawable"?
Reply
#7
There is of course ofnuts collections of plugins

http://sourceforge.net/projects/gimp-pat...s/scripts/
http://sourceforge.net/projects/gimp-too...s/scripts/

You can always find references using google search but often the site has gone or it is an ancient script that no longer works with Gimp 2.10

A big collection of all sorts here: https://www.gimpscripts.net/

And a smaller collection of old scripts updated for 2.10 https://www.gimphelp.org/script210.html

You might be interested in a 'bespoke' font plugin/ These are not SVG fonts, They are bitmap made in Gimp for Gimp. Examples here: http://gimpchat.com/viewtopic.php?f=12&t=20396&start=0
Ask on gimpchat for more information.
-------------
pdb is the procedural database Look in Help -> Plugin Browser and also Procedure Browser for the parameters a plugin/script expects. You also find the registered name of the plugin. Example script-fu-grid-guides goes in a python plugin as pdb.script_fu_grid_guides Note the underscores used for python.

timg / tdrawable are just what I use, more common is a plain image / drawable Have a look at how it is done in other plugins.

Struggling at the moment: my internet is slower than a snail, makes updating a pain
Reply
#8
Can you please test the plugin on this file?
Everything works but the guides are not exactly in the center between squares (not everywhere). I don't know why.
Maybe they are slightly different from the first file?
So I try to find out: is it the source file that is a bit different or is the plugin needing other values somewhere?
I'm not 100% if all pictures are exactly the same size (the squares)


Could you also give me the exact lline for python-fu-ofn-export-layers please?
I found the paramters but not sure how to do it Smile
With that line I have enough to study! It must be below the guilotine. I don't know if parameter "input image" is "timg" or "tdrawable" (and the other parameters too)


If you know a good book (free or not) or website to learn gimp python, I would be interested. Can't find one but this article is nice to start: https://medium.com/@chriziegler/introduc...41b860ad7e

Do you think this book is still representative for modern gimp (it was written for gimp 2.4)? it's old but has overview of everything and a section about plugins and scripts.
https://gimpbook.com/


Attached Files Thumbnail(s)
   

.xcf   wonder boy script.xcf (Size: 866.95 KB / Downloads: 22)
Reply
#9
(02-27-2024, 06:02 PM)gimpygirl Wrote: Can you please test the plugin on this file?
Everything works but the guides are not exactly in the center between squares (not everywhere). I don't know why.
Maybe they are slightly different from the first file?
So I try to find out: is it the source file that is a bit different or is the plugin needing other values somewhere?
I'm not 100% if all pictures are exactly the same size (the squares)

I am using the test image originally provided. If it is a bit off then do a bit of manual editing as at the beginning.
Make a grid
Layer ->  Transform -> Offset
Adjust the x and y values. It does depend on which part of the image you check. Maybe put 18 , -31 in the script.

   

Quote:Could you also give me the exact lline for python-fu-ofn-export-layers please?
I found the paramters but not sure how to do it Smile
With that line I have enough to study! It must be below the guilotine. I don't know if parameter "input image" is "timg" or "tdrawable" (and the other parameters too)

Code:
pdb.python_fu_ofn_export_layers(timg, "C:\\Users\\yourname\\Project", "{numUp0}.png", "-", 0 )
Look at the required parameters. Compare with the plugin dialogue. Replace yourname in the above.
Yes goes below guillotine. 4 space indent.

   

Quote:If you know a good book (free or not) or website to learn gimp python, I would be interested. Can't find one but this article is nice to start: https://medium.com/@chriziegler/introduc...41b860ad7e
Do you think this book is still representative for modern gimp (it was written for gimp 2.4)? it's old but has overview of everything and a section about plugins and scripts.
https://gimpbook.com/  

Gimp Python reference is very sparse. The reference you give is best you will get at the moment. Pecks book is old, big difference between 2.4/2.6 and Gimp 2.10
Reply
#10
Thanks so much!!!

Some questions
  • See screenshot: what is the difference between image and drawable?
  • See screenshot: runmode parameter you never need to use?
  • how can I specify the "current folder" (where the source gimp file is) in the python_fu_ofn_export_layers ? So I want a way the images are exported to the same folder as my gimp file (whatever that is for each file)
  • Do I need to restart GIMP for each code change in a plugin?

I was also wondering if you think there is a way to automate a "select by color" on the image for the color black of the squares, the blue color of the border around the squares, removing both selections and adding an alpha layer (so it becomes transparent)
See screenshot for this result

Can this all be done in the plugin, before all other operations? (so at the beginning of everything). I was thinking maybe you can define the point (x,y) where the "select by color" hits the image and then delete this selection (but I don't know if this is possible)
Maybe this can only be done manually in gimp?

Thanks


Attached Files Thumbnail(s)
       
Reply


Forum Jump: