1.0.0 • Published 4 years ago

create-ico v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

create-ico

Creates an ico file from a single input image, using sharp to resize the image to specified icon sizes (and apply an optional circular mask), pngquant to optimize the pngs, and icon-encoder to assemble the ico (the older to-ico chokes on optimized pngs).

Especially useful for favicons, as pngquant keeps the ico file as small as possible, and the optional mask makes it possible to generate a round favicon from the same square image used for maskable home screen icons.

Install

npm install create-ico

Usage

createIco(input: string | Buffer, options?: CreateIcoOptions): Promise<Buffer>
createIco(input: string | Buffer, output: string, options?: CreateIcoOptions): Promise<void>

  • input The input image as accepted by sharp.
  • output The output file path. (Optional)
  • options (Optional)
    • shape: 'circle' Optional mask to apply to the icon. (Optional)
    • sizes: number[] Icon sizes to generate. Defaults to 16, 32, as recommended for favicons. Size cannot exceed 256 (the ico format stores width & height as a single byte each). (Optional)
    • pngquant Options passed to pngquant. Defaults to speed 1, strip metadata. See docs here. (Optional)
import { createIco } from 'create-ico';

await createIco('image.png', 'output.ico', { shape: 'circle' });

// or
let ico = await createIco('image.png', { sizes: [16, 32, 64, 256] });
fs.writeFileSync('output.ico', ico);