Horje
function resizeBase64Img(base64, newWidth, newHeight) { return new Promise<string>((resolve, reject)=>{ Code Example
function resizeBase64Img(base64, newWidth, newHeight) { return new Promise((resolve, reject)=>{
/**
 * Resize a base 64 Image
 * @param {String} base64 - The base64 string (must include MIME type)
 * @param {Number} newWidth - The width of the image in pixels
 * @param {Number} newHeight - The height of the image in pixels
 */
function resizeBase64Img(base64, newWidth, newHeight) {
    return new Promise((resolve, reject)=>{
        var canvas = document.createElement("canvas");
        canvas.style.width = newWidth.toString()+"px";
        canvas.style.height = newHeight.toString()+"px";
        let context = canvas.getContext("2d");
        let img = document.createElement("img");
        img.src = base64;
        img.onload = function () {
            context.scale(newWidth/img.width,  newHeight/img.height);
            context.drawImage(img, 0, 0); 
            resolve(canvas.toDataURL());               
        }
    });
}




Javascript

Related
group by hash in jquery Code Example group by hash in jquery Code Example
angular 2 on data bound event equivalent Code Example angular 2 on data bound event equivalent Code Example
convert space to dash/hyphen javascript regex Code Example convert space to dash/hyphen javascript regex Code Example
formatting JSON online Code Example formatting JSON online Code Example
find word in javascript string Code Example find word in javascript string Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10