From 2f743f09151bd24d6afdc9543791265ff8d7f9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Wed, 22 Jan 2025 14:53:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 分别是给网站项目截图用和相机格式转换(虽然颜色会有问题 --- all-hif-to-jpg.sh | 40 +++++++++++++++++++++++++++++++++++++ all-png-to-webp.sh | 34 +++++++++++++++++++++++++++++++ iphone-sony-photo-format.sh | 4 ++-- 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 all-hif-to-jpg.sh create mode 100755 all-png-to-webp.sh diff --git a/all-hif-to-jpg.sh b/all-hif-to-jpg.sh new file mode 100755 index 0000000..46f6d5f --- /dev/null +++ b/all-hif-to-jpg.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# 检查是否提供了目录参数 +if [ "$#" -ne 1 ]; then + echo "Usage: \$0 /path/to/directory" + exit 1 +fi + +# 获取目录路径 +directory="$1" + +# 检查提供的路径是否是一个目录 +# if [ ! -d "$directory" ]; then +# echo "Error: $directory is not a valid directory." +# exit 1 +# fi + +# 切换到指定目录 +cd "$directory" || exit + +for file in *.HIF; do + # 检查文件是否存在 + if [[ -f "$file" ]]; then + # 获取不带扩展名的文件名 + filename="${file%.*}" + jpg_file="${filename}.jpg" + + # 检查对应的 .jpg 文件是否已经存在 + if [[ -f "$jpg_file" ]]; then + echo "Skipping $file, $jpg_file already exists." + continue + fi + + # 使用 magick 命令转换为 .jpg 格式 + magick "$file" -colorspace sRGB "$jpg_file" + echo "Converted $file to $jpg_file" + else + echo "No .hif files found in the directory: $directory." + fi +done \ No newline at end of file diff --git a/all-png-to-webp.sh b/all-png-to-webp.sh new file mode 100755 index 0000000..7259c55 --- /dev/null +++ b/all-png-to-webp.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# 检查是否安装了必要的工具 +if ! command -v magick &> /dev/null; then + echo "错误: 未找到 ImageMagick,请先安装 ImageMagick" + exit 1 +fi + +if ! command -v exiftool &> /dev/null; then + echo "错误: 未找到 ExifTool,请先安装 ExifTool" + exit 1 +fi + +# 遍历当前目录下的所有 PNG 文件 +for png_file in *.png; do + # 检查文件是否存在(防止没有 png 文件时的错误) + if [ ! -f "$png_file" ]; then + echo "当前目录下没有 PNG 文件" + exit 0 + fi + + # 获取文件名(不含扩展名) + filename="${png_file%.*}" + + # 转换为 WebP 格式 + echo "正在转换: $png_file -> ${filename}.webp" + magick "$png_file" "${filename}.webp" + + # 写入作者信息 + echo "正在写入作者信息到: ${filename}.webp" + exiftool -overwrite_original -Author="奇趣保罗" "${filename}.webp" +done + +echo "所有文件处理完成!" diff --git a/iphone-sony-photo-format.sh b/iphone-sony-photo-format.sh index 149fb1c..c846d9e 100755 --- a/iphone-sony-photo-format.sh +++ b/iphone-sony-photo-format.sh @@ -6,7 +6,7 @@ mkdir -p output # 遍历当前文件夹下的所有 heic 和 png 文件 -for file in *.{HEIC,heic,PNG,png,JPG,jpg}; do +for file in *.{HEIC,heic,HEIF,heif,PNG,png,JPG,jpg}; do # 跳过不存在的文件 if [[ ! -f "$file" ]]; then @@ -54,6 +54,6 @@ for file in *.{HEIC,heic,PNG,png,JPG,jpg}; do # 使用 exiftool 抹掉图片的 gps 信息,并设置作者名称为 Paul exiftool -overwrite_original -gps:all= -artist="奇趣保罗" -CreatorTool= "output/$new_filename" - echo "\n\n" + echo '\n\n' done