Skip to content

Instantly share code, notes, and snippets.

@hashedhyphen
Last active October 8, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashedhyphen/2531f47e5456afb44f03ddb0b95c9454 to your computer and use it in GitHub Desktop.
Save hashedhyphen/2531f47e5456afb44f03ddb0b95c9454 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Cases</title>
<script>
document.addEventListener('DOMContentLoaded', () => {
const ctx1 = document.getElementById('canvas1').getContext('2d');
const ctx2 = document.getElementById('canvas2').getContext('2d');
const ctx3 = document.getElementById('canvas3').getContext('2d');
const ctx4 = document.getElementById('canvas4').getContext('2d');
const img = document.getElementById('img');
img.addEventListener('load', () => {
try {
ctx1.drawImage(img,
0, // sx
0, // sy
1, // sWidth (in question)
1, // sHeight (in question)
0, // dx
0, // dy
0, // dWidth
0, // dHeight
);
} catch (err) {
console.error(`${err.name}: ${err.message}`);
}
try {
ctx2.drawImage(img,
0, // sx
0, // sy
0, // sWidth (in question)
1, // sHeight (in question)
0, // dx
0, // dy
0, // dWidth
0, // dHeight
);
} catch (err) {
console.error(`${err.name}: ${err.message}`);
}
try {
ctx3.drawImage(img,
0, // sx
0, // sy
1, // sWidth (in question)
0, // sHeight (in question)
0, // dx
0, // dy
0, // dWidth
0, // dHeight
);
} catch (err) {
console.error(`${err.name}: ${err.message}`);
}
try {
ctx4.drawImage(img,
0, // sx
0, // sy
0, // sWidth (in question)
0, // sHeight (in question)
0, // dx
0, // dy
0, // dWidth
0, // dHeight
);
} catch (err) {
console.error(`${err.name}: ${err.message}`);
}
});
});
</script>
</head>
<body>
<img id="img" src="https://mdn.mozillademos.org/files/5397/rhino.jpg">
<canvas id="canvas1"></canvas>
<canvas id="canvas2"></canvas>
<canvas id="canvas3"></canvas>
<canvas id="canvas4"></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment