From 5488c799ccf0f341b8a62da010205300bf331da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Tue, 23 Apr 2024 14:17:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20iPhone=20=E5=9B=BE=E7=89=87=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=BD=AC=E6=8D=A2=20jpg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 检查到文件已经存在则跳过转换流程,优化代码 --- iphone-photo-format.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) mode change 100644 => 100755 iphone-photo-format.sh diff --git a/iphone-photo-format.sh b/iphone-photo-format.sh old mode 100644 new mode 100755 index fd6d962..5e68da8 --- a/iphone-photo-format.sh +++ b/iphone-photo-format.sh @@ -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 图片