Author Topic: How to pull metadata from a PNG header and place into info fields?  (Read 2193 times)

Offline Sonadiatoms

  • Newcomer
  • *
  • Posts: 17
    • View Profile
I have many images that have been generated using AI. 

The generator software has embedded the parameters used to make the image in plain text, in what I believe to be the header of the file.  If I open up the .png file in a text editor, I can read "parameters futuristic biomorphic Water park dystopian city, Art Nouveau Castel Béranger Paris aerospace manufacturing facility, mandelbulb red yellow blue black and white by AJ Casson and Paul Cézanne"
Underneath it:  Negative prompt: crowded, busy composition, claustrophobic
Steps: 50, Sampler: Euler a, CFG scale: 10, Seed: 267507505, Size: 824x824, Model hash: ac25001a

I would like to pull out these values and place them into file metadata that is understandable to Photo Mechanic, such as within the "Extended Description" field.  Right now, I don't see a way to view this data within PM.  Any ideas? 
An example PNG is attached below if you want to inspect it.

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25020
    • View Profile
    • Camera Bits, Inc.
Re: How to pull metadata from a PNG header and place into info fields?
« Reply #1 on: January 15, 2023, 11:37:40 PM »
I have many images that have been generated using AI. 

The generator software has embedded the parameters used to make the image in plain text, in what I believe to be the header of the file.  If I open up the .png file in a text editor, I can read "parameters futuristic biomorphic Water park dystopian city, Art Nouveau Castel Béranger Paris aerospace manufacturing facility, mandelbulb red yellow blue black and white by AJ Casson and Paul Cézanne"
Underneath it:  Negative prompt: crowded, busy composition, claustrophobic
Steps: 50, Sampler: Euler a, CFG scale: 10, Seed: 267507505, Size: 824x824, Model hash: ac25001a

I would like to pull out these values and place them into file metadata that is understandable to Photo Mechanic, such as within the "Extended Description" field.  Right now, I don't see a way to view this data within PM.  Any ideas? 
An example PNG is attached below if you want to inspect it.

Photo Mechanic Plus sees the 'tEXt' chunk but it's just plain text and is not in either IPTC or XMP format (standard metadata types) and ignores it.  ExifTool looks like it could be used to extract that textual data and then insert IPTC or XMP metadata into the PNG that PM would recognize.  PM does not have the capability of extracting text chunks that are not IPTC or XMP formatted.

https://exiftool.org/

$exiftool -v /path/to/your file.png (not going to put the extremely long filename here)
  ExifToolVersion = 12.22
  FileName = 01015-267507505-futuristic biomorphic Water park dystopian city, Art Nouve[snip]
  FileSize = 861193
  FileModifyDate = 1673853810
  FileAccessDate = 1673854321
  FileInodeChangeDate = 1673853974
  FilePermissions = 33188
  FileType = PNG
  FileTypeExtension = PNG
  MIMEType = image/png
PNG IHDR (13 bytes):
  + [BinaryData directory, 13 bytes]
  | ImageWidth = 824
  | ImageHeight = 824
  | BitDepth = 8
  | ColorType = 2
  | Compression = 0
  | Filter = 0
  | Interlace = 0
PNG tEXt (356 bytes):
  | [adding parameters]
  Parameters = futuristic biomorphic Water park dystopian city, Art Nouveau Castel B..r[snip]
PNG IDAT (14 chunks, total 860612 bytes)
PNG IEND (end of image)

As you can see, exiftool sees the data and likely can extract it, and write it to an IPTC or XMP field of your choosing, updating the file.

HTH,

-Kirk

Offline Sonadiatoms

  • Newcomer
  • *
  • Posts: 17
    • View Profile
Re: How to pull metadata from a PNG header and place into info fields?
« Reply #2 on: January 16, 2023, 12:48:01 AM »
Hi Kirk,

Thank you for the detailed explanation of this process, and for linking the tool itself.  I do have thousands of images to process this with, meaning that ideally this would work in batch where I point to directories rather than individual files.  I will investigate more... thanks for the lead.