Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible to script Metadata?
#1
I'd love a way to "sign" my work with a quick shortcut for both jpg and png files.

Currently I just type something in the comment box when exporting a jpg. It would be nice if you could save your comment as part of setting your save defaults, but it doesn't work that way. This is still much quicker than writing a Title/Author in a png file. For that I have exported what I would like as my defaults and have to do Image > Metadata > Edit Metadata Select: Import Metadata from the drop-down and navigate to my saved file.

So my question is, would it be possible to script this at all to make it a bit quicker and easier? 
ie.. script the importing of a default set of metadata.
Reply
#2
Well that's a shame.

I counted that it takes me 10 distinct actions to import metadata, which is still quicker than having to write it out each time. I thought it might be quicker to try and script it than to ask for a feature request, as I doubt this would make it high on the priority list. I guess exiftool might be the quickest way for adding it after the fact, but it won't add it to the xcf where is the ideal spot for it.

If someone can thing of a better way I'm all ears.

Thanks for looking.
Reply
#3
I found your first post interesting. Unfortunately nothing, so guessing a plugin is not possible (or easy)  I do recall a similar question some time back on GimpChat.

Using exif probably the best way to go. I do not have it installed at the moment. Find the syntax a pita, although I once used the exiv2 gui. Any information on ease of use appreciated.

Other possibilities.  You can add comments with ImageMagick (IM) The mogrify command writes the file in place. Wildcard for lots of similar format or named single files
Code:
mogrify -comment "your replacement comment here"  *.jpg
or using a text file for input
Code:
mogrify -comment @file.txt filename.tif

Thinking along the lines of a series of 'boiler plate' text files.

Do not try this with  a gimp .xcf file it will trash it.

Observations.
jpegs are ok, the comment is written into the file and visible in Gimp  example: https://i.imgur.com/KqWFAUJ.jpg
png's are weird. Using Gimp to write the comment and properties it is there and visible. Using IM and the comment vanishes from Gimp but I can see it using XnViewMP https://i.imgur.com/4ybwH2X.jpg
Closest thing to an xcf might be a multi-page tif except text layers and Layer groups are flattened. https://i.imgur.com/YTPqJJI.jpg

For what use it might be, a little plugin (that is all I can ever manage, 'little') comment .py to display the comment.  Only saves you one click.


Attached Files
.zip   comment.zip (Size: 443 bytes / Downloads: 140)
Reply
#4
You have to use a "parasite", this seems to work:

Code:
p=gimp.Parasite('gimp-comment',0,'(C) Ofnuts from python-fu')
image.parasite_attach(p)
Reply
#5
(09-25-2020, 09:13 AM)rich2005 Wrote: Using exif probably the best way to go. I do not have it installed at the moment. Find the syntax a pita, although I once used the exiv2 gui. Any information on ease of use appreciated.

Well I only planned to use it in a bash script, (the only scripting I have any experience in) so I'm not real worried about syntax as I only ever need to get it right one. Tongue
I've used it before for some things, but not for a while. I did find the link below both informative for using exiftool, and what fields are best to use.
https://libre-software.net/edit-metadata-exiftool/

(09-25-2020, 09:13 AM)rich2005 Wrote: Observations.
jpegs are ok, the comment is written into the file and visible in Gimp  example: https://i.imgur.com/KqWFAUJ.jpg
png's are weird. Using Gimp to write the comment and properties it is there and visible. Using IM and the comment vanishes from Gimp but I can see it using XnViewMP https://i.imgur.com/4ybwH2X.jpg
Closest thing to an xcf might be a multi-page tif except text layers and Layer groups are flattened. https://i.imgur.com/YTPqJJI.jpg

JPEG's are easy for sure, comparatively. The nice thing is that it at least prompts you on export with a comment box so you can see if it's there or not. It's crazy though that you can't have your default comment that's set in the preferences automatically applied to your default save options. At least they could give you the same button you get in the Image Properties > Comment window where you can just click a button to apply your comment.

   

PNG's are are weird for sure. I don't really care where the metadata ends up, as longs as it's attached in a somewhat relevant field. It should hitch a ride with the image until someone (or some site) intentionally strips the metadata. I am still an avid user of xnviewmp even though it doesn't play nice with gimp, and is what I used in my testing as well. It shows both jpeg and png comments, so I'm satisfied with that.

(09-25-2020, 09:13 AM)rich2005 Wrote: For what use it might be, a little plugin (that is all I can ever manage, 'little') comment .py to display the comment.  Only saves you one click.

Thank you for this, but it doesn't appear to do anything for me. I tried before and after adding a comment but see nothing in in a window, or in the error console. Here is the output of my system console.


Code:
comment-Warning: no comment

comment-Warning: Gimp'd by akovia


Thanks a lot!
Akovia
Reply
#6
@Ofnuts - question about xcf format comment

This a shell using your two lines of code.

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# adds a comment

import re, os, sys
from gimpfu import *

def add_comment (image,drawable,comment):
            
    if not comment:
        comment="no comment "
        p=gimp.Parasite('gimp-comment',0,comment)
        image.parasite_attach(p)
    else:
        p=gimp.Parasite('gimp-comment',0,comment)
        image.parasite_attach(p)
      
register(
    "python_fu_add_comment",
    " ",
    " ",
    "",
    " ",
    "2020",
    "<Image>/Tools/add comment",
    "*",
    [
        (PF_TEXT, "comment", "new comment", "")
     ],  
    [],
    add_comment,
            )
main()

Using this on a png file (same with jpeg)
Files has default comment - new comment added using script - png exported - file closed - opened again - comment is there. https://i.imgur.com/6QvhWWr.mp4

Same procedure but using xcf format. The comment is not saved (or is it lost when the xcf is reopened?) Whichever way the comment has gone. https://i.imgur.com/QhoiZ67.mp4
Reply
#7
(09-26-2020, 10:29 AM)rich2005 Wrote: @Ofnuts  - question about xcf format comment

This a shell using your two lines of code.

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# adds a comment

import re, os, sys
from gimpfu import *

def add_comment (image,drawable,comment):
           
   if not comment:
       comment="no comment "
       p=gimp.Parasite('gimp-comment',0,comment)
       image.parasite_attach(p)
   else:
       p=gimp.Parasite('gimp-comment',0,comment)
       image.parasite_attach(p)
     
register(
    "python_fu_add_comment",
    " ",
    " ",
    "",
    " ",
    "2020",
    "<Image>/Tools/add comment",
    "*",
    [
       (PF_TEXT, "comment", "new comment", "")
    ],  
    [],
    add_comment,
            )
main()

Using this on a png file (same with jpeg)
Files has default comment -  new comment added using script - png exported - file closed - opened again - comment is there.  https://i.imgur.com/6QvhWWr.mp4

Same procedure but using xcf format. The comment is not saved (or is it lost when the xcf is reopened?)  Whichever way the comment has gone. https://i.imgur.com/QhoiZ67.mp4

A diagonal look across the source code hints that the 2nd argument is a parasite "type", and a collection of C constants related to Gimp parasites says #define GIMP_PARASITE_PERSISTENT 1|, and indeed, using 1 instead of 0 seems to make the parasite survive in a saved XCF.


Code:
p=gimp.Parasite('gimp-comment',1,'(C) Ofnuts from python-fu')
image.parasite_attach(p)
Reply
#8
Yes, works here as well. Thank you.
Reply
#9
(09-27-2020, 09:15 AM)rich2005 Wrote: Yes, works here as well.  Thank you.

I was just searching the forums for something else and realized I never thanked you for this. (Getting old really sucks)

I am terribly sorry it took so long but I am very thankful for this nice little script.

Thanks Rich!
Reply


Forum Jump: