The 1. page content
Introductory
Az exiftool command can be used to read or write metadata for different file formats from the command line, which can be especially useful when you need a larger amount of automated file processing.
In this description, we will review some of the more general usage examples, as well as test a complete automation shell script that copies IPTC data from JPG files to EPS files.
Installation
If we don't have it on our machine yet exiftool package, then install the following apt-get command on Debian-based systems:
sudo apt-get install exiftool
In essence, this is an alias that is physically a libimage-exiftool-perl installs Debian 8 (Jessie) on 9.74 and Debian 9 (Stretch) on 10.40.
After running the command, you can use the program.
Basic Uses
The exiftool command can be used to handle metadata in basically three ways: read, write, and copy. Of course, the program supports a lot of switches and options, but in terms of its operation, it is worth separating these three "modes".
For the examples, I created three JPG files, one with the Linux GIMP program (proba_gimp.jpg) and the other in Windows with Photoshop (proba_ps.jpg). Both are 1024x768 blank saved images. The third image file is a web page PHP file managed / generated by your script (proba_php.jpg), where we can find other details. Perhaps JPG files are the most common file formats for demonstrating metadata management, so we will practice them in this chapter.
Reading
To read the GIMP jpg metadata:
exiftool proba_gimp.jpg
And the output is:
ExifTool Version Number : 10.40 File Name : proba.jpg Directory : . File Size : 10 kB File Modification Date/Time : 2019:05:25 10:09:47+02:00 File Access Date/Time : 2019:05:25 10:10:31+02:00 File Inode Change Date/Time : 2019:05:25 10:09:47+02:00 File Permissions : rw-r--r-- File Type : JPEG File Type Extension : jpg MIME Type : image/jpeg JFIF Version : 1.01 Resolution Unit : inches X Resolution : 72 Y Resolution : 72 Comment : Created with GIMP Image Width : 1024 Image Height : 768 Encoding Process : Progressive DCT, Huffman coding Bits Per Sample : 8 Color Components : 3 Y Cb Cr Sub Sampling : YCbCr4:4:4 (1 1) Image Size : 1024x768 Megapixels : 0.786
To read the Photoshop image metadata:
exiftool proba_ps.jpg
output:
ExifTool Version Number : 10.40 File Name : proba_ps.jpg Directory : . File Size : 62 kB File Modification Date/Time : 2019:05:25 10:24:04+02:00 File Access Date/Time : 2019:05:25 10:24:21+02:00 File Inode Change Date/Time : 2019:05:25 10:24:04+02:00 File Permissions : rw-r--r-- File Type : JPEG File Type Extension : jpg MIME Type : image/jpeg Exif Byte Order : Big-endian (Motorola, MM) Orientation : Horizontal (normal) X Resolution : 72 Y Resolution : 72 Resolution Unit : inches Software : Adobe Photoshop CS5 Windows Modify Date : 2019:05:25 10:23:42 Color Space : sRGB Exif Image Width : 1024 Exif Image Height : 768 Compression : JPEG (old-style) Thumbnail Offset : 314 Thumbnail Length : 920 IPTC Digest : 00000000000000000000000000000000 Displayed Units X : inches Displayed Units Y : inches Print Style : Centered Print Position : 0 0 Print Scale : 1 Global Angle : 120 Global Altitude : 30 URL List : Slices Group Name : Névtelen-1 Num Slices : 1 Pixel Aspect Ratio : 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 CS5 Photoshop Quality : 12 Photoshop Format : Standard Progressive Scans : 3 Scans XMP Toolkit : Adobe XMP Core 5.0-c060 61.134777, 2010/02/12-17:32:00 Creator Tool : Adobe Photoshop CS5 Windows Create Date : 2019:05:25 10:23:42+02:00 Metadata Date : 2019:05:25 10:23:42+02:00 Format : image/jpeg Instance ID : xmp.iid:84F62D68C67EE9119084C99B2E87B7B0 Document ID : xmp.did:84F62D68C67EE9119084C99B2E87B7B0 Original Document ID : xmp.did:84F62D68C67EE9119084C99B2E87B7B0 Color Mode : RGB ICC Profile Name : sRGB IEC61966-2.1 History Action : created History Instance ID : xmp.iid:84F62D68C67EE9119084C99B2E87B7B0 History When : 2019:05:25 10:23:42+02:00 History Software Agent : Adobe Photoshop CS5 Windows 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 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 Viewing Cond Illuminant : 19.6445 20.3718 16.8089 Viewing Cond Surround : 3.92889 4.07439 3.36179 Viewing Cond Illuminant Type : D50 Luminance : 76.03647 80 87.12462 Measurement Observer : CIE 1931 Measurement Backing : 0 0 0 Measurement Geometry : Unknown Measurement Flare : 0.999% Measurement Illuminant : D65 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) DCT Encode Version : 100 APP14 Flags 0 : [14] APP14 Flags 1 : (none) Color Transform : YCbCr Image Width : 1024 Image Height : 768 Encoding Process : Baseline DCT, Huffman coding Bits Per Sample : 8 Color Components : 3 Y Cb Cr Sub Sampling : YCbCr4:4:4 (1 1) Image Size : 1024x768 Megapixels : 0.786 Thumbnail Image : (Binary data 920 bytes, use -b option to extract)
As you can see, Photoshop stores a lot more stuff in the meta part of your saved image files.
And the metadata of the image that PHP saves:
exiftool proba_php.jpg
ExifTool Version Number : 10.40 File Name : proba_php.jpg Directory : . File Size : 264 kB File Modification Date/Time : 2019:05:25 11:57:55+02:00 File Access Date/Time : 2019:05:25 12:14:09+02:00 File Inode Change Date/Time : 2019:05:25 12:05:45+02:00 File Permissions : rw-r--r-- File Type : JPEG File Type Extension : jpg MIME Type : image/jpeg JFIF Version : 1.01 Resolution Unit : None X Resolution : 1 Y Resolution : 1 Comment : CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 85. Image Width : 2828 Image Height : 2828 Encoding Process : Baseline DCT, Huffman coding Bits Per Sample : 8 Color Components : 3 Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2) Image Size : 2828x2828 Megapixels : 8.0
Here and what is interesting is the data in the "Comment" field, which shows that the image was created with the PHP GD image manager extension with an image quality setting of 85.
Groups
Metadata is embedded in files in a structured way, so it is possible to query a separate group of related data, such as XMP including a record that Adobe applications place in image files. Here's how to get it from an image file that Photoshop saves:
exiftool -XMP:all proba_ps.jpg
XMP Toolkit : Adobe XMP Core 5.0-c060 61.134777, 2010/02/12-17:32:00 Creator Tool : Adobe Photoshop CS5 Windows Create Date : 2019:05:25 10:23:42+02:00 Metadata Date : 2019:05:25 10:23:42+02:00 Format : image/jpeg Instance ID : xmp.iid:84F62D68C67EE9119084C99B2E87B7B0 Document ID : xmp.did:84F62D68C67EE9119084C99B2E87B7B0 Original Document ID : xmp.did:84F62D68C67EE9119084C99B2E87B7B0 Color Mode : RGB ICC Profile Name : sRGB IEC61966-2.1 History Action : created History Instance ID : xmp.iid:84F62D68C67EE9119084C99B2E87B7B0 History When : 2019:05:25 10:23:42+02:00 History Software Agent : Adobe Photoshop CS5 Windows
So only list XMP-related fields and values.
In the command line, the ": all"suffix provides a list of all fields in textual form. Otherwise, it will output the XMP (or any of several fields) records as binary data, which can be processed by other programs, for example, into a file, etc.
Or, for example, you can query the Exif group similarly:
exiftool -Exif:all proba_ps.jpg
Orientation : Horizontal (normal) X Resolution : 72 Y Resolution : 72 Resolution Unit : inches Software : Adobe Photoshop CS5 Windows Modify Date : 2019:05:25 10:23:42 Color Space : sRGB Exif Image Width : 1024 Exif Image Height : 768 Compression : JPEG (old-style) Thumbnail Offset : 314 Thumbnail Length : 920 Thumbnail Image : (Binary data 920 bytes, use -b option to extract)
Unique fields
It is also possible to read individual fields, for example, if we need to create an automated processing script to evaluate certain data fields, etc.
In light of these, we can conveniently read the resolution of an image from one of our jpg examples:
exiftool -Imagesize proba_ps.jpg
Image Size : 1024x768
However, you can retrieve multiple fields at the same time, for example exif width and height separately:
exiftool -ExifImageWidth -ExifImageHeight proba_ps.jpg
Exif Image Width : 1024 Exif Image Height : 768
And so on, we can retrieve any number of unique fields.
Formatting data
We can format the requested information in many ways, so we can use it flexibly in our own tasks and programs.
JSON form
Remaining in the last example, if we needed the data in, say, JSON form, -j switch to our previous command:
exiftool -j -ExifImageWidth -ExifImageHeight proba_ps.jpg
And in JSON, we get the result that we can easily use from any of our programming languages:
[{
"SourceFile": "proba_ps.jpg",
"ExifImageWidth": 1024,
"ExifImageHeight": 768
}]
Double milled form
If we are in a situation that is just native Bash instructions - where no external JSON processing programs are available - then use it -l switch (small L) to the previous one -j instead:
exiftool -l -ExifImageWidth -ExifImageHeight proba_ps.jpg
In this case, we get the field name and value pairs in a double-row version:
Exif Image Width 1024 Exif Image Height 768
And this with the Bash cycles and array structure you can easily wrinkle it by taking advantage of line breaks.
PHP array form
If you want to process the received data in PHP, use -php switch:
exiftool -php -ExifImageWidth -ExifImageHeight proba_ps.jpg
Then we get the values in the form of a PHP array:
Array(Array( "SourceFile" => "proba_ps.jpg", "ExifImageWidth" => 1024, "ExifImageHeight" => 768 ));
which can then be easily parsed into a real PHP array.
Exiftool also includes a number of output formatting options, of which the command is useful manual page orient.
A next page we continue with the write function of the exiftool command ...
Navigation
- To post registration and login required
- 551 views