feat: iPhone 图片格式转换
This commit is contained in:
parent
926f2b571a
commit
7c7cd7d771
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 将 iPhone 拍摄的照片转换格式为 jpg 并处理 exif 信息
|
||||||
|
|
||||||
|
# 创建文件夹 output
|
||||||
|
mkdir -p output
|
||||||
|
|
||||||
|
# 遍历当前文件夹下的所有 heic 和 png 文件
|
||||||
|
for file in *.{HEIC,heic,PNG,png,JPG}; do
|
||||||
|
|
||||||
|
# 跳过不该执行的文件
|
||||||
|
if [[ "$file" == "." || "$file" == ".." || "$file" == "*.heic" || "$file" == "*.png" || "$file" == "*.jpg" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 存储图片名到变量
|
||||||
|
filename=$(basename "$file")
|
||||||
|
|
||||||
|
# 将文件名中的后缀替换为 .jpg
|
||||||
|
echo "$filename\n";
|
||||||
|
new_filename=${filename/.HEIC/.jpg}
|
||||||
|
new_filename=${new_filename/.heic/.jpg}
|
||||||
|
new_filename=${new_filename/.png/.jpg}
|
||||||
|
new_filename=${new_filename/.PNG/.jpg}
|
||||||
|
new_filename=${new_filename/.JPG/.jpg}
|
||||||
|
|
||||||
|
if [[ "${filename##*.}" == "png" || "${filename##*.}" == "PNG" || "${filename##*.}" == "jpg" || "${filename##*.}" == "JPG" ]]; then
|
||||||
|
# 使用 ImageMagick 直接处理 PNG 图片
|
||||||
|
magick "$file" -gravity center -quality 80 output/$new_filename
|
||||||
|
else
|
||||||
|
# 判断图片是竖屏的还是横屏的
|
||||||
|
# 使用 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
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 使用 exiftool 抹掉图片的 gps 信息,并设置作者名称为 Paul
|
||||||
|
exiftool -overwrite_original -gps:all= -artist="奇趣保罗" -CreatorTool= "output/$new_filename"
|
||||||
|
|
||||||
|
echo "\n\n"
|
||||||
|
|
||||||
|
done
|
||||||
|
|
@ -42,9 +42,6 @@ for file in *.{HEIC,heic}; do
|
||||||
|
|
||||||
echo "匹配 $new_filename 成功,id 是 $id\n"
|
echo "匹配 $new_filename 成功,id 是 $id\n"
|
||||||
|
|
||||||
# 存储图片名到变量
|
|
||||||
filename=$(basename "$file")
|
|
||||||
|
|
||||||
# 判断图片是竖屏的还是横屏的
|
# 判断图片是竖屏的还是横屏的
|
||||||
# 使用 identify 命令判断图片的宽度和高度
|
# 使用 identify 命令判断图片的宽度和高度
|
||||||
width=$(identify -format "%w" "$file")
|
width=$(identify -format "%w" "$file")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue