Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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());               
        }
    });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: -d {followingjson} curl 
Javascript :: parallaxprovider 
Javascript :: destructure object exlude one 
Javascript :: find cypress running in ci or open mode 
Javascript :: how to add make touchstart passive in jquery "3.4.0" 
Javascript :: riverSizes javascript 
Javascript :: es6 1 to one 
Javascript :: svm with foreach and doMC 
Javascript :: react cleanup meas 
Javascript :: js swap 
Javascript :: getElementbyhref 
Javascript :: dom javascript cheat sheet 
Javascript :: sequelize body 
Javascript :: get the latest git commit SHA-1 in a repository js 
Javascript :: agregar año en javascript 
Javascript :: recorrer letra por letra js 
Javascript :: snippets chrome devtools debugging 
Javascript :: How to make move able triangle in canvas js 
Javascript :: how to autoclose paranthesis in javascript input 
Javascript :: asp.net run javascript on page load 
Javascript :: @webfilter objectify where we can use 
Javascript :: how to pass an id to the route of a seprate file react 
Javascript :: liquid - array item accessing 
Javascript :: gatsby markdown link blank 
Javascript :: javascript accessing this in callback 
Javascript :: convert from python to javascript online 
Javascript :: Set initial state on react-native-router-flex 
Javascript :: double and operator javascript 
Javascript :: javamailsender schedular 
Javascript :: browserify call bundeled function 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =