带PNG数据的ICO文件
查看一些具有PNG数据的ICO文件,而不是ICO,我正在尝试创建同样的ICO。示例:
$ identify sample.ico
sample.ico[0] PNG 32x32 32x32+0+0 8-bit sRGB 884B 0.000u 0:00.000
sample.ico[1] PNG 16x16 16x16+0+0 8-bit sRGB 884B 0.000u 0:00.000
$ file sample.ico
sample.ico: MS Windows icon resource - 2 icons,
32x32, 16 colors withPNG image data, 32 x 32, 8-bit/color RGBA, non-interlaced, 4 bits/pixel,
16x16, 16 colors withPNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced, 4 bits/pixel
播放,我发现我可以做类似的事情来获得png ico:
$ convert icon-32x32.png png8:test1.ico
$ identify test1.ico
test1.ico PNG 32x32 32x32+0+0 8-bit sRGB 934B 0.000u 0:00.000
但是,如果我使用多个输入文件,我会得到多个输出文件:
$ convert icon-16x16.png icon-32x32.png png8:test2.ico
$ ls -1 test2*
test2-0.ico
test2-1.ico
不以png8:
将数据转换为ICO。
$ convert icon-16x16.png icon-32x32.png test3.ico
$ identify test3.ico
test3.ico[0] ICO 16x16 16x16+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
test3.ico[1] ICO 32x32 32x32+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
如果该文件对于ICO格式来说太大,则PNG是“保留”的:
$ convert ../icon-32x32.png ../icon-512x512.png test4.ico
$ identify test4.ico
test3.ico[0] ICO 32x32 32x32+0+0 32-bit sRGB 53.4KB 0.000u 0:00.000
test3.ico[1] PNG 512x512 512x512+0+0 8-bit sRGB 53.4KB 0.000u 0:00.000
如何使用ImageMagick中所有尺寸的PNG数据创建一个ICO文件?
Looking at some ICO files that have PNG data instead of ICO and I am trying to create the same. Example:
$ identify sample.ico
sample.ico[0] PNG 32x32 32x32+0+0 8-bit sRGB 884B 0.000u 0:00.000
sample.ico[1] PNG 16x16 16x16+0+0 8-bit sRGB 884B 0.000u 0:00.000
$ file sample.ico
sample.ico: MS Windows icon resource - 2 icons,
32x32, 16 colors withPNG image data, 32 x 32, 8-bit/color RGBA, non-interlaced, 4 bits/pixel,
16x16, 16 colors withPNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced, 4 bits/pixel
Playing around I have found I can do something like this to get PNG ICO:
$ convert icon-32x32.png png8:test1.ico
$ identify test1.ico
test1.ico PNG 32x32 32x32+0+0 8-bit sRGB 934B 0.000u 0:00.000
But if I use multiple input files I get multiple output files:
$ convert icon-16x16.png icon-32x32.png png8:test2.ico
$ ls -1 test2*
test2-0.ico
test2-1.ico
Not prefixing with png8:
converts the data to ICO.
$ convert icon-16x16.png icon-32x32.png test3.ico
$ identify test3.ico
test3.ico[0] ICO 16x16 16x16+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
test3.ico[1] ICO 32x32 32x32+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
If the file is too big for the ICO format, the PNG is "preserved":
$ convert ../icon-32x32.png ../icon-512x512.png test4.ico
$ identify test4.ico
test3.ico[0] ICO 32x32 32x32+0+0 32-bit sRGB 53.4KB 0.000u 0:00.000
test3.ico[1] PNG 512x512 512x512+0+0 8-bit sRGB 53.4KB 0.000u 0:00.000
How can I create a ICO file with PNG data for all sizes in ImageMagick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尚未找到具有ImageMagick的任何解决方案,但可以使用GIMP。
只需为每个大小创建一个图层,然后将其导出为
file.ico
。在出现的选项对话中检查
compress(png)
。一个人还可以设置
bpp
等。对于较低的分辨率,可以使用:4BPP,1位alpha,16个插条调色板
4BPP,1-- BIT Alpha,16个插槽调色板
8BPP,1位Alpha,256插槽调色板
...
Have not found any solution with imagemagick but one can use GIMP.
Just create a layer for each size and export as
file.ico
.In options dialogue that appear check off
Compress (PNG)
.One can also set
bpp
etc. For lower resolutions one can use for example:4bpp, 1-bit alpha, 16-slots palette
4bpp, 1-bit alpha, 16-slots palette
8bpp, 1-bit alpha, 256-slots palette
...
实际上,您可以仅使用Windows Direct2D API进行从SVG到ICO或SVG或PNG到ICO的整个转换,而无需任何第三方工具。
我今天构建了该工具。 ICO格式存在一些奇怪的问题,因为它实际上可以通过设置bmpheader.bheight * -1」和PNG 「MSFT博客链接来支持旋转「「直接直接了解旋转。但是许多工具不正确地理解它。因此,最好将直接从SVG或PNG转换为更严格的GUID_WICPIXELFORMAT32BPPBGRA格式,并用于
查看基础知识以
drawsvgdocument
带有comptr
comptr; DC;
实际上
从中编写ICO格式有点繁重,因为您需要构建正确的
icondir
和一个或多个icondirentry
每个部分bitmapinfoheader
您要发射到ICO文件中。总而言之,发现真正在所有工具中使用的正确格式与某些工具都可以使用。我花了大约4个小时的测试和实验。参见:
https://devblogs.microsoft.s.microsoft.com/oldnewthing/oldnewthing/20101022222-00/? P = 12473
PS,我的动机是能够产生SVG直接在我的PWA和本机应用程序的脚本工具中,然后在部署时间发射PNG和ICO,以在包装中大大节省两个文件尺寸,并仅使用SVG允许相当无限的主题。
You can actually do the entire conversion from SVG to ICO or SVG to PNG or PNG to ICO using ONLY Windows Direct2D APIs without needing any 3rd party tools.
I built that tool today. The ICO format has some wonky issues in that it can actually support rotation 「by setting bmpHeader.biHeight * -1」, and PNG 「MSFT blog link below」 directly but many tools don't understand it properly. So it is best to translate from SVG or PNG directly to a stricter GUID_WICPixelFormat32bppPBGRA format and use
To see the basics look for
DrawSvgDocument
withComPtr<ID2D1DeviceContext5> dc;
and
Actually writing an ICO format from that is a bit more heavy lifting because you need to build the CORRECT
ICONDIR
and one or moreICONDIRENTRY
sections for eachBITMAPINFOHEADER
entry you want to emit into your ICO file. All in all it is a bit of a one time PITA to discover the correct formats that actually work in all tools vs just some tools. It took me about 4 hours of testing and experimenting.See also:
https://devblogs.microsoft.com/oldnewthing/20101022-00/?p=12473
p.s., My motivation was to be able to generate SVGs directly in my scripting tool for PWAs and native apps, and then emit PNGs and ICOs at deployment time to save significantly on both file-size in a package and allow fairly infinite theming using only SVGs.