It is currently Mon Aug 10, 2026 5:39 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Help Requested with GIMP paths/vectors visibility and Item_ID
PostPosted: Wed Sep 18, 2024 12:27 am  (#1) 
Offline
New Member

Joined: Sep 17, 2024
Posts: 2
Hello,

I've been a long-time lurker, and this is my first post in this community. Before getting to my request, I would first like to express my genuine gratitude to all for your participation in this forum. While lurking over the past few months, I have learned A LOT from you and your posts/comments.

Secondly, I would like to apologize if this post is lacking in detail, as it is my second attempt to post this request, my first being lost just a little while ago, as I was doing a final proof reading before submitting. There was a storm in my area, the power flickered off and on, but alas, long enough to cause my computer to shut down.

As for my request, I need help with individually toggling paths/vectors from VISIBLE to NOT VISIBLE. Full disclosure, I have no professional background in programming, just a life long love/hate relationship with all things computers, with very little of that having to do with programming. I have Googled and Binged this subject until I thought I might pull my hair out, but have not yet found a successful solution to accomplish this. My main efforts have been centered on getting pdb.gimp_item_set_visible() to work, but I cannot for the life of me understand the necessary syntax, or find a resource to sufficiently explain the syntax. I have also not been able to figure out how to retrieve the given Item_ID of layers or channels, let alone paths/vectors. I have seen a few posts on various forums by Ofnuts, TIn Tran, Xenoid, and others, relating to the visibility of paths/vectors, as well as the retrieval of Item_IDs by type, but to no avail. Additionally, I have poured through the GIMP Python documentation, and the PDB looking for a solution; if it's there, I missed it or am too obtuse to have understood that I was looking at it.

Longish background, my grandmother and great aunt, following the deaths of their respective spouses, became avid and accomplished globetrotting travel companions in the 1950s and 1960s. Sadly, they have both passed on as well. Following their passing, I inherited two very large boxes of photo slides along with VERY DETAILED travelogues, containing corresponding dates/times, photo subjects, locations, and events associated with the many, many slides contained therein. I recently rediscovered these boxes in the closet of a guest bedroom while moving to a new house. Now that I have time, I have decided that I would like to memorialize my grandmother and great aunt's adventures by digitizing the photos, incorporating the photo metadata contained in the travelogues, for eventual display in a digital picture frame, which I also hope to share with the rest of my extended family.

Thus far, I have a GIMP Python plugin that creates a template .xcf, with various text layers (16 total; four in each corner) located in each of the four corners of the image. The plugin GUI passes the variables for the photo date, photo subjects, location, and events, and passes them to the corresponding text layers, and adjusts the text layer offsets based upon the length of the various text layer contents. Due to the variety of photo slides, some of them will require scaling in size and resolution. As result of this, due to the potential(likely) loss of text resolution fidelity once a text layer is scaled, the next step of the plugin is to convert the text layers to paths/vectors before scaling, and then filling the paths/vectors with a contrasting color following scaling. Once scaled, based upon the contents and composition of the photo, I would like to be able to programmatically leave the paths/vectors in the most aesthetically pleasing corner to VISIBLE (TRUE), and toggle the paths/vectors in the other three unused corners to NOT VISIBLE (FALSE), and then export the image to a .png file. I understand from my research that this task would like be much more easily accomplished in an application such as ImageMagick, with which I cannot disagree... however, I was well down the road on the creation of this plugin when I learned of the existence of ImageMagick, and have found this to be a fun and enjoyable (if not somewhat frustrating at times) endeavor, with the unintended side benefit of significantly adding to my admittedly anemic (some might call it STILL anemic) knowledge of Python. For this reason, I have decided to stay the course and tough it out in GIMP Python.

Respectfully, if anyone can assist me with the following:

1.) Please point me in the direction of instructions/tutorials/examples ore an explanation of how to toggle paths/vectors with (ideally) a single line of code, or barring that, the shortest code possible. As mentioned previously, I believe it is likely related to pdb.gimp_item_set_visible(), but I have yet to figure out how to use the correct syntax.

or

2.) Please point me in the direction of instructions/tutorials/examples or explanation of how to retrieve Item_IDs for layers/channels/paths.

or

3.) Ideally, both of the above.

For any assistance or instruction related to this request, I will be very, very grateful.

Many Thanks,

The Desdichado


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: Help Requested with GIMP paths/vectors visibility and Item_ID
PostPosted: Wed Sep 18, 2024 3:24 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Foreword: most of the Python doc is auto-generated from code that was initially mean for script-fu/scheme. So it is not totally accurate for Python and there are some differences:

* In script-fu everything that you handle (paths, layers...) has an ID, and this ID is how GIMP distinguishes two objects.
* All names-with-dashes become names_with_underscores
* In Python you have objects, and you pass the objects directly (in some very rare cases, if you need an ID, you can retrieve it from the Python object). Where the object is optional (ID=-1), you use Python's "None" (without quotes).
* If all the API is accessible through the PDB, many simple actions are also defined as object methods so these two are equivalent:

pdb.gimp_item_set_visible(path)
path.visible=True


However, the procedure you mention won't work... the paths that you see are markers, they aren't part of the image (a bit like guides, or the "marching ants" that show the selection). So when you export to PNG, there is nothing to see in the PNG. If you want to see the paths in the PNG you have to render them as pixels before exporting. In the paths list, you can right click your selected path and then use "Stroke path" or "Fill path" (which will apply only to the path you selected, so no need to make the others invisible).

In Layers, Channels and Paths lists you can toggle the visibility of all items at once by shift-clicking any of them (the one you shift-click stays unchanged, all others become invisible or visible).

When you write a script to process a path (or a layer), to be know to Gimp the script has to "register" (so that Gimp knows how to show it in the UI and how to call it), and this includes describing the script arguments to Gimp. If there is a path/layer as a second argument (the first being an image), this argument is automatically set as the target path/layer (the first argument being set to the active image).

Personally, I would advise against scaling anything. Storage is cheap. Adjust the scanner definition to be around 12Mpx per image or, if using a camera, try to fill the frame, and leave it at that.

_________________
Image


Top
 Post subject: Re: Help Requested with GIMP paths/vectors visibility and Item_ID
PostPosted: Wed Sep 18, 2024 11:10 pm  (#3) 
Offline
New Member

Joined: Sep 17, 2024
Posts: 2
Thank you for your reply, Ofnuts!

I am thinking I was not entirely clear in my original post regarding my planned workflow with this plug-in; to clarify:

If my original understanding was correct, and I believe it was, based upon your reply, I have understood any path/vector to be just a series of "invisible" nodes ("invisible" for the purposes of export from the .xcf file to a .png), and any path remains "invisible" until it has been rendered or filled as a raster before exporting. What I was looking for was a way to individually toggle the visibility of individual paths (analogous to clicking the "eye" icon in the Layers or Path Dialog). To be more concise my intended workflow is as follows:

1.) Pass the variables from the plug-in GUI containing the photo data, subjects, location, and events (working)
2.) Update 16 text layers with the corresponding values passed by the GUI. The text layers as above, with photo date, subjects, location, and events (4 layers) comprising one set, with a set in each corner, Left Upper, Right Upper, Left Lower, and Right Lower, 4 sets x 4 corners = 16 total text layers. The layer offsets for each of these layers is programmatically adjusted based upon the length of the strings that the variable are passing so as to remain in what I have deemed to be the most aesthetically pleasing location of each corner. (working)
3.) Once all text layers are updated, the plug-in converts all text layers to paths. (working)
4.) Once all paths have been rendered, delete the original text layers, leaving only the 16 path/vectors and the Background layer (where the actual display photo will eventually reside). (working)
5.) Programmatically toggle the visibility so that the correct corresponding paths/vectors for the photo date, subjects, location, and event for Left Upper corner are toggled to "visible" and all other paths are toggled to "not visible", and fill/render those four paths as raster to a new transparent layer, then toggle those four paths/vectors back to "not visible". Then repeat this step for each of the other remaining paths/vectors in the three remaining corners, leaving the image with 16 not visible paths, four new transparent layers, with each containing the photo metadata, and the background image.
6.) I had planned to then scale the .xcf image to the matching size/resolution of the final display image, but your reply has me reconsidering this step.
7.) Import final display image, where I can manually toggle the visibility of the four transparent layers containing photo metadata to decide which one to use for the final export of the photo to .png, based upon (again, very subjectively, which one I regard to be the most aesthetically pleasing based upon the photo composition).
8.) Export final display image with either the Left Upper, Right Upper, Left Lower, or Right Lower transparent photo metadata layer.
9.) Then on to run the plugin on the next photo.

Following your reply yesterday, I was able to get the path/vector visibility working, so that I have a proof-of-concept version of my plugin that successfully completes most of step 5 above (working for Left Upper corner only currently), using the following code:

    img.vectors[0].visible=True
    img.vectors[4].visible=True
    img.vectors[8].visible=True
    img.vectors[12].visible=True


Your explanation helped me immensely, many thanks, Ofnuts! I am now on to the step of parsing your code contained with the ofn-stroke-fill-path.py, in order to figure out how you fill the visible paths/vectors. I see that your recursively apply the code to all vector objects. There is A LOT going on in that plug-in, much of which is currently over my head! However, I'll get there.

Many thanks again for your assistance, sir.


Top
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group