вторник, 14 июля 2020 г.

JavaScript Console log image


function consoleLogImage (imageUrlOrBase64Data, imageSizeInPercent) {

    if (imageSizeInPercent === undefined) {imageSizeInPercent = 100;}

    var image = new Image();

    image.onload = function () {

        var style = [

            'font-size: 1px;',

            'padding: ' + (this.height / 100 * imageSizeInPercent) + 'px ' + (this.width / 100 * imageSizeInPercent) + 'px;',

            'background: url(' + imageUrlOrBase64Data + ') no-repeat;',

            'background-size: contain;'

        ].join(' ');

        console.log('%c ', style);

    };

    image.src = imageUrlOrBase64Data;

}



var imageBase64Data = (

    'data:image/png;base64,' +

    'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbG' +

    'yAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJ' +

    'cEhZcwAADsMAAA7DAcdvqGQAAAAXSURBVBhXY3wro8KA' +

    'BJigNAyQxmdgAABeXwE3yYq9egAAAABJRU5ErkJggg=='

);


consoleLogImage(imageBase64Data, 50);