Sample usage of high-level metadata operations.
#include <exiv2/exiv2.hpp>
#include <iostream>
int main(int argc, char* const argv[]) {
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return EXIT_FAILURE;
}
std::string file(argv[1]);
exifData["Exif.Image.Model"] = "Test 1";
exifData["Exif.Image.SamplesPerPixel"] = static_cast<uint16_t>(162);
exifData["Exif.Image.XResolution"] = -2;
std::cout << "Added a few tags the quick way.\n";
v->read("1999:12:31 23:59:59");
exifData.
add(key, v.get());
std::cout << "Added key \"" << key << "\", value \"" << *v << "\"\n";
std::cout << "Added key \"" << key << "\", value \"" << rv << "\"\n";
date.replace(0, 4,
"2000");
std::cout <<
"Modified key \"" << tag.
key() <<
"\", new value \"" << tag.
value() <<
"\"\n";
if (pos == exifData.
end())
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Key not found");
v = pos->getValue();
if (!prv)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Downcast failed");
pos->setValue(&rv);
std::cout << "Modified key \"" << key << "\", new value \"" << pos->value() << "\"\n";
if (pos == exifData.
end())
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Key not found");
std::cout << "Deleted key \"" << key << "\"\n";
image->setExifData(exifData);
image->writeMetadata();
return EXIT_SUCCESS;
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return EXIT_FAILURE;
}
}
Simple error class used for exceptions. An output operator is provided to print errors to a stream.
Definition: error.hpp:235
A container for Exif data. This is a top-level class of the Exiv2 library. The container holds Exifda...
Definition: exif.hpp:379
iterator erase(iterator pos)
Delete the Exifdatum at iterator position pos, return the position of the next exifdatum....
void add(const ExifKey &key, const Value *pValue)
Add an Exifdatum from the supplied key and value pair. This method copies (clones) key and value....
iterator findKey(const ExifKey &key)
Find the first Exifdatum with the given key, return an iterator to it.
iterator end()
End of the metadata.
Definition: exif.hpp:439
Concrete keys for Exif metadata and access to Exif tag reference data.
Definition: tags.hpp:271
An Exif metadatum, consisting of an ExifKey and a Value and methods to manipulate these.
Definition: exif.hpp:41
const Value & value() const override
Return a constant reference to the value.
std::string key() const override
Return the key of the Exifdatum.
std::string toString() const override
Return the value as a string.
static Image::UniquePtr open(const std::string &path, bool useCurl=true)
Create an Image subclass of the appropriate type by reading the specified file. Image type is derived...
Template for a Value of a basic type. This is used for unsigned and signed short, long and rationals.
Definition: value.hpp:1131
ValueList value_
The container for all values. In your application, if you know what subclass of Value you're dealing ...
Definition: value.hpp:1214
int read(const byte *buf, size_t len, ByteOrder byteOrder) override
Read the value from a character buffer.
Definition: value.hpp:1502
static UniquePtr create(TypeId typeId)
A (simple) factory to create a Value type.
static void terminate()
Terminate the XMP Toolkit and unregister custom namespaces.
static bool initialize(XmpParser::XmpLockFct xmpLockFct=nullptr, void *pLockData=nullptr)
Initialize the XMP Toolkit.
std::pair< int32_t, int32_t > Rational
8 byte signed rational type.
Definition: types.hpp:31
@ date
IPTC date type.
Definition: types.hpp:88
@ asciiString
Exif ASCII type, 8-bit byte.
Definition: types.hpp:72
ValueType< URational > URationalValue
Unsigned rational value type.
Definition: value.hpp:1302