2025-01-03 19:07:17 +08:00
|
|
|
|
# Image EXIF Reader
|
|
|
|
|
|
|
|
|
|
一个简单的图片 EXIF 数据读取器,支持读取 JPEG、TIFF 等格式图片的 EXIF 元数据。
|
|
|
|
|
|
|
|
|
|
## 功能特点
|
|
|
|
|
|
|
|
|
|
- 支持多种图片格式:JPEG/JPG、TIFF、HEIC/HEIF、PNG、WebP
|
|
|
|
|
- 读取常见 EXIF 数据:相机信息、拍摄参数、镜头信息等
|
|
|
|
|
- 简单易用的 API
|
|
|
|
|
- 支持浏览器直接使用
|
|
|
|
|
- 轻量级,无依赖
|
|
|
|
|
|
|
|
|
|
## 快速开始
|
|
|
|
|
|
|
|
|
|
### 1. 直接使用
|
|
|
|
|
|
|
|
|
|
html
|
|
|
|
|
|
|
|
|
|
<!-- 引入插件 -->
|
|
|
|
|
<script src="dist/imageExifReader.min.js"></script>
|
|
|
|
|
<!-- HTML -->
|
|
|
|
|
<input type="file" id="imageInput" accept="image/jpeg,image/jpg">
|
|
|
|
|
<div id="exifData"></div>
|
|
|
|
|
<script>
|
|
|
|
|
// 初始化读取器
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
### 2. NPM 安装
|
|
|
|
|
|
|
|
|
|
bash
|
|
|
|
|
|
|
|
|
|
npm install image-exif-reader
|
|
|
|
|
|
|
|
|
|
javascript
|
|
|
|
|
|
|
|
|
|
import ImageExifReader from 'image-exif-reader';
|
|
|
|
|
|
|
|
|
|
const reader = new ImageExifReader();
|
|
|
|
|
function handleImageUpload(file) {
|
|
|
|
|
reader.readExifData(file, (error, exifData) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error('读取失败:', error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log('EXIF 数据:', exifData);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## API 文档
|
|
|
|
|
|
|
|
|
|
### ImageExifReader
|
|
|
|
|
|
|
|
|
|
#### readExifData(file, callback)
|
|
|
|
|
|
|
|
|
|
读取图片的 EXIF 数据。
|
|
|
|
|
|
|
|
|
|
参数:
|
|
|
|
|
|
|
|
|
|
- file: File - 图片文件对象
|
|
|
|
|
- callback: Function(error, exifData)
|
|
|
|
|
- error: Error | null - 错误信息
|
|
|
|
|
- exifData: Object - EXIF 数据对象
|
|
|
|
|
|
|
|
|
|
返回数据示例:
|
|
|
|
|
|
|
|
|
|
javascript
|
|
|
|
|
{
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## 支持的 EXIF 标签
|
|
|
|
|
|
|
|
|
|
### 基本信息
|
|
|
|
|
|
|
|
|
|
- Make: 相机制造商
|
|
|
|
|
- Model: 相机型号
|
|
|
|
|
- DateTime: 拍摄时间
|
|
|
|
|
- Software: 软件信息
|
|
|
|
|
|
|
|
|
|
### 拍摄参数
|
|
|
|
|
|
|
|
|
|
- ExposureTime: 曝光时间
|
|
|
|
|
- FNumber: 光圈值
|
|
|
|
|
- ISOSpeedRatings: ISO 感光度
|
|
|
|
|
- FocalLength: 焦距
|
|
|
|
|
- ExposureMode: 曝光模式
|
|
|
|
|
- WhiteBalance: 白平衡
|
|
|
|
|
|
|
|
|
|
### 镜头信息
|
|
|
|
|
|
|
|
|
|
- LensModel: 镜头型号
|
|
|
|
|
- LensSerialNumber: 镜头序列号
|
|
|
|
|
- FocalLengthIn35mmFilm: 35mm 等效焦距
|
|
|
|
|
|
|
|
|
|
### 图像信息
|
|
|
|
|
|
|
|
|
|
- XResolution: X 轴分辨率
|
|
|
|
|
- YResolution: Y 轴分辨率
|
|
|
|
|
- ResolutionUnit: 分辨率单位
|
|
|
|
|
|
|
|
|
|
## 开发
|
|
|
|
|
|
|
|
|
|
bash
|
|
|
|
|
|
|
|
|
|
安装依赖
|
|
|
|
|
npm install
|
|
|
|
|
构建项目
|
|
|
|
|
npm run build
|
|
|
|
|
运行示例
|
|
|
|
|
npm run dev
|
|
|
|
|
运行测试
|
|
|
|
|
npm test
|
|
|
|
|
|
|
|
|
|
## 示例
|
|
|
|
|
|
|
|
|
|
查看 `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
|
|
|
|
|
|
|
|
|
|
- 初始版本发布
|
|
|
|
|
- 支持 JPEG/TIFF 格式
|
|
|
|
|
- 基础 EXIF 数据读取
|