Page 1 of 1

MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T13:17:07-07:00
by mhulse
Hello,

(my IM version info is in my signature)

I am converting a bunch of images to a specific file format (JPG) and I need to store the original file names in the metadata of the image.

For example: "foo.png" gets converted to "foo.jpg" and its original file name gets stored in the meta data of the converted image file (I am throwing out the PNG version after conversion by IM).

I noticed, when getting info on a test image, that there is a "Comments" field:

Image

But when I try to read the exif info, I don't see "comments":

Code: Select all

$ identify -format '%[EXIF:*]' test.jpg
exif:ColorSpace=1
exif:DateTime=2016:12:24 12:07:49
exif:ExifImageLength=1500
exif:ExifImageWidth=2100
exif:ExifOffset=172
exif:Orientation=1
exif:ResolutionUnit=2
exif:Software=Adobe Photoshop CC 2017 (Macintosh)
exif:thumbnail:Compression=6
exif:thumbnail:JPEGInterchangeFormat=310
exif:thumbnail:JPEGInterchangeFormatLength=920
exif:thumbnail:ResolutionUnit=2
exif:thumbnail:XResolution=72/1
exif:thumbnail:YResolution=72/1
exif:XResolution=3000000/10000
exif:YResolution=3000000/10000
… and:

Code: Select all

$ identify -verbose test.jpg
Image: test.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 2100x1500+0+0
  Resolution: 300x300
  Print size: 7x5
  Units: PixelsPerInch
  Type: Bilevel
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8/1-bit
  Channel depth:
    gray: 1-bit
  Channel statistics:
    Pixels: 3150000
    Gray:
      min: 255 (1)
      max: 255 (1)
      mean: 255 (1)
      standard deviation: nan (nan)
      kurtosis: nan
      skewness: nan
      entropy: nan
  Colors: 1
  Histogram:
   3150000: (255,255,255) #FFFFFF gray(255)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 2100x1500+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 99
  Orientation: TopLeft
  Properties:
    date:create: 2016-12-24T12:08:13-08:00
    date:modify: 2016-12-24T12:07:52-08:00
    exif:ColorSpace: 1
    exif:DateTime: 2016:12:24 12:07:49
    exif:ExifImageLength: 1500
    exif:ExifImageWidth: 2100
    exif:ExifOffset: 172
    exif:Orientation: 1
    exif:ResolutionUnit: 2
    exif:Software: Adobe Photoshop CC 2017 (Macintosh)
    exif:thumbnail:Compression: 6
    exif:thumbnail:JPEGInterchangeFormat: 310
    exif:thumbnail:JPEGInterchangeFormatLength: 920
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:XResolution: 3000000/10000
    exif:YResolution: 3000000/10000
    jpeg:colorspace: 2
    jpeg:sampling-factor: 1x1,1x1,1x1
    signature: 5efb91b21ee3e35677d9c72f0f95990a8b55e96ae1a6541f6bf41b9e16f54930
  Profiles:
    Profile-8bim: 3190 bytes
    Profile-exif: 1236 bytes
    Profile-icc: 3144 bytes
    Profile-xmp: 3339 bytes
  Artifacts:
    filename: test.jpg
    verbose: true
  Tainted: False
  Filesize: 222KB
  Number pixels: 3.15M
  Pixels per second: 39.38MB
  User time: 0.060u
  Elapsed time: 0:01.079
  Version: ImageMagick 6.9.7-0 Q16 x86_64 2016-12-18 http://www.imagemagick.org
Question(s):

1. Using IM, Is it possible for me to read and write to the comments section of the image's meta data (as seen in above screen shot).

2. If you had to store the original file name in an image, where would you put it? Should I use Exif or IPTC fields for this?

3. Can IM read/write Exif/IPTC or "get info" (as seen above in screen shot)?

Thanks a billion for you help, I really appreciate it!

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T13:56:13-07:00
by GeeMack
mhulse wrote:1. Using IM, Is it possible for me to read and write to the comments section of the image's meta data (as seen in above screen shot).

2. If you had to store the original file name in an image, where would you put it? Should I use Exif or IPTC fields for this?
This command would read "input.jpg", use its filename to set a comment which will be contained in the output file, resize the input image (... and whatever other processing you might want to do there...), and write it to "output.png"...

Code: Select all

convert input.jpg -set comment "%[f]" -resize 50% output.png
Instead of using "%[f]" there you could use "%[t]" to make the comment from the input filename without the extension.

The next command would read that "output.png" file, read the comment data from the file into an IM variable called "filename:f", resize the image etc., and write an output file using "filename:f" which is the same name as that original we read and modified above...

Code: Select all

convert output.png -set filename:f "%[c]" -resize 50% "%[filename:f]"
If you had written the comment from the input name without the extension, you'd have to make the output filename something like "%[filename:f].jpg"
3. Can IM read/write Exif/IPTC or "get info" (as seen above in screen shot)?
Yes, for the types of images which are able to contain those sorts of information. There is a pretty good page of instructions to do that sort of thing at THIS link.

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T14:02:40-07:00
by mhulse
Thank you so much for the quick reply and pro help GeeMack, I really appreciate it!

I am trying your suggestions now. :)

Also, thank you for the linkage. Reading that as well. I think I found that page before posting my question, but I was thrown off as I did not see my "Hello world!" comment when dumping the meta data using the commands in my first post. I wasn't sure if "Comments" was specific to my OS (although, I am pretty sure Windows has this field too). Everything I have read, which is not too much as "Comments" is hard to Google for, says that "Comments" is an EXIF field. Again though, dumping that meta information does not show "Hello world!" (I added that though my OS by typing it in the "get info" window).

Anyway, with that said, thank you again for your help and code tips/linkages! Reading/testing now. I'll let you know how it goes. :)

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T14:09:36-07:00
by mhulse
GeeMack, looking at your examples, I just realized that IM will have to process the image to add the exif data you mentioned. Thinking about it, I probably want to avoid this as I am using IM to convert images later in my workflow (I need to add original file name earlier in my workflow, but not convert said images).

I am looking at exiftool now.

Interestingly, it doesn't show "Comments" (i.e. "Hello world!") either:

Code: Select all

$ exiftool -a -u -g1 test.jpg
---- ExifTool ----
ExifTool Version Number         : 10.36
---- System ----
File Name                       : test.jpg
Directory                       : .
File Size                       : 217 kB
File Modification Date/Time     : 2016:12:24 12:07:52-08:00
File Access Date/Time           : 2016:12:24 12:45:18-08:00
File Inode Change Date/Time     : 2016:12:24 12:08:13-08:00
File Permissions                : rw-r--r--
---- File ----
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Image Width                     : 2100
Image Height                    : 1500
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:4:4 (1 1)
---- IFD0 ----
Orientation                     : Horizontal (normal)
X Resolution                    : 300
Y Resolution                    : 300
Resolution Unit                 : inches
Software                        : Adobe Photoshop CC 2017 (Macintosh)
Modify Date                     : 2016:12:24 12:07:49
---- ExifIFD ----
Color Space                     : sRGB
Exif Image Width                : 2100
Exif Image Height               : 1500
---- IFD1 ----
Compression                     : JPEG (old-style)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Thumbnail Offset                : 322
Thumbnail Length                : 920
---- Photoshop ----
IPTC Digest                     : 00000000000000000000000000000000
Print Info 2                    : ...printOutput.PstSbool.InteenumInteClrm.printSixteenBitbool.printerNameTEXT..printProofSetupObjc.Proof Setup.proofSetup.Bltnenum.builtinProof.proofCMYK
Print Style                     : ...printOutputOptions.CptnboolClbrboolRgsMboolCrnCboolCntCboolLblsboolNgtvboolEmlDboolIntrboolBckgObjc.RGBC.Rd  doub@o�Grn doub@o�Bl  doub@o�BrdTUntF#RltBld UntF#RltRsltUntF#Pxl@r�.vectorDatabool.PgPsenumPgPsPgPCLeftUntF#RltTop UntF#RltScl UntF#Prc@Y.cropWhenPrintingbool.cropRectBottomlong.cropRectLeftlong.cropRectRightlong.cropRectToplong
X Resolution                    : 300
Displayed Units X               : inches
Y Resolution                    : 300
Displayed Units Y               : inches
Print Style                     : Centered
Print Position                  : 0 0
Print Scale                     : 1
Global Angle                    : 90
Global Altitude                 : 30
Print Flags                     : 0 0 0 0 0 0 0 0 1
Print Flags Info                : ..
Color Halftoning Info           : /ff.lff../ff.���..2.Z..5.-..
Color Transfer Funcs            : ����������������������.�����������������������.�����������������������.�����������������������.�
Grid Guides Info                : ..@.@
URL List                        :
Slices Group Name               : test
Num Slices                      : 1
Pixel Aspect Ratio              : 1
IDs Base Value                  : 1
Photoshop Thumbnail             : (Binary data 920 bytes, use -b option to extract)
Has Real Merged Data            : Yes
Writer Name                     : Adobe Photoshop
Reader Name                     : Adobe Photoshop CC 2017
Photoshop Quality               : 12
Photoshop Format                : Standard
Progressive Scans               : 3 Scans
---- XMP-x ----
XMP Toolkit                     : Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01
---- XMP-xmp ----
Creator Tool                    : Adobe Photoshop CC 2017 (Macintosh)
Create Date                     : 2016:12:24 12:07:49-08:00
Metadata Date                   : 2016:12:24 12:07:49-08:00
Modify Date                     : 2016:12:24 12:07:49-08:00
---- XMP-dc ----
Format                          : image/jpeg
---- XMP-xmpMM ----
Instance ID                     : xmp.iid:421642fc-b721-4e31-b57f-74ac6f0c4a8e
Document ID                     : xmp.did:421642fc-b721-4e31-b57f-74ac6f0c4a8e
Original Document ID            : xmp.did:421642fc-b721-4e31-b57f-74ac6f0c4a8e
History Action                  : created
History Instance ID             : xmp.iid:421642fc-b721-4e31-b57f-74ac6f0c4a8e
History When                    : 2016:12:24 12:07:49-08:00
History Software Agent          : Adobe Photoshop CC 2017 (Macintosh)
---- XMP-photoshop ----
Color Mode                      : RGB
ICC Profile Name                : sRGB IEC61966-2.1
---- ICC-header ----
Profile CMM Type                : Lino
Profile Version                 : 2.1.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 1998:02:09 06:49:00
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : IEC
Device Model                    : sRGB
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Media-Relative Colorimetric
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : HP
Profile ID                      : 0
---- ICC_Profile ----
Profile Copyright               : Copyright (c) 1998 Hewlett-Packard Company
Profile Description             : sRGB IEC61966-2.1
Media White Point               : 0.95045 1 1.08905
Media Black Point               : 0 0 0
Red Matrix Column               : 0.43607 0.22249 0.01392
Green Matrix Column             : 0.38515 0.71687 0.09708
Blue Matrix Column              : 0.14307 0.06061 0.7141
Device Mfg Desc                 : IEC http://www.iec.ch
Device Model Desc               : IEC 61966-2.1 Default RGB colour space - sRGB
Viewing Cond Desc               : Reference Viewing Condition in IEC61966-2.1
Luminance                       : 76.03647 80 87.12462
Technology                      : Cathode Ray Tube Display
Red Tone Reproduction Curve     : (Binary data 2060 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 2060 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 2060 bytes, use -b option to extract)
---- ICC-view ----
Viewing Cond Illuminant         : 19.6445 20.3718 16.8089
Viewing Cond Surround           : 3.92889 4.07439 3.36179
Viewing Cond Illuminant Type    : D50
---- ICC-meas ----
Measurement Observer            : CIE 1931
Measurement Backing             : 0 0 0
Measurement Geometry            : Unknown
Measurement Flare               : 0.999%
Measurement Illuminant          : D65
---- Adobe ----
DCT Encode Version              : 100
APP14 Flags 0                   : [14]
APP14 Flags 1                   : (none)
Color Transform                 : YCbCr
---- Composite ----
Image Size                      : 2100x1500
Megapixels                      : 3.1
Thumbnail Image                 : (Binary data 920 bytes, use -b option to extract)

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T14:28:06-07:00
by mhulse
Ahhhh, "Comments" is a MacOS Finder meta data thing (kMDItemFinderComment):

Code: Select all

$ mdls test.jpg
_kMDItemOwnerUserID            = 501
kMDItemBitsPerSample           = 32
kMDItemColorSpace              = "RGB"
kMDItemContentCreationDate     = 2016-12-24 20:07:49 +0000
kMDItemContentModificationDate = 2016-12-24 20:07:49 +0000
kMDItemContentType             = "public.jpeg"
kMDItemContentTypeTree         = (
    "public.jpeg",
    "public.item",
    "public.data",
    "public.image",
    "public.jpeg",
    "public.content"
)
kMDItemCreator                 = "Adobe Photoshop CC 2017 (Macintosh)"
kMDItemDateAdded               = 2016-12-24 20:07:52 +0000
kMDItemDisplayName             = "test.jpg"
kMDItemFinderComment           = "Hello world!"
kMDItemFSContentChangeDate     = 2016-12-24 20:07:52 +0000
kMDItemFSCreationDate          = 2016-12-24 20:07:52 +0000
kMDItemFSCreatorCode           = "8BIM"
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = (null)
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = (null)
kMDItemFSLabel                 = 0
kMDItemFSName                  = "test.jpg"
kMDItemFSNodeCount             = (null)
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 222341
kMDItemFSTypeCode              = "JPEG"
kMDItemHasAlphaChannel         = 0
kMDItemKind                    = "JPEG image"
kMDItemLastUsedDate            = 2016-12-24 20:24:09 +0000
kMDItemLogicalSize             = 222341
kMDItemOrientation             = 0
kMDItemPhysicalSize            = 225280
kMDItemPixelCount              = 3150000
kMDItemPixelHeight             = 1500
kMDItemPixelWidth              = 2100
kMDItemProfileName             = "sRGB IEC61966-2.1"
kMDItemResolutionHeightDPI     = 300
kMDItemResolutionWidthDPI      = 300
kMDItemUseCount                = 1
kMDItemUsedDates               = (
    "2016-12-24 08:00:00 +0000"
)
Interesting!

Code tip found here: http://apple.stackexchange.com/a/165098/40515

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T14:37:15-07:00
by mhulse
Looks like "Comments" is available on Windows too:

Image

Found here: http://stackoverflow.com/q/26091836/922323

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T14:44:17-07:00
by fmw42
.
I believe the comment field is not OS specific. I think it is available to most common image formats. It is not the same as EXIF comment. IM does not write EXIF data, it only reads it, if available.

See http://www.imagemagick.org/Usage/basics/#settings
"Properties
These are a freeform set of key-value strings that are attached to each image on an individual basis. Each image can have a completely different set of strings. Essentially they are meta-data items that do not need to be accessed or decoded regularly, or are used in some special way.
Typical examples of this are: label, caption, and comment strings; creation and modified dates; user defined strings; results from some operators.
Users can use Set to set or change these, as long as the 'key' does not correspond to some known 'attribute'."
To write to a comment field in the meta data:

Code: Select all

convert rose: -set comment "fred" rose.png
To read the comment field to the terminal:

Code: Select all

convert rose.png -format "%c\n" info:
fred

If you look at the verbose info, you will see that the comment field is not part of the EXIF data, since this image had no EXIF data to start and after creating the comment field.

Code: Select all

identify -verbose rose.png
...

Properties:
comment: fred
date:create: 2016-12-24T13:35:06-08:00
date:modify: 2016-12-24T13:35:06-08:00
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:gAMA: gamma=0.45454544 (See Gamma, above)
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 70, 46
png:sRGB: intent=0 (Perceptual Intent)
png:text: 3 tEXt/zTXt/iTXt chunks were found
signature: a698f2fe0c6c31f83d19554a6ec02bac79c961dd9a87e7ed217752e75eb615d7
...

You can also write to a label field.

Code: Select all

convert rose.png -set label "fred2" rose.png
convert rose.png -format "%l\n" info:
fred2

Code: Select all

identify -verbose rose.png
...
Properties:
comment: fred
date:create: 2016-12-24T13:42:03-08:00
date:modify: 2016-12-24T13:42:03-08:00
label: fred2
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:gAMA: gamma=0.45454544 (See Gamma, above)
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 70, 46
png:sRGB: intent=0 (Perceptual Intent)
png:text: 4 tEXt/zTXt/iTXt chunks were found
signature: a698f2fe0c6c31f83d19554a6ec02bac79c961dd9a87e7ed217752e75eb615d7
...


EXIFTOOL will show both the comment and the label.

Code: Select all

exiftool -s -ee -g1 -u -n -D rose.png
---- ExifTool ----
- ExifToolVersion : 8.71
---- System ----
- FileName : rose.png
- Directory : .
- FileSize : 7022
- FileModifyDate : 2016:12:24 13:42:03-08:00
- FilePermissions : 644
---- File ----
- FileType : PNG
- MIMEType : image/png
---- PNG ----
0 ImageWidth : 70
4 ImageHeight : 46
8 BitDepth : 8
9 ColorType : 2
10 Compression : 0
11 Filter : 0
12 Interlace : 0
- Gamma : 2.2
0 WhitePointX : 0.3127
1 WhitePointY : 0.329
2 RedX : 0.64
3 RedY : 0.33
4 GreenX : 0.3
5 GreenY : 0.6
6 BlueX : 0.15
7 BlueY : 0.06
- BackgroundColor : 255 255 255
- Comment : fred
- datecreate : 2016-12-24T13:35:06-08:00
- datemodify : 2016-12-24T13:35:06-08:00
- Label : fred2
---- Composite ----
- ImageSize : 70x46


But they are not EXIF meta data

Code: Select all

convert rose: -format "%[EXIF:*]" info:
returns nothing



You can remove a comment by setting it to an empty string.

Code: Select all

convert rose.png -set comment "" rose.png

Re: MacOS "Comments" field of image (when getting info): Read and write?

Posted: 2016-12-24T17:31:06-07:00
by mhulse
Thanks so much for the detailed info Fred! That is super helpful!!! I am experimenting with all of your, and GeeMack's, tips now. :)

You guys rock!!!!! Much appreciated.

If I learn anything worth sharing, I will post back code samples here.