W3Schools.com

HTML5 canvas imagedata width Attribute

HTML5 track Tag Reference HTML5 canvas reference

Example

Create a 50*50 pixels imagedata object where every pixel is red:

Canvas

Yor browser does not support the canvas tag.

JavaScript:

var ctx=c.getContext("2d");
var imgData=ctx.createImageData(50,50);
for (i=0; i<imgData.width*imgData.height*4;i+=4)
  {
  imgData.data[i+0]=255;
  imgData.data[i+1]=0;
  imgData.data[i+2]=0;
  imgData.data[i+3]=255;
  }
ctx.putImageData(imgData,10,10);

Try it yourself »

Definition and Usage

The width attribute specifies the width of the imagedata object, in pixels.


JavaScript Syntax

JavaScript syntax: imgData.width=50;


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The width attribute is supported in all major browsers.


Attribute Values

Values Description
number Specifies the width of the imagedata object

HTML5 track Tag Reference HTML5 canvas reference


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE