Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Last active October 21, 2025 09:23
Show Gist options
  • Select an option

  • Save iqiancheng/970ec0aed97a7491ea71c07e4e54c3c0 to your computer and use it in GitHub Desktop.

Select an option

Save iqiancheng/970ec0aed97a7491ea71c07e4e54c3c0 to your computer and use it in GitHub Desktop.
把当前目录下所有 PNG 转成 75% 质量的 JPG on macOS magick CLI
# 把当前目录下所有 PNG 转成 75% 质量的 JPG,并在原文件名后加 _quality75.jpg
find . -maxdepth 1 -type f -iname '*.png' -print0 | xargs -0 -I{} sh -c 'magick "$1" -background white -alpha remove -alpha off -strip -quality 85 "${1%.png}_q85.jpg"' _ {}

说明 • 使用 -background white -alpha remove -alpha off 处理透明背景,避免黑底;如需其他颜色,把 white 改成你想要的颜色值(如 “#1e1e1e”)。 • -strip 会移除元数据以进一步减小体积;若需保留 ICC/EXIF,删除 -strip。 • 质量 75 是偏中高的网页常用档位;需要更高或更小体积,调节 -quality。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment