最近拍照片比较多,发博客和小红书等,需要压缩一下照片。压缩之后保存到自己的 immich 服务当中,浏览照片时镜头相机拍摄参数等信息没了。
我一直在用 squoosh 在线压缩或者使用命令行批量压缩,但是压缩后丢失了镜头相机等元数据。看了一下 squoosh 官方的某个 issue ,应该不会做这个功能了
试了一下 tinypng.com ,在线使用会完全抹掉这些信息。也试了一下 api,
只会保留拍摄时间,相机和镜头相关信息没了……
有没有一种图片压缩服务,能够保留照片的 exif 镜头相机信息?
感谢大家提意见。已经用 exiftool 搞定了(这么好用的的东西现在才知道!
我是在一个 alpine 容器里操作的。以前写过这篇文章 [可能是]最好的压缩图片程序,使用 squoosh-cli 批量压缩图片 https://hellodk.cn/post/1141
使用 alpine 安装 exiftool
, apk add exiftool
,
squoosh-cli 批量压缩
squoosh-cli --mozjpeg '{"quality":60,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}' \ -d output \ -s -dk-compressed \ *.jpg
再调用一个 shell 脚本即可将原本文件的 exif info 写入 squoosh 压缩后的文件当中。squoosh压缩后文件占用 163KB,写入 exif 信息之后文件占用变成 172KB,可以接受。
shell 内容如下
#!/bin/sh # 检查是否提供了必要的参数 if [ -z "$1" ] || [ -z "$2" ]; then echo "Usage: $0 <input_dir> <output_dir>" exit 1 fi # 从命令行参数中读取输入目录和输出目录 input_dir="$1" output_dir="$2" # 检查输入目录是否存在 if [ ! -d "$input_dir" ]; then echo "Input directory '$input_dir' does not exist." exit 1 fi # 检查输出目录是否存在 if [ ! -d "$output_dir" ]; then echo "Output directory '$output_dir' does not exist, creating it." exit 1 fi # 定义原始图片目录和输出目录 input_dir="." output_dir="./output" # 遍历所有 JPG 文件 for input_file in "$input_dir"/*.jpg; do # 提取文件名,不带路径 filename=$(basename "$input_file") # 构建目标文件路径 output_file="${output_dir}/${filename%.jpg}-dk-compressed.jpg" # 检查压缩后的文件是否存在,以防万一 if [ ! -f "$output_file" ]; then echo "File $output_file does not exist, skipping..." continue fi # 复制 EXIF 元数据 exiftool -TagsFromFile "$input_file" -all:all "$output_file" # 删除生成的备份文件(-TagsFromFile 操作会创建一个备份文件) rm "${output_file}_original" done
1 flyxq 2024-07-15 10:38:46 +08:00 这玩意不是 ai 问一下就知道了吗。Python 中的 PIL 库( Pillow ) |
![]() | 2 MisakaTang 2024-07-15 10:42:56 +08:00 ![]() |
![]() | 3 tool2dx 2024-07-15 10:45:44 +08:00 你都用命令行压缩了,就是加一行代码的事情,exiftool -TagsFromFile source.jpg -all:all target.jpg |
6 NoOneNoBody 2024-07-15 10:49:41 +08:00 exiftool 赛高 |
![]() | 7 tomczhen 2024-07-15 11:09:00 +08:00 xnview 应该可以 |
![]() | 8 conky 2024-07-15 11:16:02 +08:00 synology photo 会提供压缩的 jpg ,保留了这些信息 |
![]() | 9 jasonlu233 2024-07-15 11:26:54 +08:00 libvips |
![]() | 10 ko20 OP 谢谢大家,已经用 exiftool 搞定了,太强了。详情见附言 |
![]() | 12 chen1210 2024-07-15 11:44:10 +08:00 |
![]() | 13 ko20 OP 直接通过压缩得到保留 exif 元数据图片的压缩服务,今天发现下面这个网站可以 - GitHub https://github.com/Lymphatus/caesium-image-compressor - 在线尝试 https://caesium.app/ --- 当然我现在的工作流是更适合我自己的。squoosh 压缩有比较大的自定义权限。 |