blob: fc762f2a1105c225a305db60afeee983e79942a5 [file] [log] [blame]
<!DOCTYPE html>
<style>
div.container {
display: inline-block;
margin-right: 20px;
margin-bottom: 10px;
width: 100px;
vertical-align: top;
}
div.horizontal {
width: 102px;
height: 52px;
}
div.vertical {
width: 52px;
height: 102px;
}
canvas {
border: 1px solid black;
}
canvas.horizontal {
width: 100px;
height: 50px;
}
canvas.vertical {
width: 50px;
height: 100px;
}
</style>
<body>
<b>CanvasRenderingContext2D.drawImage() should rotate the images respecting their EXIF orientation.</b>
<br>
<br>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas1"></canvas>
</div>
<br>Normal
</div>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas2"></canvas>
</div>
<br>Flipped horizontally
</div>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas3"></canvas>
</div>
<br>Rotated 180&deg;
</div>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas4"></canvas>
</div>
<br>Flipped vertically
</div>
<br>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas5"></canvas>
</div>
<br>Rotated 90&deg; CCW and flipped vertically
</div>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas6"></canvas>
</div>
<br>Rotated 90&deg; CCW
</div>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas7"></canvas>
</div>
<br>Rotated 90&deg; CW and flipped vertically
</div>
<div class ="container">
<div class ="vertical">
<canvas class="vertical" id="canvas8"></canvas>
</div>
<br>Rotated 90&deg; CW
</div>
<br>
<div class ="container">
<div class ="horizontal">
<canvas class="horizontal" id="canvas9"></canvas>
</div>
<br>Undefined (invalid value)
</div>
<script>
if (window.testRunner)
window.testRunner.waitUntilDone();
window.onload = function() {
var names = [
{ resource: "resources/exif-orientation-1-ul.jpg", id : "canvas1" },
{ resource: "resources/exif-orientation-2-ur.jpg", id : "canvas2" },
{ resource: "resources/exif-orientation-3-lr.jpg", id : "canvas3" },
{ resource: "resources/exif-orientation-4-lol.jpg", id : "canvas4" },
{ resource: "resources/exif-orientation-5-lu.jpg", id : "canvas5" },
{ resource: "resources/exif-orientation-6-ru.jpg", id : "canvas6" },
{ resource: "resources/exif-orientation-7-rl.jpg", id : "canvas7" },
{ resource: "resources/exif-orientation-8-llo.jpg", id : "canvas8" },
{ resource: "resources/exif-orientation-9-u.jpg", id : "canvas9" }
];
var drawCount = 0;
names.forEach(function(name) {
var image = new Image;
image.src = name.resource;
image.decode().then(() => {
let canvas = document.getElementById(name.id);
canvas.width = image.width;
canvas.height = image.height;
let context = canvas.getContext("2d");
context.drawImage(image, 0, 0, canvas.width, canvas.height);
if (++drawCount == names.length) {
if (window.testRunner)
window.testRunner.notifyDone();
}
});
});
}
</script>
</body>