0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

关于apng png gif imagemagick的那些处理

Last updated at Posted at 2022-11-26

静态PNG图片

去除png图片的透明背景(转换为白色)

magick mogrify -format png -alpha remove *.png

注:mogrify为覆盖(但后缀名不同仍然无法覆盖),convert为输出新文件

动态PNG图片转换为GIF

一键:

 magick.exe convert -format gif -set dispose Previous -layers coalesce -loop 0 apng:origin.png test.gif

拆解:

  • -formart gif:转换为gif格式
  • -set dispose Previous 重置dispose选项,并设置为“Previoius”模式,详细看这里ImageMagick (legacy) – 命令行选项
  • -layers coalesce 让gif变成类似胶片的模式,虽然没看懂但是……加了这个之后突然就好了,说明在这里 ImageMagick (legacy) – 命令行选项
  • -loop 0 :修改循环次数为无限
  • apng: :动态png强制以apng格式读取,否则将认作静态png处理

批量处理

本来想用shell,后来发现想要做的循环和判断几乎可以在一行里解决。那么先上一行流。

 ls ./apng |awk -F ".png" '{print $1}' |xargs -I {} magick.exe convert -format gif -set dispose Previous -layers coalesce -loop 0 apng:./apng/{}.png ./gif/{}.gif

拆解

  • ls ./apng 打印目录下文件
  • awk -F ".png" '{print $1}':以.png为分隔符切割前一步输出,并打印第一个区块(这里顺便起到了grep的作用,但是总感觉可以用ls解决……)
  • xargs -I {}:将前文输出内容多次使用 例如后面 ./apng/{}.png ./gif/{}.gif,就使用了文件名两次,来分别制定原文件名和输出文件名。

参考したページ

ImageMagick – Command-line Tools: Mogrify

提取与优化Line贴图的正确姿势 - 哔哩哔哩

Can I use ImageMagick to convert Animated PNG (APNG) into animated WEBP format? · Discussion #3846 · ImageMagick/ImageMagick

ImageMagick – Image Formats

为什么有的GIF图片只会播放一遍,而有的会重复播放?关于gif你想知道的一切! - 轻狂书生han - 博客园

Animation Basics -- IM v6 Examples

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?