pub struct ExifTool { /* private fields */ }Expand description
ExifTool 主结构体
使用 -stay_open 模式保持 ExifTool 进程运行,
避免每次操作都重新启动进程的开销。
§线程安全
ExifTool 是线程安全的,可以在多个线程间共享。
内部使用 Arc<Mutex> 保护进程通信。
Implementations§
Source§impl ExifTool
impl ExifTool
Sourcepub fn query<P: AsRef<Path>>(&self, path: P) -> QueryBuilder<'_>
pub fn query<P: AsRef<Path>>(&self, path: P) -> QueryBuilder<'_>
查询单个文件的元数据
返回一个 QueryBuilder,可以使用 Builder 模式配置查询选项。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 基本查询
let metadata = exiftool.query("photo.jpg").execute()?;
// 高级查询
let metadata = exiftool.query("photo.jpg")
.include_unknown(true)
.tag("Make")
.tag("Model")
.execute()?;Sourcepub fn query_batch<P: AsRef<Path>>(&self, paths: &[P]) -> BatchQueryBuilder<'_>
pub fn query_batch<P: AsRef<Path>>(&self, paths: &[P]) -> BatchQueryBuilder<'_>
批量查询多个文件的元数据
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
let paths = vec!["photo1.jpg", "photo2.jpg", "photo3.jpg"];
let results = exiftool.query_batch(&paths)
.tag("FileName")
.tag("ImageSize")
.execute()?;
for (path, metadata) in results {
println!("{}: {:?}", path.display(), metadata.get("FileName"));
}Sourcepub fn write<P: AsRef<Path>>(&self, path: P) -> WriteBuilder<'_>
pub fn write<P: AsRef<Path>>(&self, path: P) -> WriteBuilder<'_>
写入元数据到文件
返回一个 WriteBuilder,可以使用 Builder 模式配置写入选项。
§警告
默认情况下,ExifTool 会创建备份文件(filename_original)。
使用 overwrite_original(true) 可以不创建备份直接覆盖原文件。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 基本写入
exiftool.write("photo.jpg")
.tag("Copyright", "© 2026 My Company")
.execute()?;
// 高级写入
exiftool.write("photo.jpg")
.tag("Artist", "Photographer")
.tag("Copyright", "© 2026")
.delete("Comment")
.overwrite_original(true)
.execute()?;Sourcepub fn read_tag<T, P, S>(&self, path: P, tag: S) -> Result<T>
pub fn read_tag<T, P, S>(&self, path: P, tag: S) -> Result<T>
读取单个标签的值
这是 query().tag().execute() 的快捷方式。
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
let make: String = exiftool.read_tag("photo.jpg", "Make")?;
println!("相机制造商: {}", make);
// 使用 TagId
use exiftool_rs_wrapper::TagId;
let model: String = exiftool.read_tag("photo.jpg", "Model")?;Sourcepub fn version(&self) -> Result<String>
pub fn version(&self) -> Result<String>
获取 ExifTool 版本
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
let version = exiftool.version()?;
println!("ExifTool version: {}", version);获取所有支持的标签列表
Sourcepub fn delete_original<P: AsRef<Path>>(
&self,
path: P,
force: bool,
) -> Result<()>
pub fn delete_original<P: AsRef<Path>>( &self, path: P, force: bool, ) -> Result<()>
删除备份文件
使用 -delete_original 选项删除 _original 备份文件。
§参数
path- 原始文件路径(ExifTool 会找到对应的备份文件)force- 是否强制删除(使用-delete_original!)
§示例
use exiftool_rs_wrapper::ExifTool;
let exiftool = ExifTool::new()?;
// 删除 photo.jpg 的备份文件 photo.jpg_original
exiftool.delete_original("photo.jpg", false)?;
// 强制删除备份文件
exiftool.delete_original("photo.jpg", true)?;Trait Implementations§
Source§impl AdvancedWriteOperations for ExifTool
impl AdvancedWriteOperations for ExifTool
Source§fn shift_datetime<P: AsRef<Path>>(
&self,
path: P,
offset: DateTimeOffset,
) -> Result<()>
fn shift_datetime<P: AsRef<Path>>( &self, path: P, offset: DateTimeOffset, ) -> Result<()>
偏移日期时间标签 Read more
Source§fn shift_specific_datetime<P: AsRef<Path>>(
&self,
path: P,
tag: TagId,
offset: DateTimeOffset,
) -> Result<()>
fn shift_specific_datetime<P: AsRef<Path>>( &self, path: P, tag: TagId, offset: DateTimeOffset, ) -> Result<()>
仅偏移特定日期时间标签
Source§fn numeric_operation<P: AsRef<Path>>(
&self,
path: P,
tag: TagId,
operation: NumericOperation,
) -> Result<()>
fn numeric_operation<P: AsRef<Path>>( &self, path: P, tag: TagId, operation: NumericOperation, ) -> Result<()>
数值运算
Source§impl BinaryOperations for ExifTool
impl BinaryOperations for ExifTool
Source§fn write_binary<P: AsRef<Path>>(&self, path: P) -> BinaryWriteBuilder<'_>
fn write_binary<P: AsRef<Path>>(&self, path: P) -> BinaryWriteBuilder<'_>
写入二进制数据
Source§impl ConfigOperations for ExifTool
impl ConfigOperations for ExifTool
Source§fn with_config<P: AsRef<Path>>(self, config_path: P) -> Self
fn with_config<P: AsRef<Path>>(self, config_path: P) -> Self
加载配置文件
Source§fn calculate_checksum<P: AsRef<Path>>(
&self,
path: P,
algorithm: ChecksumAlgorithm,
) -> Result<ChecksumResult>
fn calculate_checksum<P: AsRef<Path>>( &self, path: P, algorithm: ChecksumAlgorithm, ) -> Result<ChecksumResult>
计算校验和
Source§fn calculate_checksums<P: AsRef<Path>>(
&self,
path: P,
algorithms: &[ChecksumAlgorithm],
) -> Result<Vec<ChecksumResult>>
fn calculate_checksums<P: AsRef<Path>>( &self, path: P, algorithms: &[ChecksumAlgorithm], ) -> Result<Vec<ChecksumResult>>
计算多个校验和
Source§fn verify_checksum<P: AsRef<Path>>(
&self,
path: P,
expected: &str,
algorithm: ChecksumAlgorithm,
) -> Result<bool>
fn verify_checksum<P: AsRef<Path>>( &self, path: P, expected: &str, algorithm: ChecksumAlgorithm, ) -> Result<bool>
验证文件完整性
Source§fn diff<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
source: P,
target: Q,
) -> Result<DiffResult>
fn diff<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, target: Q, ) -> Result<DiffResult>
比较两个文件的元数据
比较两个文件的元数据(仅特定标签)
Source§impl FileOperations for ExifTool
impl FileOperations for ExifTool
Source§fn rename_file<P: AsRef<Path>>(
&self,
path: P,
pattern: &RenamePattern,
) -> Result<PathBuf>
fn rename_file<P: AsRef<Path>>( &self, path: P, pattern: &RenamePattern, ) -> Result<PathBuf>
重命名单个文件
Source§fn rename_files<P: AsRef<Path>>(
&self,
paths: &[P],
pattern: &RenamePattern,
) -> Result<Vec<PathBuf>>
fn rename_files<P: AsRef<Path>>( &self, paths: &[P], pattern: &RenamePattern, ) -> Result<Vec<PathBuf>>
批量重命名文件
Source§fn organize_by_date<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
path: P,
target_dir: Q,
date_format: &str,
) -> Result<PathBuf>
fn organize_by_date<P: AsRef<Path>, Q: AsRef<Path>>( &self, path: P, target_dir: Q, date_format: &str, ) -> Result<PathBuf>
按日期组织文件到目录
Source§fn organize<P: AsRef<Path>>(
&self,
path: P,
options: &OrganizeOptions,
) -> Result<PathBuf>
fn organize<P: AsRef<Path>>( &self, path: P, options: &OrganizeOptions, ) -> Result<PathBuf>
根据元数据组织文件
Source§impl FormatOperations for ExifTool
impl FormatOperations for ExifTool
Source§fn read_formatted<P: AsRef<Path>>(
&self,
path: P,
options: &ReadOptions,
) -> Result<FormattedOutput>
fn read_formatted<P: AsRef<Path>>( &self, path: P, options: &ReadOptions, ) -> Result<FormattedOutput>
使用自定义格式读取元数据
Source§fn read_directory<P: AsRef<Path>>(
&self,
path: P,
options: &ReadOptions,
) -> Result<Vec<FormattedOutput>>
fn read_directory<P: AsRef<Path>>( &self, path: P, options: &ReadOptions, ) -> Result<Vec<FormattedOutput>>
递归读取目录
Source§impl GeoOperations for ExifTool
impl GeoOperations for ExifTool
Source§fn geotag_from_track<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
image: P,
track_file: Q,
) -> Result<()>
fn geotag_from_track<P: AsRef<Path>, Q: AsRef<Path>>( &self, image: P, track_file: Q, ) -> Result<()>
从 GPS 轨迹文件地理标记
Source§fn generate_tracklog<P: AsRef<Path>, Q: AsRef<Path>>(
&self,
images: &[P],
output: Q,
) -> Result<()>
fn generate_tracklog<P: AsRef<Path>, Q: AsRef<Path>>( &self, images: &[P], output: Q, ) -> Result<()>
生成 GPS 轨迹文件
Source§fn reverse_geocode<P: AsRef<Path>>(
&self,
coord: &GpsCoordinate,
) -> Result<GeocodeResult>
fn reverse_geocode<P: AsRef<Path>>( &self, coord: &GpsCoordinate, ) -> Result<GeocodeResult>
反向地理编码
Source§impl HexDumpOperations for ExifTool
impl HexDumpOperations for ExifTool
Source§impl StreamingOperations for ExifTool
impl StreamingOperations for ExifTool
Source§fn process_streaming<P, F, R>(
&self,
path: P,
options: &StreamOptions,
processor: F,
) -> Result<R>
fn process_streaming<P, F, R>( &self, path: P, options: &StreamOptions, processor: F, ) -> Result<R>
流式处理大文件
Source§impl VerboseOperations for ExifTool
impl VerboseOperations for ExifTool
Source§fn verbose_dump<P: AsRef<Path>>(
&self,
path: P,
options: &VerboseOptions,
) -> Result<String>
fn verbose_dump<P: AsRef<Path>>( &self, path: P, options: &VerboseOptions, ) -> Result<String>
获取详细输出
Auto Trait Implementations§
impl Freeze for ExifTool
impl RefUnwindSafe for ExifTool
impl Send for ExifTool
impl Sync for ExifTool
impl Unpin for ExifTool
impl UnsafeUnpin for ExifTool
impl UnwindSafe for ExifTool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more