toDataURL.jpeg.quality.basic.html (1961B)
1 <!DOCTYPE html> 2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> 3 <title>Canvas test: toDataURL.jpeg.quality.basic</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/html/canvas/resources/canvas-tests.js"></script> 7 <link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css"> 8 <body class="show_output"> 9 10 <h1>toDataURL.jpeg.quality.basic</h1> 11 <p class="desc">toDataURL with JPEG uses the quality parameter</p> 12 13 14 <p class="output">Actual output:</p> 15 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 16 <p class="output expectedtext">Expected output:<p><img src="toDataURL.jpeg.quality.basic.png" class="output expected" id="expected" alt=""> 17 <ul id="d"></ul> 18 <script> 19 var t = async_test("toDataURL with JPEG uses the quality parameter"); 20 _addTest(function(canvas, ctx) { 21 22 ctx.fillStyle = '#00f'; 23 ctx.fillRect(0, 0, 100, 50); 24 ctx.fillStyle = '#0ff'; 25 ctx.fillRect(0, 3, 100, 1); 26 // Check for JPEG support first 27 var data = canvas.toDataURL('image/jpeg'); 28 if (!data.match(/^data:image\/jpeg[;,]/)) { 29 _assert(true, "true"); 30 } else { 31 var data_hi = canvas.toDataURL('image/jpeg', 0.99); 32 var data_lo = canvas.toDataURL('image/jpeg', 0.01); 33 ctx.fillStyle = '#f00'; 34 ctx.fillRect(0, 0, 100, 50); 35 deferTest(); 36 var img_hi = new Image(); 37 img_hi.onload = function () 38 { 39 var img_lo = new Image(); 40 img_lo.onload = t.step_func_done(function () 41 { 42 ctx.drawImage(img_hi, 0, 0, 50, 50, 0, 0, 50, 50); 43 ctx.drawImage(img_lo, 0, 0, 50, 50, 50, 0, 50, 50); 44 _assert(data_hi.length > data_lo.length, "data_hi.length > data_lo.length"); 45 _assertPixelApprox(canvas, 25,25, 0,0,255,255, 8); 46 _assertPixelApprox(canvas, 75,25, 0,0,255,255, 32); 47 }); 48 img_lo.src = data_lo; 49 }; 50 img_hi.src = data_hi; 51 } 52 53 54 }); 55 </script>