{"id":9287,"date":"2022-10-06T04:34:04","date_gmt":"2022-10-06T04:34:04","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=9287"},"modified":"2022-10-06T04:34:04","modified_gmt":"2022-10-06T04:34:04","slug":"canvas-reference","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/10\/06\/canvas-reference\/","title":{"rendered":"Canvas Reference"},"content":{"rendered":"\n<p>The HTML5\u00a0&lt;canvas>\u00a0element is used for drawing graphics via scripting (commonly\u00a0JavaScript). But the &lt;canvas> element does not have drawing opportunities on its own. To draw the graphics, you must use a script because the &lt;canvas> element is only a container for graphics.<\/p>\n\n\n\n<p>The getContext() method returns an object which presents properties and methods for drawing on the canvas.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"colors-styles-and-shadows-2\">Colors, Styles, and Shadows<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>fillStyle<\/td><td>Sets or returns the color, gradient, or pattern used to fill the shapes.<\/td><\/tr><tr><td>strokeStyle<\/td><td>Sets or returns the color, gradient, or pattern used for the lines around the shapes.<\/td><\/tr><tr><td>shadowColor<\/td><td>Sets or returns the color of the shadows.<\/td><\/tr><tr><td>shadowBlur<\/td><td>Sets or returns the blur level of the shadows.<\/td><\/tr><tr><td>shadowOffsetX<\/td><td>Sets or returns the x offset of the shadow.<\/td><\/tr><tr><td>shadowOffsetY<\/td><td>Sets or returns the y offset of the shadow.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>createLinearGradient()<\/td><td>Creates a linear gradient for using on the canvas content.<\/td><\/tr><tr><td>createPattern()<\/td><td>Repeats a particular element in the specified direction.<\/td><\/tr><tr><td>createRadialGradient()<\/td><td>Creates a circular\/radial gradient for using on the canvas content.<\/td><\/tr><tr><td>addColorStop()<\/td><td>Defines colors and stop positions in the gradient object.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"line-styles-4\">Line Styles<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>lineCap<\/td><td>Sets or returns the style of the line\u2019s end caps.<\/td><\/tr><tr><td>lineJoin<\/td><td>Sets or returns the type of drawn corners.<\/td><\/tr><tr><td>lineWidth<\/td><td>Sets or returns the width of the current line.<\/td><\/tr><tr><td>miterLimit<\/td><td>Sets or returns the maximum miter length.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rectangles-6\">Rectangles<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>rect()<\/td><td>Creates rectangles.<\/td><\/tr><tr><td>fillRect()<\/td><td>Draws filled rectangles.<\/td><\/tr><tr><td>strokeRect()<\/td><td>Draws rectangular outlines.<\/td><\/tr><tr><td>clearRect()<\/td><td>Clears the specified pixels within a particular rectangle.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"paths-8\">Paths<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>fill()<\/td><td>Fills the path to the canvas.<\/td><\/tr><tr><td>stroke()<\/td><td>Draws the defined path.<\/td><\/tr><tr><td>beginPath()<\/td><td>Begins a new path or resets the current path.<\/td><\/tr><tr><td>moveTo()<\/td><td>Moves the path to the defined point in the canvas without drawing a line.<\/td><\/tr><tr><td>closePath()<\/td><td>Adds a path from the current point back to the start point.<\/td><\/tr><tr><td>lineTo()<\/td><td>Adds a line to the current sub-path.<\/td><\/tr><tr><td>clip()<\/td><td>Restricts the drawing to a particular area.<\/td><\/tr><tr><td>quadraticCurveTo()<\/td><td>Adds a quadratic B\u00e9zier curve.<\/td><\/tr><tr><td>bezierCurveTo()<\/td><td>Adds a cubic B\u00e9zier curve.<\/td><\/tr><tr><td>arc()<\/td><td>Adds an arc\/curve for creating circles or parts of circles.<\/td><\/tr><tr><td>arcTo()<\/td><td>Adds an arc\/curve between two tangents.<\/td><\/tr><tr><td>isPointInPath()<\/td><td>Defines whether the specified point is in the current path, or not.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"transformations-10\">Transformations<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>scale()<\/td><td>Scales up or scales down the current drawing.<\/td><\/tr><tr><td>rotate()<\/td><td>Rotates the current drawing.<\/td><\/tr><tr><td>translate()<\/td><td>Adjusts the coordinate system of the canvas.<\/td><\/tr><tr><td>transform()<\/td><td>Applies transformation matrix to the canvas.<\/td><\/tr><tr><td>setTransform()<\/td><td>Is similar to transform(). Can be used to skew, scale, and translate the canvas.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"text-12\">Text<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>font<\/td><td>Sets the appearance of a text drawn on the canvas.<\/td><\/tr><tr><td>textAlign<\/td><td>Sets the alignment of a text drawn on the canvas.<\/td><\/tr><tr><td>textBaseline<\/td><td>Sets the vertical alignment of a text drawn on the canvas.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>fillText()<\/td><td>Adds text to the canvas.<\/td><\/tr><tr><td>strokeText()<\/td><td>Adds outlined text to the canvas.<\/td><\/tr><tr><td>measureText()<\/td><td>Measures the text width.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"image-drawing-14\">Image Drawing<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>drawImage()<\/td><td>Draws an image, video, or canvas onto the canvas.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pixel-manipulation-16\">Pixel Manipulation<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>width<\/td><td>Returns an ImageData object\u2019s width.<\/td><\/tr><tr><td>height<\/td><td>Returns an ImageData object\u2019s height.<\/td><\/tr><tr><td>data<\/td><td>Returns an object which contains image data of a specified ImageData object.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>createImageData()<\/td><td>Creates a newImageData object.<\/td><\/tr><tr><td>getImageData()<\/td><td>Returns an ImageData object which copies the pixel data for the specified rectangle.<\/td><\/tr><tr><td>putImageData()<\/td><td>Puts the image data onto the canvas from the ImageData object.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"compositing-18\">Compositing<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>globalAlpha<\/td><td>Sets or returns the current alpha\/transparency\/ value.<\/td><\/tr><tr><td>globalCompositeOperation<\/td><td>Sets or returns the type of compositing operation when a new image is drawn.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"other-20\">Other<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>save()<\/td><td>Saves the current state of a context.<\/td><\/tr><tr><td>restore()<\/td><td>Returns the path state and attributes saved previously.<\/td><\/tr><tr><td>createEvent()<\/td><td>Creates an event object.<\/td><\/tr><tr><td>getContext()<\/td><td>Returns a drawing context.<\/td><\/tr><tr><td>toDataURL()<\/td><td>Returns a data URL.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The HTML5\u00a0&lt;canvas>\u00a0element is used for drawing graphics via scripting (commonly\u00a0JavaScript). But the &lt;canvas> element does not have drawing opportunities on its own. To draw the graphics, you must use a script because the &lt;canvas> element is only a container for graphics. The getContext() method returns an object which presents properties and methods for drawing on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[546],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/9287"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=9287"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/9287\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=9287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=9287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=9287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}