OLD | NEW |
(Empty) | |
| 1 <img id="png"/> |
| 2 <img id="jpeg-high"/> |
| 3 <img id="jpeg-low"/> |
| 4 <img id="webp-high"/> |
| 5 <img id="webp-low"/> |
| 6 <script> |
| 7 if (window.testRunner) { |
| 8 testRunner.waitUntilDone(); |
| 9 } |
| 10 |
| 11 var pngImage = document.getElementById('png'); |
| 12 var jpegImageHigh = document.getElementById('jpeg-high'); |
| 13 var jpegImageLow = document.getElementById('jpeg-low'); |
| 14 var webpImageHigh = document.getElementById('webp-high'); |
| 15 var webpImageLow = document.getElementById('webp-low'); |
| 16 var numTestCount = 5; |
| 17 function imageLoaded() { |
| 18 numTestCount--; |
| 19 if (numTestCount == 0 && window.testRunner) { |
| 20 window.testRunner.notifyDone(); |
| 21 } |
| 22 } |
| 23 pngImage.addEventListener('load', imageLoaded); |
| 24 jpegImageHigh.addEventListener('load', imageLoaded); |
| 25 jpegImageLow.addEventListener('load', imageLoaded); |
| 26 webpImageHigh.addEventListener('load', imageLoaded); |
| 27 webpImageLow.addEventListener('load', imageLoaded); |
| 28 |
| 29 var canvas = document.createElement("canvas"); |
| 30 canvas.width = 50; |
| 31 canvas.height = 50; |
| 32 var ctx = canvas.getContext('2d'); |
| 33 ctx.fillStyle = "red"; |
| 34 ctx.fillRect(0, 0, 25, 25); |
| 35 ctx.fillStyle = "green"; |
| 36 ctx.fillRect(25, 0, 25, 25); |
| 37 ctx.fillStyle = "blue"; |
| 38 ctx.fillRect(0, 25, 25, 25); |
| 39 ctx.fillStyle = "black"; |
| 40 ctx.fillRect(25, 25, 25, 25); |
| 41 ctx.strokeStyle = "yellow"; |
| 42 ctx.strokeRect(0, 0, 50, 50); |
| 43 |
| 44 canvas.toBlob(function(blob) { |
| 45 pngImage.src = URL.createObjectURL(blob); |
| 46 }); |
| 47 |
| 48 canvas.toBlob(function(blob) { |
| 49 jpegImageHigh.src = URL.createObjectURL(blob); |
| 50 }, "image/jpeg", 1.0); |
| 51 |
| 52 canvas.toBlob(function(blob) { |
| 53 jpegImageLow.src = URL.createObjectURL(blob); |
| 54 }, "image/jpeg", 0.2) |
| 55 |
| 56 canvas.toBlob(function(blob) { |
| 57 webpImageHigh.src = URL.createObjectURL(blob); |
| 58 }, "image/webp", 1.0); |
| 59 |
| 60 canvas.toBlob(function(blob) { |
| 61 webpImageLow.src = URL.createObjectURL(blob); |
| 62 }, "image/webp", 0.2); |
| 63 |
| 64 </script> |
| 65 |
OLD | NEW |