imagemagick:把png文件转ico(ImageMagick 6.9.10) 

一,png转ico

[lhdop@blog img]$ /usr/bin/convert -resize x128 fl.png -background transparent a3.ico

查看生成的ico

[lhdop@blog img]$ identify a3.ico
a3.ico ICO 84x128 84x128+0+0 8-bit sRGB 44606B 0.000u 0:00.000

可见生成的ico不是标准的正方形

二,截取中间正方形部分生成ico

[lhdop@blog img]$ /usr/bin/convert -resize 128x -gravity center -crop 128x128+0+0 fl.png -background transparent a4.ico

原图:

fl.png

截取中间正方形后:

a4.ico

查看生成的ico

[lhdop@blog img]$ identify a4.ico
a4.ico ICO 128x128 128x128+0+0 8-bit sRGB 67646B 0.000u 0:00.000

三,强制指定成正方形:比例会失调:

[lhdop@blog img]$ /usr/bin/convert -resize 128x128! fl.png -background transparent a5.ico

如图:

查看生成的ico:

[lhdop@blog img]$ identify a5.ico
a5.ico ICO 128x128 128x128+0+0 8-bit sRGB 67646B 0.000u 0:00.000

说明:刘宏缔的架构森林—专注it技术的博客,
网址:https://imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/06/01/imagemagick-ba-png-wen-jian-zhuan-ico-imagemagick-6-9-10/
代码: https://github.com/liuhongdi/https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com

四,指定包含多个尺寸的ico文件

[lhdop@blog img]$ convert -background transparent fl.png -define icon:auto-resize=16,24,32,48,64,72,96,128,256 a6.ico  

查看生成的ico:

[lhdop@blog img]$ identify a6.ico
a6.ico[0] ICO 16x16 16x16+0+0 8-bit sRGB 0.000u 0:00.002
a6.ico[1] ICO 24x24 24x24+0+0 8-bit sRGB 0.000u 0:00.002
a6.ico[2] ICO 32x32 32x32+0+0 8-bit sRGB 0.000u 0:00.002
a6.ico[3] ICO 48x48 48x48+0+0 8-bit sRGB 0.000u 0:00.002
a6.ico[4] ICO 64x64 64x64+0+0 8-bit sRGB 0.000u 0:00.002
a6.ico[5] ICO 72x72 72x72+0+0 8-bit sRGB 0.000u 0:00.002
a6.ico[6] ICO 96x96 96x96+0+0 8-bit sRGB 0.000u 0:00.001
a6.ico[7] ICO 128x128 128x128+0+0 8-bit sRGB 0.000u 0:00.001
a6.ico[8] PNG 256x256 256x256+0+0 8-bit sRGB 197772B 0.000u 0:00.000

可以看到共有我们指定的9个size

五,查看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
QR:imagemagick:把png文件转ico(ImageMagick 6.9.10) 

发表回复