Converting a png/jpg to .ico in javascript
Asked Answered
L

1

-2

So i want a tool that generates a .ico file from a jpg/png. I have generated the jpg from a canvas using this code:

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

Which takes from this canvas:

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

So the qustion is; is it possible to convert the generated png to a ico?

Lamori answered 17/1, 2018 at 15:36 Comment(3)
gist.github.com/twolfson/7656254 but you still need to do your homework on thatFrancis
Here is a library wich do the work github.com/egy186/icojsSilvery
@Silvery this seems to be the inverse (ICO to PNG/JPG)? The OP requested something to convert from PNG/JPG to ICO.Clef
W
2

In Firefox you can do this directly from canvas:

// 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>

otherwise, to support other browsers you will have to build the ico file manually. See format description and for example this answer on how you can do that.

Wolford answered 17/1, 2018 at 22:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.