Giter Site home page Giter Site logo

Animated AVIF about modernizr HOT 3 OPEN

mathiasbynens avatar mathiasbynens commented on June 18, 2024
Animated AVIF

from modernizr.

Comments (3)

mathiasbynens avatar mathiasbynens commented on June 18, 2024 2

FWIW, I looked into this a while back, and couldn’t find a good way to specifically detect animated AVIF without depending on the ImageDecoder API. The problem is, the ImageDecoder API is itself not supported across browsers yet.

Here’s what I ended up with:

// A hand-made 1×1px two-frame animation: a red frame followed by a green frame.
// Note that AVIF animations always loop indefinitely.
const ANIMATED_AVIF_URL = 'data:image/avif;base64,AAAALGZ0eXBhdmlzAAAAAGF2aXNhdmlmbXNmMWlzbzhtaWYxbWlhZk1BMUEAAAD5bWV0YQAAAAAAAAAvaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAFBpY3R1cmVIYW5kbGVyAAAAAA5waXRtAAAAAAABAAAAHmlsb2MAAAAARAAAAQABAAAAAQAAA7gAAAAkAAAAKGlpbmYAAAAAAAEAAAAaaW5mZQIAAAAAAQAAYXYwMUNvbG9yAAAAAGppcHJwAAAAS2lwY28AAAAUaXNwZQAAAAAAAAACAAAAAgAAABBwaXhpAAAAAAMICAgAAAAMYXYxQ4EgAAAAAAATY29scm5jbHgAAgACAACAAAAAF2lwbWEAAAAAAAAAAQABBAECgwQAAAKLbW9vdgAAAGxtdmhkAAAAAAAAAAAAAAAAAAAyAAAAAAAAAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAhd0cmFrAAAAXHRraGQAAAADAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAIAAAACAAAAAAGzbWRpYQAAACBtZGhkAAAAAAAAAAAAAAAAAAAyAAAABABVxAAAAAAAL2hkbHIAAAAAAAAAAHBpY3QAAAAAAAAAAAAAAABQaWN0dXJlSGFuZGxlcgAAAAFcbWluZgAAABR2bWhkAAAAAQAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAABHHN0YmwAAACcc3RzZAAAAAAAAAABAAAAjGF2MDEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAgACAEgAAABIAAAAAAAAAAEYTGF2YzU5LjQ0LjEwMCBsaWJhb20tYXYxAAAAAAAAAAAY//8AAAAMYXYxQ4EgAAAAAAAKZmllbAEAAAAAEHBhc3AAAAABAAAAAQAAABBjY3N0AAAAAHwAAAAAAAAYc3R0cwAAAAAAAAABAAAAAgAAAgAAAAAUc3RzcwAAAAAAAAABAAAAAQAAABxzdHNjAAAAAAAAAAEAAAABAAAAAgAAAAEAAAAcc3RzegAAAAAAAAAAAAAAAgAAACQAAAAbAAAAFHN0Y28AAAAAAAAAAQAAA7gAAABHbWRhdAoLIAAAAAZ//NAQ0AIyFRAAwAAAAoAAAAX172TdcwHjmhthyDIZMAPAgAAABsAAAAKAAACAAB6cDnVHjqg2Jg==';

function supportsStaticAvif() {
  const promise = new Promise((resolve) => {
    const img = new Image();
    img.onload = () => resolve(true);
    img.onerror = () => resolve(false);
    img.src = ANIMATED_AVIF_URL;
  });
  return promise;
}

async function supportsAnimatedAvif() {
  const response = await fetch(ANIMATED_AVIF_URL);
  const bytes = response.body;
  const imageDecoder = new ImageDecoder({
    data: bytes,
    type: 'image/avif',
  });
  const result = await imageDecoder.decode();
  return imageDecoder.tracks.selectedTrack.animated && imageDecoder.tracks.length > 1;
}

from modernizr.

eoyoa avatar eoyoa commented on June 18, 2024 1

Hi, I would like to try contributing. Could I be assigned this issue?

from modernizr.

eoyoa avatar eoyoa commented on June 18, 2024

Apologies, but I am currently unavailable to work on this issue, so I will unassign myself. Thank you for the opportunity regardless.

from modernizr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.