Added -c option to the exiv2 utility to set the Jpeg comment from a string given on the command line. Implements feature #446.

v0.27.3
Andreas Huggel 20 years ago
parent d509e8c86f
commit 8ef1d8f854

@ -1020,6 +1020,16 @@ namespace Action {
assert(image_.get() != 0); assert(image_.get() != 0);
image_->readMetadata(); image_->readMetadata();
if (!Params::instance().jpegComment_.empty()) {
if (Params::instance().verbose_) {
std::cout << "Setting Jpeg comment '"
<< Params::instance().jpegComment_
<< "'"
<< std::endl;
}
image_->setComment(Params::instance().jpegComment_);
}
// loop through command table and apply each command // loop through command table and apply each command
ModifyCmds& modifyCmds = Params::instance().modifyCmds_; ModifyCmds& modifyCmds = Params::instance().modifyCmds_;
ModifyCmds::const_iterator i = modifyCmds.begin(); ModifyCmds::const_iterator i = modifyCmds.begin();

@ -54,7 +54,7 @@ Adjust EXIF timestamps by the given time. This action requires the option
.TP .TP
.B mo | modify .B mo | modify
Apply commands to modify (add, set, delete) the EXIF/IPTC metadata of image Apply commands to modify (add, set, delete) the EXIF/IPTC metadata of image
files. Requires option \fB\-m\fP or \fB\-M\fP. files. Requires option \fB\-c\fP, \fB\-m\fP or \fB\-M\fP.
.TP .TP
.B mv | rename .B mv | rename
Rename files and/or set file timestamps according to the EXIF create Rename files and/or set file timestamps according to the EXIF create
@ -139,18 +139,21 @@ those for the \fB\-d\fP option.
Filename format for the 'rename' action. The format string follows Filename format for the 'rename' action. The format string follows
\fBstrftime\fP(3). Default filename format is %Y%m%d_%H%M%S. \fBstrftime\fP(3). Default filename format is %Y%m%d_%H%M%S.
.TP .TP
.B \-c \fItxt\fP
Jpeg comment string to set in the image ('modify' action).
.TP
.B \-m \fIfile\fP .B \-m \fIfile\fP
Command file for the modify action. Command file for the 'modify' action.
.TP .TP
.B \-M \fIcmd\fP .B \-M \fIcmd\fP
Command line for the modify action. The format for the commands is the same Command line for the 'modify' action. The format for the commands is the same
as that of the lines of a command file. as that of the lines of a command file.
.TP .TP
.B \-l \fIdir\fP .B \-l \fIdir\fP
Location (directory) for files to be inserted or extracted. Location (directory) for files to be inserted or extracted.
.TP .TP
.B \-S \fI.suf\fP .B \-S \fI.suf\fP
Use suffix \fI.suf\fP for source files for insert command. Use suffix \fI.suf\fP for source files in 'insert' action.
.SH COMMANDS .SH COMMANDS
Commands for the 'modify' action can be read from a command file, e.g., Commands for the 'modify' action can be read from a command file, e.g.,
.sp 1 .sp 1

@ -197,8 +197,9 @@ void Params::help(std::ostream& os) const
<< " mv | rename Rename files and/or set file timestamps according to the\n" << " mv | rename Rename files and/or set file timestamps according to the\n"
<< " Exif create timestamp. The filename format can be set with\n" << " Exif create timestamp. The filename format can be set with\n"
<< " -r format, timestamp options are controlled with -t and -T.\n" << " -r format, timestamp options are controlled with -t and -T.\n"
<< " mo | modify Apply commands to modify (add, set, delete) the Exif\n" << " mo | modify Apply commands to modify (add, set, delete) the Exif and\n"
<< " and Iptc metadata of image files. Requires option -m or -M.\n" << " Iptc metadata of image files or set the Jpeg comment.\n"
<< " Requires option -c, -m or -M.\n"
<< "\nOptions:\n" << "\nOptions:\n"
<< " -h Display this help and exit.\n" << " -h Display this help and exit.\n"
<< " -V Show the program version and exit.\n" << " -V Show the program version and exit.\n"
@ -232,6 +233,7 @@ void Params::help(std::ostream& os) const
<< " -r fmt Filename format for the 'rename' action. The format string\n" << " -r fmt Filename format for the 'rename' action. The format string\n"
<< " follows strftime(3). Default filename format is " << " follows strftime(3). Default filename format is "
<< format_ << ".\n" << format_ << ".\n"
<< " -c txt Jpeg comment string to set in the image.\n"
<< " -m file Command file for the modify action. The format for commands is\n" << " -m file Command file for the modify action. The format for commands is\n"
<< " set|add|del <key> [[<type>] <value>].\n" << " set|add|del <key> [[<type>] <value>].\n"
<< " -M cmd Command line for the modify action. The format for the\n" << " -M cmd Command line for the modify action. The format for the\n"
@ -258,6 +260,7 @@ int Params::option(int opt, const std::string& optarg, int optopt)
case 'd': rc = evalDelete(optarg); break; case 'd': rc = evalDelete(optarg); break;
case 'e': rc = evalExtract(optarg); break; case 'e': rc = evalExtract(optarg); break;
case 'i': rc = evalInsert(optarg); break; case 'i': rc = evalInsert(optarg); break;
case 'c': rc = evalModify(opt, optarg); break;
case 'm': rc = evalModify(opt, optarg); break; case 'm': rc = evalModify(opt, optarg); break;
case 'M': rc = evalModify(opt, optarg); break; case 'M': rc = evalModify(opt, optarg); break;
case 'l': directory_ = optarg; break; case 'l': directory_ = optarg; break;
@ -458,6 +461,7 @@ int Params::evalModify(int opt, const std::string& optarg)
action_ = Action::modify; action_ = Action::modify;
// fallthrough // fallthrough
case Action::modify: case Action::modify:
if (opt == 'c') jpegComment_ = optarg;
if (opt == 'm') cmdFiles_.push_back(optarg); // parse the files later if (opt == 'm') cmdFiles_.push_back(optarg); // parse the files later
if (opt == 'M') cmdLines_.push_back(optarg); // parse the commands later if (opt == 'M') cmdLines_.push_back(optarg); // parse the commands later
break; break;
@ -567,9 +571,10 @@ int Params::getopt(int argc, char* const argv[])
<< ": Adjust action requires option -a time\n"; << ": Adjust action requires option -a time\n";
rc = 1; rc = 1;
} }
if (action_ == Action::modify && cmdFiles_.empty() && cmdLines_.empty()) { if ( action_ == Action::modify
&& cmdFiles_.empty() && cmdLines_.empty() && jpegComment_.empty()) {
std::cerr << progname() std::cerr << progname()
<< ": Modify action requires at least one -m or -M option\n"; << ": Modify action requires at least one -c, -m or -M option\n";
rc = 1; rc = 1;
} }
if (0 == files_.size()) { if (0 == files_.size()) {

@ -149,6 +149,7 @@ public:
CmdFiles cmdFiles_; //!< Names of the modification command files CmdFiles cmdFiles_; //!< Names of the modification command files
CmdLines cmdLines_; //!< Commands from the command line CmdLines cmdLines_; //!< Commands from the command line
ModifyCmds modifyCmds_; //!< Parsed modification commands ModifyCmds modifyCmds_; //!< Parsed modification commands
std::string jpegComment_; //!< Jpeg comment to set in the image
std::string directory_; //!< Location for files to extract/insert std::string directory_; //!< Location for files to extract/insert
std::string suffix_; //!< File extension of the file to insert std::string suffix_; //!< File extension of the file to insert
Files files_; //!< List of non-option arguments. Files files_; //!< List of non-option arguments.
@ -158,7 +159,7 @@ private:
@brief Default constructor. Note that optstring_ is initialized here. @brief Default constructor. Note that optstring_ is initialized here.
The c'tor is private to force instantiation through instance(). The c'tor is private to force instantiation through instance().
*/ */
Params() : optstring_(":hVvfktTFa:r:p:d:e:i:m:M:l:S:"), Params() : optstring_(":hVvfktTFa:r:p:d:e:i:c:m:M:l:S:"),
help_(false), help_(false),
version_(false), version_(false),
verbose_(false), verbose_(false),

@ -24,8 +24,8 @@ Actions:
mv | rename Rename files and/or set file timestamps according to the mv | rename Rename files and/or set file timestamps according to the
Exif create timestamp. The filename format can be set with Exif create timestamp. The filename format can be set with
-r format, timestamp options are controlled with -t and -T. -r format, timestamp options are controlled with -t and -T.
mo | modify Apply commands to modify (add, set, delete) the Exif mo | modify Apply commands to modify (add, set, delete) the Exif and
and Iptc metadata of image files. Requires option -m or -M. Iptc metadata of image files. Requires option -c, -m or -M.
Options: Options:
-h Display this help and exit. -h Display this help and exit.
@ -59,6 +59,7 @@ Options:
are the same as those for the -d option. are the same as those for the -d option.
-r fmt Filename format for the 'rename' action. The format string -r fmt Filename format for the 'rename' action. The format string
follows strftime(3). Default filename format is %Y%m%d_%H%M%S. follows strftime(3). Default filename format is %Y%m%d_%H%M%S.
-c txt Jpeg comment string to set in the image.
-m file Command file for the modify action. The format for commands is -m file Command file for the modify action. The format for commands is
set|add|del <key> [[<type>] <value>]. set|add|del <key> [[<type>] <value>].
-M cmd Command line for the modify action. The format for the -M cmd Command line for the modify action. The format for the

Loading…
Cancel
Save