catdad-experiments / heic-decode

🤳 decode heic images to extracts the raw pixel data
42 stars 14 forks source link

Multiple images #3

Closed jzarca01 closed 4 years ago

jzarca01 commented 4 years ago

What if there are multiple images in a heic file ? For example https://dynamicwallpaper.club/wallpaper/brzq430bmso

catdad commented 4 years ago

I'm sure we can figure something out. Let me play around with it for a bit

catdad commented 4 years ago

Published in 1.1.0.

const fs = require('fs');
const decode = require('heic-decode');

(async () => {
  const buffer = await promisify(fs.readFile)('/path/to/my/multi-image.heic');
  const images = decode.all({ buffer });

  for (let image of images) {
    // decode and use each image individually
    // so you don't run out of memory
    const {
      width,  // integer width of the image
      height, // integer height of the image
      data    // ArrayBuffer containing decoded raw image data
    } = await image.decode();
  }
})();

Note: not much image processing happens in order to get the images themselves, so if you want say only the 4th image in a file of 12 images, you can choose to call decode on just the 4th item in the array. This skips pretty much all the processing in the other images.

jzarca01 commented 4 years ago

Thanks a lot !