Posted By

Sephr on 03/05/09


Tagged

canvas apng


Versions (?)

APNG Feature Detection


 / Published in: JavaScript
 

URL: http://eligrey.com/2009/03/03/apng-feature-detection/

APNG Feature Detection

This code will set the variable, apng_supported to true if APNG and <canvas> are supported.

This script requires the following APNG image (157 bytes): http://code.eligrey.com/apng-detect/apng-test.png

  1. (function(_global) {
  2. var apng_test = new Image(),
  3. ctx = document.createElement("canvas").getContext("2d");
  4. apng_test.src = "apng-test.png"; // a data URI will cause a security error so you _have_ to link to an external resource
  5. // frame 1 (skipped on apng-supporting browsers): 0,0,0,255
  6. // frame 2: 0,0,0,0
  7. apng_test.onload = function() {
  8. ctx.drawImage(apng_test, 0, 0);
  9. _global.apng_supported = ( ctx.getImageData(0, 0, 1, 1).data[3] == 0 );
  10. }
  11. })(this);

Report this snippet  

You need to login to post a comment.