automate layer movement - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions) +--- Thread: automate layer movement (/Thread-automate-layer-movement) Pages:
1
2
|
automate layer movement - gimpygirl - 02-27-2024 Hi Referring to this post: https://www.gimp-forum.net/Thread-Cut-squares-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? RE: automate layer movement - Ofnuts - 02-27-2024 (02-27-2024, 01:02 AM)gimpygirl Wrote: Hi 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'), RE: automate layer movement - gimpygirl - 02-27-2024 (02-27-2024, 01:15 AM)Ofnuts Wrote:(02-27-2024, 01:02 AM)gimpygirl Wrote: Hi 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 RE: automate layer movement - Ofnuts - 02-27-2024 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. RE: automate layer movement - rich2005 - 02-27-2024 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 RE: automate layer movement - gimpygirl - 02-27-2024 Thanks a lot! I think a new hobby has started!
RE: automate layer movement - rich2005 - 02-27-2024 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 RE: automate layer movement - gimpygirl - 02-27-2024 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 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/introduction-to-python-scripting-in-gimp-141b860ad7e 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/ RE: automate layer movement - rich2005 - 02-27-2024 (02-27-2024, 06:02 PM)gimpygirl Wrote: Can you please test the plugin on this file? I am using the test image 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. [attachment=11312] Quote:Could you also give me the exact lline for python-fu-ofn-export-layers please? Code: pdb.python_fu_ofn_export_layers(timg, "C:\\Users\\yourname\\Project", "{numUp0}.png", "-", 0 ) Yes goes below guillotine. 4 space indent. [attachment=11311] 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/introduction-to-python-scripting-in-gimp-141b860ad7e 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 RE: automate layer movement - gimpygirl - 02-28-2024 Thanks so much!!! Some questions
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 |