pub struct WriteBuilder<'et> { /* private fields */ }Expand description
写入构建器
Implementations§
Source§impl<'et> WriteBuilder<'et>
impl<'et> WriteBuilder<'et>
设置多个标签
Sourcepub fn tag_append(
self,
tag: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn tag_append( self, tag: impl Into<String>, value: impl Into<String>, ) -> Self
追加值到标签(-TAG+=VALUE)
使用 += 运算符将值追加到现有标签值后面。
适用于列表类型的标签,如 Keywords 等。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 追加关键词到现有列表
exiftool.write("photo.jpg")
.tag_append("Keywords", "landscape")
.overwrite_original(true)
.execute()?;Sourcepub fn tag_remove(
self,
tag: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn tag_remove( self, tag: impl Into<String>, value: impl Into<String>, ) -> Self
从标签中移除值(-TAG-=VALUE)
使用 -= 运算符从现有标签值中移除指定值。
适用于列表类型的标签。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 从关键词列表中移除某个关键词
exiftool.write("photo.jpg")
.tag_remove("Keywords", "old-keyword")
.overwrite_original(true)
.execute()?;Sourcepub fn tag_prepend(
self,
tag: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn tag_prepend( self, tag: impl Into<String>, value: impl Into<String>, ) -> Self
前置值到标签(-TAG^=VALUE)
使用 ^= 运算符将值前置到现有标签值之前。
适用于列表类型的标签。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 在关键词列表前面插入关键词
exiftool.write("photo.jpg")
.tag_prepend("Keywords", "important")
.overwrite_original(true)
.execute()?;Sourcepub fn tag_from_file(
self,
tag: impl Into<String>,
file_path: impl Into<String>,
) -> Self
pub fn tag_from_file( self, tag: impl Into<String>, file_path: impl Into<String>, ) -> Self
从文件读取值写入标签(-TAG<=FILE)
使用 <= 运算符从指定文件中读取数据作为标签值。
常用于写入二进制数据(如缩略图、预览图)。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 从文件读取缩略图写入
exiftool.write("photo.jpg")
.tag_from_file("ThumbnailImage", "thumb.jpg")
.overwrite_original(true)
.execute()?;Sourcepub fn tag_append_from_file(
self,
tag: impl Into<String>,
file_path: impl Into<String>,
) -> Self
pub fn tag_append_from_file( self, tag: impl Into<String>, file_path: impl Into<String>, ) -> Self
追加从文件读取的值到标签(-TAG+<=FILE)
使用 +<= 运算符从指定文件中读取数据追加到现有标签值。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 从文件追加数据到标签
exiftool.write("photo.jpg")
.tag_append_from_file("Comment", "comment.txt")
.overwrite_original(true)
.execute()?;Sourcepub fn overwrite_original(self, yes: bool) -> Self
pub fn overwrite_original(self, yes: bool) -> Self
覆盖原始文件(不创建备份)
Sourcepub fn write_mode(self, mode: WriteMode) -> Self
pub fn write_mode(self, mode: WriteMode) -> Self
设置写入模式
使用 -wm 选项设置写入/创建标签的模式
§模式
WriteMode::Write(w) - 写入标签(默认)WriteMode::Create(c) - 仅创建标签(不修改现有标签)WriteMode::WriteCreate(wc) - 写入或创建
§示例
use exiftool_rs_wrapper::{ExifTool, WriteMode};
let exiftool = ExifTool::new()?;
// 仅创建新标签,不修改现有标签
exiftool.write("photo.jpg")
.tag("NewTag", "value")
.write_mode(WriteMode::Create)
.execute()?;Sourcepub fn api_option(
self,
opt: impl Into<String>,
value: Option<impl Into<String>>,
) -> Self
pub fn api_option( self, opt: impl Into<String>, value: Option<impl Into<String>>, ) -> Self
设置 API 选项
使用 -api 选项设置 ExifTool API 选项
Sourcepub fn user_param(
self,
param: impl Into<String>,
value: Option<impl Into<String>>,
) -> Self
pub fn user_param( self, param: impl Into<String>, value: Option<impl Into<String>>, ) -> Self
设置用户参数
使用 -userParam 选项设置用户参数
Sourcepub fn ignore_minor_errors(self, yes: bool) -> Self
pub fn ignore_minor_errors(self, yes: bool) -> Self
忽略次要错误
使用 -m 选项忽略次要错误和警告,继续处理其他文件。
这在批量处理时很有用,可以避免单个文件错误导致整个操作失败。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 批量写入时忽略次要错误
exiftool.write("photo.jpg")
.tag("Copyright", "© 2026")
.ignore_minor_errors(true)
.execute()?;Sourcepub fn preserve_time(self, yes: bool) -> Self
pub fn preserve_time(self, yes: bool) -> Self
保留文件修改时间
使用 -P 选项保留文件的原始修改时间。
默认情况下,ExifTool 会更新文件的修改时间为当前时间。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 写入元数据但保留原始修改时间
exiftool.write("photo.jpg")
.tag("Copyright", "© 2026")
.preserve_time(true)
.execute()?;Sourcepub fn quiet(self, yes: bool) -> Self
pub fn quiet(self, yes: bool) -> Self
静默模式
使用 -q 选项启用静默模式,减少输出信息。
可以使用多次来增加静默程度。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 静默模式下写入
exiftool.write("photo.jpg")
.tag("Copyright", "© 2026")
.quiet(true)
.execute()?;Sourcepub fn zip_compression(self, yes: bool) -> Self
pub fn zip_compression(self, yes: bool) -> Self
启用 ZIP 压缩
使用 -z 选项读写压缩的元数据信息。
某些文件格式支持压缩元数据存储。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 使用压缩写入元数据
exiftool.write("photo.jpg")
.tag("Copyright", "© 2026")
.zip_compression(true)
.execute()?;Sourcepub fn fix_base(self, offset: Option<i64>) -> Self
pub fn fix_base(self, offset: Option<i64>) -> Self
修复 MakerNotes 偏移
使用 -F 选项修复 MakerNotes 的基准偏移。
这在处理某些损坏或格式异常的图像文件时很有用。
§参数
offset- 可选的偏移量修正值(以字节为单位)
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 自动修复 MakerNotes 偏移
exiftool.write("photo.jpg")
.tag("Copyright", "© 2026")
.fix_base(None)
.execute()?;
// 指定偏移量修复
exiftool.write("photo.jpg")
.fix_base(Some(1024))
.execute()?;Sourcepub fn fix_base_offset(self, offset: i64) -> Self
pub fn fix_base_offset(self, offset: i64) -> Self
修复 MakerNotes 偏移(带指定偏移量)
使用 -FOFFSET 选项指定具体偏移量修复 MakerNotes。
这是 fix_base(Some(offset)) 的便捷方法。
Sourcepub fn global_time_shift(self, shift: impl Into<String>) -> Self
pub fn global_time_shift(self, shift: impl Into<String>) -> Self
全局时间偏移
对应 ExifTool 的 -globalTimeShift 选项,对所有日期/时间标签
应用统一的时间偏移。格式为 [+|-]Y:M:D H:M:S。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 将所有时间标签向前偏移 1 小时
exiftool.write("photo.jpg")
.global_time_shift("+0:0:0 1:0:0")
.execute()?;Sourcepub fn offset(self, tag: impl Into<String>, offset: impl Into<String>) -> Self
pub fn offset(self, tag: impl Into<String>, offset: impl Into<String>) -> Self
日期/时间偏移
示例: .offset("DateTimeOriginal", "+1:0:0 0:0:0") 表示增加 1 天
Sourcepub fn copy_from_with_redirect<P: AsRef<Path>>(
self,
source: P,
redirects: &[(&str, &str)],
) -> Self
pub fn copy_from_with_redirect<P: AsRef<Path>>( self, source: P, redirects: &[(&str, &str)], ) -> Self
从文件复制标签(带重定向映射)
使用 -tagsFromFile SRCFILE 配合 -DSTTAG<SRCTAG 重定向语法。
可以指定源标签到目标标签的映射关系。
§参数
source- 源文件路径redirects- 标签重定向列表,每项为(目标标签, 源标签)。 生成-DSTTAG<SRCTAG参数。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 从源文件复制 Artist 到 Author,DateTimeOriginal 到 CreateDate
exiftool.write("target.jpg")
.copy_from_with_redirect("source.jpg", &[
("Author", "Artist"),
("CreateDate", "DateTimeOriginal"),
])
.overwrite_original(true)
.execute()?;Sourcepub fn copy_from_with_append<P: AsRef<Path>>(
self,
source: P,
redirects: &[(&str, &str)],
) -> Self
pub fn copy_from_with_append<P: AsRef<Path>>( self, source: P, redirects: &[(&str, &str)], ) -> Self
从文件复制标签(带追加重定向)
使用 -+DSTTAG<SRCTAG 追加方式复制标签。
§参数
source- 源文件路径redirects- 标签重定向列表,每项为(目标标签, 源标签)。 生成-+DSTTAG<SRCTAG参数。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 从源文件追加 Keywords
exiftool.write("target.jpg")
.copy_from_with_append("source.jpg", &[
("Keywords", "Keywords"),
])
.overwrite_original(true)
.execute()?;Sourcepub fn condition_num(self, num: u8, expr: impl Into<String>) -> Self
pub fn condition_num(self, num: u8, expr: impl Into<String>) -> Self
Sourcepub fn print_format_no_newline(self, format: impl Into<String>) -> Self
pub fn print_format_no_newline(self, format: impl Into<String>) -> Self
自定义打印格式(不追加换行符)
使用 -p- 选项按指定格式打印输出,不自动追加换行。
Sourcepub fn print_format(self, format: impl Into<String>) -> Self
pub fn print_format(self, format: impl Into<String>) -> Self
自定义打印格式
使用 -p 选项按指定格式打印输出。
Sourcepub fn efile_variant(
self,
filename: impl Into<String>,
num: Option<u8>,
force: bool,
) -> Self
pub fn efile_variant( self, filename: impl Into<String>, num: Option<u8>, force: bool, ) -> Self
保存错误文件名到文件(带级别和强制标志)
使用 -efileNUM 或 -efile! 或 -efileNUM! 变体。
§参数
filename- 输出文件路径num- 可选级别(2、3 等),None表示默认级别force- 是否使用!后缀(强制覆盖)
Sourcepub fn json_import(self, path: impl Into<String>) -> Self
pub fn json_import(self, path: impl Into<String>) -> Self
导入 JSON 文件中的标签
使用 -j=JSONFILE 选项从 JSON 文件中导入标签数据。
Sourcepub fn json_append(self, path: impl Into<String>) -> Self
pub fn json_append(self, path: impl Into<String>) -> Self
追加导入 JSON 文件中的标签
使用 -j+=JSONFILE 选项从 JSON 文件中追加导入标签数据。
Sourcepub fn csv_import(self, path: impl Into<String>) -> Self
pub fn csv_import(self, path: impl Into<String>) -> Self
导入 CSV 文件中的标签
使用 -csv=CSVFILE 选项从 CSV 文件中导入标签数据。
Sourcepub fn csv_append(self, path: impl Into<String>) -> Self
pub fn csv_append(self, path: impl Into<String>) -> Self
追加导入 CSV 文件中的标签
使用 -csv+=CSVFILE 选项从 CSV 文件中追加导入标签数据。
Sourcepub fn text_out_append(self, ext: impl Into<String>) -> Self
pub fn text_out_append(self, ext: impl Into<String>) -> Self
文本输出到文件(追加模式)
使用 -w+ 选项将输出追加到已有文件。
Sourcepub fn text_out_create(self, ext: impl Into<String>) -> Self
pub fn text_out_create(self, ext: impl Into<String>) -> Self
文本输出到文件(仅创建新文件)
使用 -w! 选项将输出写入新文件,但不覆盖已有文件。
Sourcepub fn tag_out_append(self, format: impl Into<String>) -> Self
pub fn tag_out_append(self, format: impl Into<String>) -> Self
标签输出到文件(追加模式)
使用 -W+ 选项为每个标签创建输出文件,追加到已有文件。
Sourcepub fn tag_out_create(self, format: impl Into<String>) -> Self
pub fn tag_out_create(self, format: impl Into<String>) -> Self
标签输出到文件(仅创建新文件)
使用 -W! 选项为每个标签创建输出文件,但不覆盖已有文件。
Sourcepub fn extension_add(self, ext: impl Into<String>) -> Self
pub fn extension_add(self, ext: impl Into<String>) -> Self
追加扩展名过滤
使用 -ext+ 选项追加文件扩展名过滤。
递归处理子目录(包含隐藏目录)
使用 -r. 选项递归处理时包含以 . 开头的隐藏目录。
Sourcepub fn execute(self) -> Result<WriteResult>
pub fn execute(self) -> Result<WriteResult>
执行写入操作