SwiftExif

SwiftExif 是一个 Swift 的封装库,用于 libexiflibiptcdata,以便在 Linux 和 macOS 上提供 JPEG 元数据提取功能。

编写 SwiftExif 是为了方便将 Munin 图片库生成器移植到 Linux 和 macOS 上运行(之前需要 ImageIO/CoreGraphics)。

libexif 用于从图像中提取和格式化 EXIF 数据,而 libiptcdata 提取“较新”的 IPTC 标准。

需求

安装

在基于 Ubuntu/Debian 的 Linux 上

apt install -y libiptc-data libexif-dev libiptcdata0-dev

在 macOS 上使用 brew

brew install libexif libiptcdata

Swift Package Manager

将 SwiftExif 添加到你的依赖项中

dependencies: [
  .package(url: "https://github.com/kradalby/SwiftExif.git", from: "0.0.x"),
]

用法

SwiftExif 旨在提供一些简单的辅助函数,这些函数本质上将所有数据作为字典返回。

例如

import SwiftExif

// Read a JPEG file and return an Image object
// Note: current error behaviour is to return empty dictionaries, no error is thrown.
let exifImage = SwiftExif.Image(imagePath: fileURL)

// Get a [String : [String : String]] dictionary. The first dictionary has items
// from the spec e.g. 0, 1, EXIF, GPS...
// The values are returned in "human readable format".
let exifDict = exifImage.Exif()

// Get a [String : [String : String]] dictionary. The first dictionary has items
// from the spec e.g. 0, 1, EXIF, GPS...
// The values are returned in a "raw" format.
let exifRawDict = exifImage.ExifRaw()

// Get a [String : Any] dictionary.
// Most items are String, however "Keywords" are [String]
let iptcDict = exifImage.Iptc()

除了高级函数外,还可以在不同的类中使用一组低级函数。请查看代码或单元测试,以了解您可以执行的其他操作。