一个用于从图像读取元数据的 Swift 库和 macOS 命令行工具。
此库使用 Apple 的 ImageIO 框架直接从图像访问元数据。 因此,它仅限于该框架支持的图像格式和元数据标签。
注意:它仅支持读取标签值。
将该包作为依赖项添加到您的 Package.swift 文件中
let package = Package(
name: "Foo",
// name, platforms, products, etc.
dependencies: [
.package(url: "https://github.com/designedbyclowns/ImageMetadata", .upToNextMinor(from: "0.1.0")),
],
targets: [
.target(name: "Foo", dependencies: [
.product(name: "ImageMetadata", package: "ImageMetadata"),
]),
]
)
用法
import ImageIO
let imageFile = try ImageFile(path: "WindowAtLeGras.jpg")
let metadata = try ImageMetadata(url: imageFile.url)
print(metadata?.description)
构建并查看文档以获取更多详细信息。
imgmd
命令行工具将提供的文件的元数据以 JSON 格式输出。 它使用 ImageTool Swift 库,主要用于帮助调试。
克隆仓库然后
make install
或者使用 Swift
swift build -c release
cp .build/release/imgmd /usr/local/bin/imgmd
imgmd --help
OVERVIEW: Extract image metadata.
Outputs metadata from the supplied image files as JSON.
USAGE: imgmd [--basic] [--exif] [--no-exif] [--gps] [--no-gps] [--iptc] [--no-iptc] [--tiff] [--no-tiff] [--debug] [<files> ...]
ARGUMENTS:
<files> Image files.
OPTIONS:
-b, --basic Basic. Don't include other metadata.
-e, --exif/--no-exif Include EXIF metadata. (default: --exif)
-g, --gps/--no-gps Include GPS metadata. (default: --gps)
-i, --iptc/--no-iptc Include IPTC metadata. (default: --iptc)
-t, --tiff/--no-tiff Include TIFF metadata. (default: --tiff)
-d, --debug Show the raw metadata.
-h, --help Show help information.
```sh
Example:
```sh
imgmd ./Resources/WindowAtLeGras.jpg
结果
{
"bitDepth" : 8,
"colorModel" : "RGB",
"colorProfile" : "GIMP built-in sRGB",
"contentType" : "public.jpeg",
"dpiHeight" : 540,
"exif" : {
"colorSpace" : 1,
"componentsConfiguration" : [
1,
2,
3,
0
],
"dateTimeDigitized" : "2025-02-13T15:00:49Z",
"dateTimeOriginal" : "1826-06-01T19:52:58Z",
"flashPixVersion" : "1.0",
"offsetTime" : "-08:00",
"offsetTimeDigitized" : "-08:00",
"offsetTimeOriginal" : "+02:00",
"pixelXDimension" : 4530,
"pixelYDimension" : 3810,
"sceneCaptureType" : "Standard",
"subsecTime" : "002",
"subsecTimeDigitized" : "002",
"subsecTimeOriginal" : "002",
"version" : "2.2.1"
},
"gps" : {
"dateTime" : "2025-02-13T15:02:45Z",
"horizontalPositioningError" : 1,
"latitude" : 46.72519666666667,
"latitudeReference" : "N",
"longitude" : 4.860291666666667,
"longitudeReference" : "E"
},
"hasAlpha" : false,
"imageFile" : {
"basename" : "WindowAtLeGras",
"contentType" : "public.jpeg",
"fileSize" : "2.1 MB (2,240,988 bytes)",
"filename" : "WindowAtLeGras.jpg",
"path" : "Resources/WindowAtLeGras.jpg"
},
"iptc" : {
"byline" : [
"Joseph Nicéphore Niépce"
],
"captionAbstract" : "The earliest surviving camera photograph.",
"city" : "Saint-Loup-de-Varennes",
"copyrightNotice" : "Public Domain",
"country" : "France",
"countryCode" : "FR",
"digitalCreationDate" : "2025-02-13T15:00:49Z",
"headline" : "View from the Window at Le Gras",
"keywords" : [
"History",
"Photograhy",
"Bitumen",
"Camera Obscura",
"Heliography"
],
"objectName" : "View from the Window at Le Gras",
"provinceState" : "Bourgogne-Franche-Comté"
},
"isFloat" : false,
"isIndexed" : false,
"orientation" : "up",
"pixelHeight" : 3810,
"pixelWidth" : 4530,
"tiff" : {
"artist" : "Joseph Nicéphore Niépce",
"copyright" : "Public Domain",
"dateTime" : "2025-02-13T15:34:57Z",
"imageDescription" : "The earliest surviving camera photograph.",
"orientation" : 1,
"photometricInterpretation" : 2,
"resolutionUnit" : 2,
"software" : "Adobe Photoshop 26.3 (Macintosh)",
"xResolution" : 540,
"yResolution" : 540
}
}
可以通过在 Xcode 中选择包目标并选择 Product > Build Documentation 来查看文档。
欢迎并鼓励提出 Pull 请求!
同样欢迎错误报告、反馈和建议。
别当混蛋就行。