How to use the icojs.parse function in icojs

To help you get started, we’ve selected a few icojs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kura52 / sushi-browser / src / captureFaviconEvent.js View on Github external
image = image.resize(Jimp.AUTO,20,Jimp.RESIZE_BICUBIC)
            }
            image.getBase64(Jimp.AUTO, function (err, src) {
              resolve(src)
            })
            //   .toBuffer().then(data=>{
            //   resolve(`data:image/png;base64,${data.toString('base64')}`)
            // })
          }

        })
      }
      else if(img.type.endsWith('icon') && ico.isICO(img)){
        console.log(148,Date.now())
        try{
          ico.parse(img).then(function (images) {
            console.log(149,Date.now())
            const icoImage = images[0]
            const imgBuffer = Buffer.from(icoImage.buffer)
            console.log(151,Date.now())
            Jimp.read(imgBuffer, function (err, image) {
              if (err || !image) {
                console.log("ERROR Failed to save file", err);
                resolve(blob)
              }
              if(Math.max(image.bitmap.width,image.bitmap.height) <= 20){
                console.log(146,Date.now())
                resolve(`data:image/png;base64,${imgBuffer.toString('base64')}`)
              }
              else{
                console.log(147,Date.now())
                if(image.bitmap.width > image.bitmap.height){
github beakerbrowser / beaker-core / dat / assets.js View on Github external
async function readAsset (archive, pathname) {
  if (pathname.endsWith('.ico')) {
    let data = await archive.pda.readFile(pathname, 'binary')
    // select the best-fitting size
    let images = await ICO.parse(data, 'image/png')
    let image = images[0]
    for (let i = 1; i < images.length; i++) {
      if (Math.abs(images[i].width - IDEAL_FAVICON_SIZE) < Math.abs(image.width - IDEAL_FAVICON_SIZE)) {
        image = images[i]
      }
    }
    let buf = Buffer.from(image.buffer)
    return `data:image/png;base64,${buf.toString('base64')}`
  } else {
    let data = await archive.pda.readFile(pathname, 'base64')
    return `data:${mime.lookup(pathname)};base64,${data}`
  }
}
github beakerbrowser / beaker / app / background-process / protocols / beaker-favicon.js View on Github external
// if a dat, see if there's a favicon.ico or .png
    try {
      let data, fs
      // pick the filesystem
      let datResolvedUrl = url
      if (url.startsWith('dat://')) {
        datResolvedUrl = await dat.dns.resolveName(url)
        fs = dat.library.getArchive(datResolvedUrl) // (only try if the dat is loaded)
      }
      if (fs) {
        // try .ico
        try {
          data = await pda.readFile(fs, '/favicon.ico', 'binary')
          if (data) {
            // select the best-fitting size
            let images = await ICO.parse(data, 'image/png')
            let image = images[0]
            for (let i = 1; i < images.length; i++) {
              if (Math.abs(images[i].width - faviconSize) < Math.abs(image.width - faviconSize)) {
                image = images[i]
              }
            }
            let buf = Buffer.from(image.buffer)
            sitedata.set(url, 'favicon', `data:image/png;base64,${buf.toString('base64')}`) // cache
            return cb({mimeType: 'image/png', data: buf})
          }
        } catch (e) {
          // .ico failed, ignore
          data = null
        }

        // try .png
github sidneys / pb-for-desktop / app / scripts / renderer-process / pushbullet / push.js View on Github external
// From .PNG
            if (isPng || isJpeg) {
                resizeWriteImage(imageBuffer, imageFilepathDownloaded, notificationIconWidth, (error, imageFilepathConverted) => {
                    if (error) { return }

                    notificationOptions.icon = imageFilepathConverted
                    showNotification(notificationOptions, decoratedPush)
                })

                return
            }

            // From .ICO
            if (isIco) {
                icojs.parse(imageBuffer, 'image/png').then(imageList => {
                    const imageMaximum = imageList[imageList.length - 1]
                    resizeWriteImage(Buffer.from(imageMaximum.buffer), imageFilepathDownloaded, notificationIconWidth, (error, imageFilepathConverted) => {
                        if (error) { return }

                        notificationOptions.icon = imageFilepathConverted
                        showNotification(notificationOptions, decoratedPush)
                    })
                })
            }

        })
        // Image: Fallback to App Icon
github wexond / desktop / src / main / services / storage.ts View on Github external
const convertIcoToPng = async (icoData: Buffer): Promise => {
  return (await icojs.parse(icoData, 'image/png'))[0].buffer;
};
github Grathium-Industries / labyrinth / src / main / services / storage.ts View on Github external
const convertIcoToPng = async (icoData: Buffer): Promise => {
  return (await icojs.parse(icoData, 'image/png'))[0].buffer;
};
github dot-browser / desktop / src / renderer / views / app / store / favicons.ts View on Github external
return new Promise((resolve: (b: Buffer) => void) => {
    icojs.parse(icoData, 'image/png').then((images: any) => {
      resolve(images[0].buffer);
    });
  });
};

icojs

parse ico file

MIT
Latest version published 3 months ago

Package Health Score

72 / 100
Full package analysis

Popular icojs functions