image - 提取保留基础 Canvas 大小 + 偏移量的 GIF 帧

标签 image imagemagick extract gif offset

我正在尝试使用 ImageMagik convert 命令提取 GIF 帧。 GIF 图像经过优化,仅覆盖动画变化(我相信他们称之为 mipmap),由于性能限制,这对于我的提取来说是理想的选择。如果我使用 -coalesce 我会失去优化,因为我在 spritesheet 中使用 GIF 帧,所以我需要按原样提取它,但是当我使用标准 convert xxx 提取它时。 gif xxx.png 动画帧的提取没有偏移,并且 Canvas 大小与基本图像 (0) 不同。

enter image description here

我需要提取所有图像以将第一帧与 GIF 元数据中保留的偏移量相匹配。我不知道如何在 ImageMagik 中实现这一点,并且想知道这是否可行?

然后,如果我让它们匹配尺寸并应用偏移,我可以轻松地将它们添加到 Sprite 表中。

非常感谢我能得到的所有帮助!谢谢。

enter image description here

专业挑战!你接受吗?! :)

最佳答案

如果您提取为 GIF,而不是 PNG,看起来没问题:

convert animated.gif frame%d.gif

identify frame*
frame0.gif GIF 307x465 307x465+0+0 8-bit sRGB 256c 61.8KB 0.000u 0:00.000
frame1.gif[1] GIF 278x372 307x465+16+61 8-bit sRGB 256c 19.9KB 0.000u 0:00.000
frame10.gif[2] GIF 278x371 307x465+17+62 8-bit sRGB 256c 17.9KB 0.000u 0:00.000
frame11.gif[3] GIF 278x370 307x465+17+63 8-bit sRGB 256c 17.4KB 0.000u 0:00.000
frame12.gif[4] GIF 275x371 307x465+20+62 8-bit sRGB 256c 17.2KB 0.000u 0:00.000
frame13.gif[5] GIF 276x370 307x465+19+63 8-bit sRGB 256c 17.9KB 0.000u 0:00.000
frame14.gif[6] GIF 275x369 307x465+19+64 8-bit sRGB 256c 16.8KB 0.000u 0:00.000

如果你想将它们覆盖到空白 Canvas 上,你可以这样做。我没有考虑太多,可能还有更简单的方法,但现在......

#!/bin/bash
# Extract individual frames
convert animated.gif frame%d.gif

# Make a blank canvas same size as original
convert -size 307x465 xc:none canvas.gif
i=0
for f in frame*; do
   geom=$(identify -format "%X%Y" $f)
   convert canvas.gif $f -geometry $geom -composite +repage g_$i.gif
   ((i++))
done

或者也许您的意思是您希望所有帧都处于正确的相对位置,但一个接一个地在单个文件中按长序列排列?

#!/bin/bash

# Extract individual frames
convert animated.gif frame%d.gif

# Make a blank canvas same size as original
convert -size 307x465 xc:none canvas.gif

# Paste individual frames onto blank canvas and append frames into long sequence
for f in frame*; do
   geom=$(identify -format "%X%Y" $f)
   convert canvas.gif $f -geometry $geom -composite +repage miff:-
done | convert - +append sequence.gif

enter image description here

关于image - 提取保留基础 Canvas 大小 + 偏移量的 GIF 帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29455454/

相关文章:

node.js - 使用 node.js 和 gm 在 AWS Lambda 上为图像添加水印

c++ - 从日期和时间中提取日期

image - 如何使具有透明度的 png 在 MatLab 中显示为透明?

java - 如何将多个PNG组合成一个大的PNG文件?

php - 想象一下。将颜色更改为透明

c - 从c中的字符串中提取double

python - 使用 BeautifulSoup 提取时保留某些 HTML 标签

php - 通过 md5 比较图像如何工作?

java - 插入文档时自动调整图像

PHP ImageMagick 从 http 获取图像