2025-01-03 19:07:17 +08:00
|
|
|
|
# Image EXIF Reader
|
|
|
|
|
|
|
|
|
|
一个简单的图片 EXIF 数据读取器,支持读取 JPEG、TIFF 等格式图片的 EXIF 元数据。
|
|
|
|
|
|
|
|
|
|
## 功能特点
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- **支持多种图片格式**:JPEG/JPG、TIFF、HEIC/HEIF、PNG、WebP。
|
|
|
|
|
- **读取常见 EXIF 数据**:相机信息、拍摄参数、镜头信息等。
|
|
|
|
|
- **简单易用的 API**。
|
|
|
|
|
- **支持浏览器直接使用**。
|
|
|
|
|
- **轻量级,无依赖**。
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
## 快速开始
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
### 直接使用
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```html
|
2025-01-03 19:07:17 +08:00
|
|
|
|
<!-- 引入插件 -->
|
|
|
|
|
<script src="dist/imageExifReader.min.js"></script>
|
|
|
|
|
<!-- HTML -->
|
2025-01-03 19:13:57 +08:00
|
|
|
|
<input type="file" id="imageInput" accept="image/jpeg,image/jpg" />
|
2025-01-03 19:07:17 +08:00
|
|
|
|
<div id="exifData"></div>
|
|
|
|
|
<script>
|
2025-01-03 19:13:57 +08:00
|
|
|
|
// 初始化读取器
|
|
|
|
|
const reader = new ImageExifReader();
|
|
|
|
|
// 处理文件选择
|
|
|
|
|
document
|
|
|
|
|
.getElementById("imageInput")
|
|
|
|
|
.addEventListener("change", function (e) {
|
|
|
|
|
const file = e.target.files[0];
|
|
|
|
|
if (!file) return;
|
|
|
|
|
reader.readExifData(file, function (error, exifData) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error("读取 EXIF 数据时出错:", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log("EXIF 数据:", exifData);
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-01-03 19:07:17 +08:00
|
|
|
|
</script>
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
### NPM 安装
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```bash
|
2025-01-03 19:07:17 +08:00
|
|
|
|
npm install image-exif-reader
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```javascript
|
|
|
|
|
import ImageExifReader from "image-exif-reader";
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
const reader = new ImageExifReader();
|
|
|
|
|
function handleImageUpload(file) {
|
2025-01-03 19:13:57 +08:00
|
|
|
|
reader.readExifData(file, (error, exifData) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error("读取失败:", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log("EXIF 数据:", exifData);
|
|
|
|
|
});
|
2025-01-03 19:07:17 +08:00
|
|
|
|
}
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
## API 文档
|
|
|
|
|
|
|
|
|
|
### ImageExifReader
|
|
|
|
|
|
|
|
|
|
#### readExifData(file, callback)
|
|
|
|
|
|
|
|
|
|
读取图片的 EXIF 数据。
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
**参数**:
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- **file**:File - 图片文件对象。
|
|
|
|
|
- **callback**:Function(error, exifData)
|
|
|
|
|
- **error**:Error | null - 错误信息。
|
|
|
|
|
- **exifData**:Object - EXIF 数据对象。
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
**返回数据示例**:
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```javascript
|
2025-01-03 19:07:17 +08:00
|
|
|
|
{
|
2025-01-03 19:13:57 +08:00
|
|
|
|
Make: "Panasonic",
|
|
|
|
|
Model: "DC-G9",
|
|
|
|
|
DateTime: "2022-03-26 18:20:19",
|
|
|
|
|
ExposureTime: "1/125",
|
|
|
|
|
FNumber: "f/1.7",
|
|
|
|
|
FocalLength: "25mm",
|
|
|
|
|
ISOSpeedRatings: 400,
|
|
|
|
|
LensModel: "LUMIX G 25mm F1.7"
|
2025-01-03 19:07:17 +08:00
|
|
|
|
}
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
## 支持的 EXIF 标签
|
|
|
|
|
|
|
|
|
|
### 基本信息
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- **Make**:相机制造商。
|
|
|
|
|
- **Model**:相机型号。
|
|
|
|
|
- **DateTime**:拍摄时间。
|
|
|
|
|
- **Software**:软件信息。
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
### 拍摄参数
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- **ExposureTime**:曝光时间。
|
|
|
|
|
- **FNumber**:光圈值。
|
|
|
|
|
- **ISOSpeedRatings**:ISO 感光度。
|
|
|
|
|
- **FocalLength**:焦距。
|
|
|
|
|
- **ExposureMode**:曝光模式。
|
|
|
|
|
- **WhiteBalance**:白平衡。
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
### 镜头信息
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- **LensModel**:镜头型号。
|
|
|
|
|
- **LensSerialNumber**:镜头序列号。
|
|
|
|
|
- **FocalLengthIn35mmFilm**:35mm 等效焦距。
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
### 图像信息
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- **XResolution**:X 轴分辨率。
|
|
|
|
|
- **YResolution**:Y 轴分辨率。
|
|
|
|
|
- **ResolutionUnit**:分辨率单位。
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
## 开发
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```bash
|
|
|
|
|
# 安装依赖
|
2025-01-03 19:07:17 +08:00
|
|
|
|
npm install
|
2025-01-03 19:13:57 +08:00
|
|
|
|
# 构建项目
|
2025-01-03 19:07:17 +08:00
|
|
|
|
npm run build
|
2025-01-03 19:13:57 +08:00
|
|
|
|
# 运行示例
|
2025-01-03 19:07:17 +08:00
|
|
|
|
npm run dev
|
2025-01-03 19:13:57 +08:00
|
|
|
|
# 运行测试
|
2025-01-03 19:07:17 +08:00
|
|
|
|
npm test
|
2025-01-03 19:13:57 +08:00
|
|
|
|
```
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
## 示例
|
|
|
|
|
|
|
|
|
|
查看 `examples` 目录中的完整示例代码。
|
|
|
|
|
|
|
|
|
|
## 浏览器兼容性
|
|
|
|
|
|
|
|
|
|
- Chrome 50+
|
|
|
|
|
- Firefox 50+
|
|
|
|
|
- Safari 11+
|
|
|
|
|
- Edge 18+
|
|
|
|
|
|
|
|
|
|
## 许可证
|
|
|
|
|
|
|
|
|
|
MIT
|
|
|
|
|
|
|
|
|
|
## 作者
|
|
|
|
|
|
2025-01-03 19:12:01 +08:00
|
|
|
|
zhengice
|
2025-01-03 19:07:17 +08:00
|
|
|
|
|
|
|
|
|
## 贡献
|
|
|
|
|
|
|
|
|
|
欢迎提交 Issue 和 Pull Request。
|
|
|
|
|
|
|
|
|
|
## 更新日志
|
|
|
|
|
|
|
|
|
|
### 1.0.0
|
|
|
|
|
|
2025-01-03 19:13:57 +08:00
|
|
|
|
- 初始版本发布。
|
|
|
|
|
- 支持 JPEG/TIFF 格式。
|
|
|
|
|
- 基础 EXIF 数据读取。
|