Skip to content

tomaszs/webp-to-jpg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

webp-to-jpg

This is a source code in pure JS to convert widely unsupported WebP format to JPG format (PNG also possible)

After execuing a website with this code and setting URL-TO-WEBP-IMAGE the webpToJpg converts image from WebP to JPG and places it inside the img. It works only in browser supporting WebP, so mainly Chrome.

<img id='a' src='URL-TO-WEBP-IMAGE' />
<script>

function webpToJpg(id) {
    var image = new Image();

    image.onload = function () {
        var canvas = document.createElement('canvas');
        canvas.width = this.naturalWidth;
        canvas.height = this.naturalHeight;
        canvas.getContext('2d').drawImage(this, 0, 0);
        document.getElementById(id).src = canvas.toDataURL('image/jpeg');
    };

    image.src = document.getElementById(id).src;
}

webpToJpg('a');

</script>

About

This is a source code in pure JS to convert widely unsupported WebP format to JPG format (PNG also possible)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published