fix: iPhone 图片格式转换 jpg

检查到文件已经存在则跳过转换流程,优化代码
This commit is contained in:
奇趣保罗 2024-04-23 14:17:38 +08:00
parent 9737d1e78b
commit 5488c799cc
1 changed files with 11 additions and 10 deletions

21
iphone-photo-format.sh Normal file → Executable file
View File

@ -8,21 +8,22 @@ mkdir -p output
# 遍历当前文件夹下的所有 heic 和 png 文件
for file in *.{HEIC,heic,PNG,png,JPG}; do
# 跳过不该执行的文件
if [[ "$file" == "." || "$file" == ".." || "$file" == "*.heic" || "$file" == "*.png" || "$file" == "*.jpg" ]]; then
# 跳过不存在的文件
if [[ ! -f "$file" ]]; then
continue
fi
# 存储图片名到变量
# 获取图片名并创建新的文件名
filename=$(basename "$file")
extension="${filename##*.}"
new_extension="jpg"
new_filename="${filename%.*}.$new_extension"
# 将文件名中的后缀替换为 .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 [[ -e "output/$new_filename" ]]; then
echo "Skipping existing file: output/$new_filename"
continue
fi
if [[ "${filename##*.}" == "png" || "${filename##*.}" == "PNG" ]]; then
# 使用 ImageMagick 直接处理 PNG 图片