HTML | canvas scale() Method
The HTML canvas scale() Method is used to scale the current drawing into smaller or larger size. After scaling the drawing, all the feature of drawing scaled. It will have to define before the canvas.
Syntax:
context.scale( scalewidth, scaleheight )
Parameter Values:
- scalewidth: It scale the width of current drawing, (1=100%, 0.5=50%, 2=200%, and so on).
- scaleheight: It scale the height of current drawing, (1=100%, 0.5=50%, 2=200%, and so on)
Example 1: This example uses canvas scale() Method to increase the drawing size.
<!DOCTYPE html> <html> <head> <title> HTML canvas scale() Method </title> </head> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <canvas id="GFG" width="500" height="300"> </canvas> <script> var x = document.getElementById("GFG"); var contex = x.getContext("2d"); contex.strokeRect(10, 10, 150, 100); contex.scale(2, 2); contex.strokeRect(50, 50, 150, 100); </script> <center> </body> </html> |
Output:

Example 2: This example uses canvas scale() Method to decrease the drawing size.
<!DOCTYPE html> <html> <head> <title> HTML canvas scale() Method </title> </head> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <canvas id="GFG" width="500" height="300"> </canvas> <script> var x = document.getElementById("GFG"); var contex = x.getContext("2d"); contex.strokeRect(10, 10, 150, 100); contex.scale(0.5, 0.5); contex.strokeRect(50, 50, 150, 100); </script> </center> </body> </html> |
Output:

Supported Browsers: The browser supported by HTML canvas scale() Method are listed below:
- Google Chrome
- Internet Explorer 9.0 or above
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | canvas arc() Method
- HTML | canvas fillRect() Method
- HTML | canvas putImageData() Method
- HTML | canvas transform() Method
- HTML | canvas clearRect() Method
- HTML | canvas strokeRect() Method
- HTML | canvas translate() Method
- HTML | canvas isPointInPath() Method
- HTML | canvas createPattern() Method
- HTML | canvas stroke() Method
- HTML | canvas setTransform() Method
- HTML | canvas fill() Method
- HTML | canvas beginPath() Method
- HTML | canvas closePath() Method
- HTML | canvas moveTo() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


