base64 - Node.js quick canvas to webp [NOT SOLVED] -


if @ code webp out-performs png , jpg alot

<canvas id="canvas"></canvas> <script> var ctx = canvas.getcontext("2d"); ctx.fillstyle = "red"; ctx.fillrect(0, 0, 8, 8);  var webp = canvas.todataurl("image/webp"); // chrome only? var png  = canvas.todataurl("image/png"); var jpg  = canvas.todataurl("image/jpeg");  console.log(webp.length, webp); //  263 byte console.log(png.length, png);   // 1918 byte console.log(jpg.length, jpg);   // 1938 byte  document.body.appendchild(new image).src = webp; document.body.appendchild(new image).src = png; document.body.appendchild(new image).src = jpg; </script> 

i using node module https://github.com/automattic/node-canvas

which not support webp but, simulate canvas element

what think need wrapper around canvas do

wrapper(canvas).todataurl('image/webp'); 

as have found out on many attempts converting base64 png image webp png poor speed wise.

webp ideal size transport via websockets quickly. if webp not supported fallback png , user have slower experience.


original question:

in node.js need way convert string base64 png base64 webp.

i string because of nature of application. save these particular images convert them (there npm modules convert image 'files') server filled images these images suppose temporary , on-the-fly each user, each user gets new 100 new images when ever move page.

in node canvas canvas.todataurl('image/webp') not supported image/png

first export image/png, convert webp. there's no other way unless build nodejs own modifications (complex!). convert png image webp, use library https://github.com/lovell/sharp or https://github.com/intervox/node-webp , clean source image after converting done.

currently, chrome supports exporting canvas contents directly webp.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -