Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  78] [ 6]  / answers: 1 / hits: 90029  / 12 Years ago, thu, may 31, 2012, 12:00:00

I'm trying to scale an image proportionately to the canvas. I'm able to scale it with fixed width and height as so:



context.drawImage(imageObj, 0, 0, 100, 100)


But I only want to resize the width and have the height resize proportionately. Something like the following:



context.drawImage(imageObj, 0, 0, 100, auto)


I've looked everywhere I can think of and haven't seen if this is possible.


More From » canvas

 Answers
19
context.drawImage(imageObj, 0, 0, 100, 100 * imageObj.height / imageObj.width)

[#85230] Wednesday, May 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvingcarloe

Total Points: 677
Total Questions: 109
Total Answers: 96

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
irvingcarloe questions
Wed, Mar 31, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;