Giter VIP home page Giter VIP logo

to-ico's Introduction

to-ico Build Status

Convert PNG to ICO in memory

Install

$ npm install --save to-ico

Usage

const fs = require('fs');
const toIco = require('to-ico');

const files = [
	fs.readFileSync('unicorn-16x16.png'),
	fs.readFileSync('unicorn-32x32.png')
];

toIco(files).then(buf => {
	fs.writeFileSync('favicon.ico', buf);
});

API

toIco(input, [options])

input

Type: Array string

Array of PNG image buffers.

The images must have a size of 16x16, 24x24, 32x32, 48x48, 64x64, 128x128 or 256x256 and they must have an 8 bit per sample (channel) bit-depth (on Unix you can check this with the file command: RGB(A) is supported, while colormap is not, because it's 8 bits per pixel instead of 8 bits per channel, which is 24 or 32 bits per pixel depending on the presence of the alpha channel). These are limitations in the underlying pngjs library. If you have a colormap PNG you can convert it to an RGB/RGBA PNG with commonly used image editing tools.

options

resize

Type: boolean
Default: false

Use the largest image and resize to sizes defined using the sizes option.

sizes

Type: Array
Default: [16, 24, 32, 48, 64, 128, 256]

Array of sizes to use when resizing.

Related

License

MIT © Kevin Martensson

to-ico's People

Contributors

gianluca-nitti avatar kevva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

to-ico's Issues

TypeError when calling 'toIco()'

I'm getting the following error when calling toIco(arr: string[])...

TypeError: Expected a buffer
    at module.exports (path\node_modules\parse-png\index.js:6:25)
    at Promise.all.data.map.x (path\node_modules\to-ico\index.js:90:35)
    at Array.map (<anonymous>)
    at generateIco (path\node_modules\to-ico\index.js:90:26)
    at module.exports (path\node_modules\to-ico\index.js:146:9)

Am I doing something wrong?

Is there a way to catch error?

When i give a wrong image file like .jpg,error happened. I want to catch it and show a alert, is there a way to do this?

Why can't arbitrary sizes be used?

The readme says:

The images must have a size of 16x16, 24x24, 32x32, 48x48, 64x64, 128x128 or 256x256.

Looking through the code, I don't see an obvious reason for this requirement. I'd like to create a file which also has 96x96, 40x40, and 24x24 icons for use in a Windows program.

If you can give me a nudge in the right direction I can probably submit a PR for this, but I'm not seeing where this limitation is coming from.

Document max size = 256

Currently only input images up to 256px are supported.
https://github.com/kevva/to-ico/blob/master/index.js#L32

$ node src/scripts/favicon.js
(node:18127) ExperimentalWarning: The fs.promises API is experimental
(node:18127) UnhandledPromiseRejectionWarning: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received 1024
    at writeU_Int8 (internal/buffer.js:555:11)
    at Buffer.writeUInt8 (internal/buffer.js:565:10)
    at createDirectory (/home/druf/pwa/client/node_modules/to-ico/index.js:32:6)
    at Promise.all.then.data (/home/druf/pwa/client/node_modules/to-ico/index.js:98:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:18127) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18127) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Done in 0.50s.

Module build failed: TypeError: Buffer.alloc is not a function

There is an issue with the new release that is killing my build. It is with this line:

https://github.com/kevva/to-ico/blob/master/index.js#L15

This is the relevant part of the error:

 70% 1406/1406 build modulesModuleBuildError: Module build failed: TypeError: Buffer.alloc is not a function
    at n (/Users/christopherdzoba/v/brawndo/node_modules/to-ico/index.js:15:21)
    at /Users/christopherdzoba/v/brawndo/node_modules/to-ico/index.js:90:18

I am using node 5.2.0

Buffer.alloc compatibility

Hi,

I just downloaded to-ico but the last version included Buffer.alloc that is not compatible with the node version 4 you're supposed to support according to your package.json.

Please consider revert this modification to keep backward compatibility (pull request #14).

Thanks,

imagemin plugin

hi kevva

will this become an imagemin plugin in the future?

Chokes on 512x512px image

If it can't downscale, it should fail with a user friendly exception ("Images larger than 256x256 px are not supported").

$ file icon_512x512.png 
icon_512x512.png: PNG image data, 512 x 512, 8-bit/color RGBA, non-interlaced

$ node_modules/.bin/to-ico icon_512x512.png 
TypeError: "value" argument is out of bounds
    at checkInt (buffer.js:1040:11)
    at Buffer.writeUInt8 (buffer.js:1088:5)
    at createDirectory (node_modules/to-ico/index.js:32:6)
    at Promise.all.then.data (node_modules/to-ico/index.js:98:16)
    at process._tickCallback (internal/process/next_tick.js:103:7)

$ npm list | grep to-ico
└─┬ [email protected]
  └─┬ [email protected]

The `icotool -l` command returns "incorrect total size of bitmap" for files produced by this library

I was doing some double-checking on the ICO files produced by to-ico. When you use icoutils to list the contents of an ICO file produced by to-ico, you will get something similar to this output:

$ icotool -l path/to/to-ico.ico
path/to/to-ico.ico: incorrect total size of bitmap (1064 specified; 1128 real)

Whereas an ICO file produced by some other tool produces this output:

$ icotool -l path/to/other.ico
--icon --index=1 --width=48 --height=48 --bit-depth=32 --palette-size=0
--icon --index=2 --width=32 --height=32 --bit-depth=32 --palette-size=0
--icon --index=3 --width=16 --height=16 --bit-depth=32 --palette-size=0

It doesn't seem to change based upon how many, or which, icon sizes I provide to to-ico. Is there a bug in how you're calculating, or encoding, output size values?

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.