Crop An Image: Draw An Image With Specified Height and Width
Crop An Image: Draw An Image With Specified Height and Width
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = 188;
var y = 30;
var width = 200;
var height = 137;
var imageObj = new Image();
imageObj.onload = function() {
context.drawImage(imageObj, x, y, width, height);
};
imageObj.src = "w.jpg";
</script>
Crop an Image
context.drawImage(image3, sx, sy, sw, sh, dx, dy, dw, dh);
The sx, sy, sw and sh parameters declare from where (sx,sy) in the image
the rectangle starts, and the width (sw) and height (sh) of the rectangle.
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var imageObj = new Image();
imageObj.onload = function() {
// draw cropped image
var sourceX = 0;
var sourceY = 0;
var sourceWidth = 150;
var sourceHeight = 150;
var destWidth = 150;
var destHeight =150;
var destX = 100;
var destY = 100;
Assignment 1:
context.font = '30pt Calibri';
context.font = '60pt Calibri';
context.textAlign = 'center';
context.lineWidth = 3;
// textBaseline aligns text vertically
// stroke color
relative to font style
context.strokeStyle = 'blue';
context.textBaseline = 'middle';
context.strokeText('Hello World!', x,
context.fillStyle = 'blue';
y);
context.fillText('Hello World!', x, y);
</script>
Translation: Move the entire image to a particular x and y location
context.fillStyle = "#ff0000";
context.fillRect(10,10, 100, 100);
context.translate(100, 100);
context.fillStyle = "#0000ff";
context.fillRect(10,10, 100, 100);
Rotate:
context.rotate(radians);
shear
//rotate 25 degrees