Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Scale to fit

var image = new Image();
image.src = "imgURL";
image.onload = function(){
    scaleToFit(this);
}

function scaleToFit(img){
    // get the scale
    var scale = Math.min(canvas.width / img.width, canvas.height / img.height);
    // get the top left position of the image
    var x = (canvas.width / 2) - (img.width / 2) * scale;
    var y = (canvas.height / 2) - (img.height / 2) * scale;
    ctx.drawImage(img, x, y, img.width * scale, img.height * scale);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: List content on thee currentwdr 
Javascript :: get a nodes path alias 
Javascript :: node-fetch retry 
Javascript :: FirebaseError: Unknown field filter op. 
Javascript :: JS function examples 
Javascript :: kayengxiong promise js 
Javascript :: js two operations in ternary 
Javascript :: how to make react host on https localhost 
Javascript :: Minimum Path Sum for loop 
Javascript :: javascript custom table 
Javascript :: vite displays blank page in docker container 
Javascript :: index wise print elemnet in javascript 
Javascript :: javascript interview questions geeksforgeeks 
Javascript :: increment number in for loop javascript 
Javascript :: javascript hover event listener 
Javascript :: clear timers nodejs 
Javascript :: javascript split string into groups of n 
Javascript :: how to get value of selected radio button in javascript 
Javascript :: counting number of times a string is in another string 
Javascript :: Hexo - Execute Console Commands 
Javascript :: Plumsail To change the modal popup window size you can try injecting the CSS to the SharePoint list view page 
Javascript :: user key value within the obj js 
Javascript :: json format in .net core 
Javascript :: javascript vuelidate identical passwords only if checkbox is ticked 
Javascript :: angularjs Uncaught ReferenceError: myFunction is not defined at HTMLInputElement.onkeyup 
Javascript :: Angularjs - Deep Orderby - How to handle multiple layers of sorting 
Javascript :: How to pass React Native Component as a JSON object 
Javascript :: How to check the increase/decrease of letter input in pasting clipboard in jQuery 
Javascript :: JOLT split flat object into key/value array 
Javascript :: nextjs app wdyr 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =