Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible to script Metadata?
#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


Messages In This Thread
Possible to script Metadata? - by akovia - 09-17-2020, 04:31 PM
RE: Possible to script Metadata? - by akovia - 09-24-2020, 08:50 PM
RE: Possible to script Metadata? - by rich2005 - 09-25-2020, 09:13 AM
RE: Possible to script Metadata? - by akovia - 09-25-2020, 09:26 PM
RE: Possible to script Metadata? - by Ofnuts - 09-25-2020, 03:23 PM
RE: Possible to script Metadata? - by rich2005 - 09-26-2020, 10:29 AM
RE: Possible to script Metadata? - by Ofnuts - 09-26-2020, 09:15 PM
RE: Possible to script Metadata? - by rich2005 - 09-27-2020, 09:15 AM
RE: Possible to script Metadata? - by akovia - 11-16-2020, 03:33 PM

Forum Jump: