What's the best way to add a custom tag to any JPEG regardless of format?
I don't know a lot about the JPEG format but my understanding is that you can't have EXIF and JFIF in the same file, so stuffing a custom tag into EXIF data would not be a good solution since the target image might be JFIF format. Furthermore, as I understand it, EXIF defines every tag that may appear within it and you cannot stuff arbitrary tags into it. So, what's the best way to add a custom tag to any JPEG image and why?
The best way to do this is using XMP if your applications support it. XMP is extensible (ie. you can create custom tags without creating problems) and it becoming a popular metadata format.
The sample config file (https://exiftool.org/config.html) gives a few examples of custom tags (EXIF, IPTC and XMP, but as I said XMP is really the only extensible format of these).
- Phil
Can you create custom tags on the command line or do you have to use a config file? The config file seems a bit intimidating for a non-perl programmer.
You can only do this with the config file.
The sample config file is intimidating because it contains a number of different examples. When you trim it down to remove everything but what you need (the custom XMP tags), it isn't very complicated:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::XMP::Main' => {
xxx => {
SubDirectory => {
TagTable => 'Image::ExifTool::UserDefined::xxx',
},
},
},
);
%Image::ExifTool::UserDefined::xxx = (
GROUPS => { 0 => 'XMP', 1 => 'XMP-xxx', 2 => 'Image' },
NAMESPACE => { 'xxx' => 'http://ns.myname.com/xxx/1.0/' },
WRITABLE => 'string',
NewXMPxxxTag1 => { },
NewXMPxxxTag2 => { },
NewXMPxxxTag3 => { },
);
1; #end
- Phil
I notice that XML is written to APP1 but so, too, is EXIF. Can the two co-exist? What about EXIF and JFIF? Can you comment on the mutual exclusivity of different meta formats?
All of the different types of metadata may co-exist in an image. The signature at the start of the segment identifies the metadata so it doesn't matter if 2 types use APP1. Technically, both JFIF and EXIF specify that their segments come first in the file, but I have seen a lot of files with both, and ExifTool (and many other software packages) will accept them even if they don't come first. But JFIF provides only minimal information that is present in EXIF anyway, so is only useful for software that doesn't read EXIF when both are present.
- Phil