在 javascript 中将 png/jpg 转换为 .ico

问题描述 投票:0回答:2

所以我想要一个从 jpg/png 生成

.ico
文件的工具。 我使用以下代码从画布生成了 jpg:

var img    = c.toDataURL("image/png");
document.write('<img src="'+img+'"/>');

取自此画布:

<canvas id="myCanvas" width="16" height="16">

所以问题是;是否可以将生成的png转换为ico?

javascript html canvas ico
2个回答
2
投票

在 Firefox 中,您可以直接从画布执行此操作:

// Make ICO files (Firefox only)
var ctx = c.getContext("2d");
ctx.arc(c.width>>1, c.height>>1, c.width>>1, 0, 6.28);
ctx.fill();

c.toBlob(function(blob) {
  console.log(blob)
}, 'image/vnd.microsoft.icon', '-moz-parse-options:format=bmp;bpp=32');
<canvas id=c width=32 height=32></canvas>

否则,要支持其他浏览器,您将必须手动构建 ico 文件。请参阅格式描述以及例如此答案了解如何做到这一点。


0
投票

从 ICO 文件中提取图像:ICO 文件可以包含多个不同大小和颜色深度的图像。转换过程通常从从 ICO 文件中提取图像开始。您可以访问此网站https://thistothat.online/jpg-to-ico.

© www.soinside.com 2019 - 2024. All rights reserved.