使用 ImageMagick 批量压缩图片

MacOS 安装: brew install imagemagick 命令行: magick input.png -quality 50% output.png Bash 脚本: #!/bin/bash # Check if ImageMagick is installed if ! command -v magick &> /dev/null then echo "ImageMagick is not installed. Please install it and try again." exit 1 fi # Loop through all jpg files in the current directory for file in *.JPG do if [ -f "$file" ]; then # Compress the image magick "$file" -quality 85% "compressed_$file" echo "Compressed: $file -> compressed_$file" fi done echo "Compression complete!"

January 23, 2025

使用 ImageMagick 批量裁剪图片白边

MacOS 安装: brew install imagemagick 命令行使用: magick convert 1.png -trim 1.png Python 批量裁剪脚本: import os for filename in os.listdir("./"): if filename.endswith(".png"): # run trim command os.system(f"magick convert {filename} -trim {filename}")

January 23, 2025