Shell-Scripts/iphone-photo-recover.sh

77 lines
2.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 恢复 iPhone 拍摄的在小窝上的部分照片
server="https://paul.ren/api"
#server="https://home.paul.xin/api"
token="eyJpZCI6MSwibmFtZSI6IlBhdWwiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE2OTY0MTE4MjgsImV4cCI6MTY5NjQzMzQyOH0=@qlcS89fPf/NxAXtyvw8/95arZRkpQxQ+7i9LYgiZhPc="
# 创建文件夹 output
mkdir -p output
# 遍历当前文件夹下的所有 heic 文件
for file in *.{HEIC,heic}; do
# 跳过不该执行的文件
if [[ "$file" == "." || "$file" == ".." || "$file" == "*.heic" ]]; then
continue
fi
# 存储图片名到变量
filename=$(basename "$file")
# 将文件名中的 .heic 替换为 .jpg
echo "$filename\n";
new_filename=${filename/.HEIC/.jpg}
new_filename=${new_filename/.heic/.jpg}
# 发送 GET 请求获取 JSON 数据
response=$(curl --header "paul-token: $token" -s "$server/media/get/?origin_name=$new_filename")
# 提取 id
id=$(echo "$response" | jq -r '.data.id')
# 如果没有 id则跳过当前循环
if [ -z "$id" ]; then
echo "匹配 $new_filename 失败\n"
continue
elif [[ "$id" == "null" ]]; then
echo "匹配 $new_filename 失败\n"
continue
fi
echo "匹配 $new_filename 成功id 是 $id\n"
# 存储图片名到变量
filename=$(basename "$file")
# 判断图片是竖屏的还是横屏的
# 使用 identify 命令判断图片的宽度和高度
width=$(identify -format "%w" "$file")
height=$(identify -format "%h" "$file")
# 指定图片大小
if [ $width -ge $height ]; then
new_size="2000x1500"
else
new_size="1500x2000"
fi
# 使用 ImageMagick 处理图片
magick "$file" -gravity center -resize "$new_size^" -extent "$new_size" -quality 80 output/$new_filename
# 使用 exiftool 抹掉图片的 gps 信息,并设置作者名称为 Paul
#exiftool -gps:all= -artist="Paul" -overwrite_original "output/$filename"
exiftool -overwrite_original -gps:all= -artist="奇趣保罗" -CreatorTool= "output/$new_filename"
# 提交该文件给服务器
curl --location "$server/media/update" \
--header "paul-token: $token" \
--form "id=$id" \
--form "photo=@output/$new_filename" \
--form 'IGNORE_UPDATE_TIME="1"'
echo "\n\n"
done