Thanks for your response. I'm not sure if we're on the same page though. I hadn't tried what you described, using the toDataUrl() to convert from png to webp, so I gave it a whirl. I found that it does not work within non-webp supported browsers, such as IE and Firefox. The code below immediately goes to 'onerror' and will not draw to the canvas in IE. It will throw on the drawImage() command because the image is not properly loaded. No problems in Chrome, the 2px webp is drawn in the top left corner of the canvas.
I need my application to work in all browsers, and I think to achieve this I'll need to convert the webp base64 over to a png base64 before adding it to the canvas. I would think that this is exactly what webpjs does (and maybe your code too), but it does not appear do so when adding the image src via JavaScript. Is there a simple hook within webpjs (or equivalent) which would take in base64 of one image type and return base64 of another?
var canvas = document.getElementById('cvs');
var context = canvas.getContext('2d');
var webp_image = new Image();
webp_image.src = "data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA";
webp_image.onload = function() {
context.drawImage(webp_image, 0, 0);
console.log('drawing image');
};
webp_image.onerror = function()
{
console.log('webp error!');
context.drawImage(webp_image, 0, 0);
console.log("that's cool, drawing image anyways");
};
Thank you