imagemagick: 对损坏的gif图做拆分(ImageMagick 6.9.10)
一,对正常的gif图拆分:
[lhdop@blog img2]$ identify maoshu.gif maoshu.gif[0] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[1] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[2] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[3] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[4] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[5] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[6] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[7] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[8] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[9] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[10] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[11] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[12] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[13] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[14] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[15] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[16] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[17] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[18] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[19] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[20] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[21] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[22] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[23] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[24] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[25] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[26] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[27] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[28] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.001 maoshu.gif[29] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.000 maoshu.gif[30] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.000 maoshu.gif[31] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.000 maoshu.gif[32] GIF 400x224 400x224+0+0 8-bit sRGB 256c 0.000u 0:00.000 maoshu.gif[33] GIF 400x224 400x224+0+0 8-bit sRGB 256c 1.84787MiB 0.000u 0:00.000 [lhdop@blog img2]$ convert maoshu.gif maoshu.png [lhdop@blog img2]$ ls a.jpeg maoshu-0.png maoshu-13.png maoshu-17.png maoshu-20.png maoshu-24.png maoshu-28.png maoshu-31.png maoshu-4.png maoshu-8.png yz.gif b.png maoshu-10.png maoshu-14.png maoshu-18.png maoshu-21.png maoshu-25.png maoshu-29.png maoshu-32.png maoshu-5.png maoshu-9.png dog49.png maoshu-11.png maoshu-15.png maoshu-19.png maoshu-22.png maoshu-26.png maoshu-2.png maoshu-33.png maoshu-6.png maoshu.gif dog.gif maoshu-12.png maoshu-16.png maoshu-1.png maoshu-23.png maoshu-27.png maoshu-30.png maoshu-3.png maoshu-7.png red.png
说明:对图片做identify时没有报错表示图片没有损坏
说明:convert时会用gif文件名加-帧数做为文件名
gif图:
提取的第9帧
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/06/03/imagemagick-dui-sun-huai-de-gif-tu-zuo-chai-fen-imagemagick/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,处理损坏的gif
1,convert时报错
[lhdop@blog img2]$ convert dog.gif dog.png convert: corrupt image `dog.gif' @ error/gif.c/DecodeImage/513. convert: corrupt image `dog.gif' @ error/gif.c/ReadGIFImage/1389. convert: no images defined `dog.png' @ error/convert.c/ConvertImageCommand/3226.
用identify查看:
[lhdop@blog img2]$ identify dog.gif dog.gif[0] GIF 250x250 250x250+0+0 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[1] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[2] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[3] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[4] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[5] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[6] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[7] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[8] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[9] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[10] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[11] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[12] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[13] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[14] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[15] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[16] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[17] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[18] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[19] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[20] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[21] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[22] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[23] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[24] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[25] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[26] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[27] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[28] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[29] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[30] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[31] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[32] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[33] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[34] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[35] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[36] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[37] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[38] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[39] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[40] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[41] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[42] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[43] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[44] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[45] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[46] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[47] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[48] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[49] GIF 248x248 250x250+1+1 8-bit sRGB 32c 0.000u 0:00.002 dog.gif[50] GIF 248x248 250x250+1+1 8-bit sRGB 32c 901120B 0.000u 0:00.002 identify: corrupt image `dog.gif' @ error/gif.c/PingGIFImage/965.
用identify查看时有corrupt报错提示
2,解决:
可以逐帧提取:
[lhdop@blog img2]$ convert dog.gif[49] dog-49.png [lhdop@blog img2]$ ls a.jpeg b.png dog-49.png dog49.png dog.gif maoshu.gif red.png yz.gif [lhdop@blog img2]$ convert dog.gif[50] dog-50.png convert: corrupt image `dog.gif' @ error/gif.c/DecodeImage/513. convert: corrupt image `dog.gif' @ error/gif.c/ReadGIFImage/1389. convert: no images defined `dog-50.png' @ error/convert.c/ConvertImageCommand/3226.
3,例子中用到gif图:
提取的第49帧
三,查看imagemagick的版本:
[lhdop@blog img]$ convert -version Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13 https://imagemagick.org Copyright: © 1999-2020 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php Features: Cipher DPC Modules OpenMP(4.5) Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib