Shell-Scripts/all-png-to-webp.sh

35 lines
943 B
Bash
Executable File
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
# 检查是否安装了必要的工具
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 "所有文件处理完成!"