Skip to main content

ExifTool

Struct ExifTool 

Source
pub struct ExifTool { /* private fields */ }
Expand description

ExifTool 主结构体

使用 -stay_open 模式保持 ExifTool 进程运行, 避免每次操作都重新启动进程的开销。

§线程安全

ExifTool 是线程安全的,可以在多个线程间共享。 内部使用 Arc<Mutex> 保护进程通信。

Implementations§

Source§

impl ExifTool

Source

pub fn new() -> Result<Self>

创建新的 ExifTool 实例

启动一个 -stay_open 模式的 ExifTool 进程。

§错误

如果 ExifTool 未安装或无法启动,返回 Error::ExifToolNotFound

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;
Source

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()?;
Source

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"));
}
Source

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()?;
Source

pub fn read_tag<T, P, S>(&self, path: P, tag: S) -> Result<T>
where T: for<'de> Deserialize<'de>, P: AsRef<Path>, S: AsRef<str>,

读取单个标签的值

这是 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")?;
Source

pub fn version(&self) -> Result<String>

获取 ExifTool 版本

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;
let version = exiftool.version()?;
println!("ExifTool version: {}", version);
Source

pub fn list_tags(&self) -> Result<Vec<String>>

获取所有支持的标签列表

Source

pub fn close(&self) -> Result<()>

关闭 ExifTool 进程

优雅地关闭进程。通常不需要手动调用, 因为 Drop 实现会自动处理。

Source

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)?;
Source

pub fn restore_original<P: AsRef<Path>>(&self, path: P) -> Result<()>

从备份恢复原始文件

使用 -restore_original 选项从 _original 备份文件恢复原始文件。

§参数
  • path - 文件路径
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 从 photo.jpg_original 恢复 photo.jpg
exiftool.restore_original("photo.jpg")?;

Trait Implementations§

Source§

impl AdvancedWriteOperations for ExifTool

Source§

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<()>

仅偏移特定日期时间标签
Source§

fn numeric_operation<P: AsRef<Path>>( &self, path: P, tag: TagId, operation: NumericOperation, ) -> Result<()>

数值运算
Source§

fn append_string<P: AsRef<Path>>( &self, path: P, tag: TagId, suffix: &str, ) -> Result<()>

字符串追加
Source§

fn write_if<P: AsRef<Path>, F>( &self, path: P, _condition: &str, builder_fn: F, ) -> Result<()>
where F: FnOnce(WriteBuilder<'_>) -> WriteBuilder<'_>,

条件写入
Source§

impl BinaryOperations for ExifTool

Source§

fn read_binary<P: AsRef<Path>>( &self, path: P, tag: BinaryTag, ) -> Result<Vec<u8>>

读取二进制数据
Source§

fn write_binary<P: AsRef<Path>>(&self, path: P) -> BinaryWriteBuilder<'_>

写入二进制数据
Source§

fn extract_thumbnail<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, dest: Q, ) -> Result<()>

提取缩略图到文件
Source§

fn extract_preview<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, dest: Q, ) -> Result<()>

提取预览图到文件
Source§

impl Clone for ExifTool

Source§

fn clone(&self) -> ExifTool

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConfigOperations for ExifTool

Source§

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>

计算校验和
Source§

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>

验证文件完整性
Source§

fn diff<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, target: Q, ) -> Result<DiffResult>

比较两个文件的元数据
Source§

fn diff_tags<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, target: Q, tags: &[TagId], ) -> Result<DiffResult>

比较两个文件的元数据(仅特定标签)
Source§

impl Debug for ExifTool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExifTool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FileOperations for ExifTool

Source§

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>>

批量重命名文件
Source§

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>

根据元数据组织文件
Source§

fn create_metadata_backup<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, backup_path: Q, ) -> Result<()>

生成元数据备份文件 (.mie 格式)
Source§

fn restore_from_backup<P: AsRef<Path>, Q: AsRef<Path>>( &self, backup: P, target: Q, ) -> Result<()>

从备份恢复元数据
Source§

impl FormatOperations for ExifTool

Source§

fn read_formatted<P: AsRef<Path>>( &self, path: P, options: &ReadOptions, ) -> Result<FormattedOutput>

使用自定义格式读取元数据
Source§

fn read_xml<P: AsRef<Path>>(&self, path: P) -> Result<String>

读取为 XML
Source§

fn read_csv<P: AsRef<Path>>(&self, path: P) -> Result<String>

读取为 CSV
Source§

fn read_html<P: AsRef<Path>>(&self, path: P) -> Result<String>

读取为 HTML 表格
Source§

fn read_text<P: AsRef<Path>>(&self, path: P) -> Result<String>

读取为纯文本
Source§

fn read_directory<P: AsRef<Path>>( &self, path: P, options: &ReadOptions, ) -> Result<Vec<FormattedOutput>>

递归读取目录
Source§

impl GeoOperations for ExifTool

Source§

fn get_gps<P: AsRef<Path>>(&self, path: P) -> Result<Option<GpsCoordinate>>

获取文件的 GPS 坐标
Source§

fn set_gps<P: AsRef<Path>>(&self, path: P, coord: &GpsCoordinate) -> Result<()>

设置文件的 GPS 坐标
Source§

fn remove_gps<P: AsRef<Path>>(&self, path: P) -> Result<()>

删除 GPS 信息
Source§

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<()>

生成 GPS 轨迹文件
Source§

fn reverse_geocode<P: AsRef<Path>>( &self, coord: &GpsCoordinate, ) -> Result<GeocodeResult>

反向地理编码
Source§

impl HexDumpOperations for ExifTool

Source§

fn hex_dump<P: AsRef<Path>>( &self, path: P, options: &HexDumpOptions, ) -> Result<String>

获取文件的十六进制转储
Source§

fn hex_dump_tag<P: AsRef<Path>>(&self, path: P, tag: TagId) -> Result<String>

获取特定标签的十六进制值
Source§

impl StreamingOperations for ExifTool

Source§

fn process_streaming<P, F, R>( &self, path: P, options: &StreamOptions, processor: F, ) -> Result<R>
where P: AsRef<Path>, F: FnMut(&mut dyn Read) -> Result<R>,

流式处理大文件
Source§

fn process_batch_with_progress<P, F>( &self, paths: &[P], options: &StreamOptions, processor: F, ) -> Vec<Result<()>>

批量处理带进度回调
Source§

impl VerboseOperations for ExifTool

Source§

fn verbose_dump<P: AsRef<Path>>( &self, path: P, options: &VerboseOptions, ) -> Result<String>

获取详细输出

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more