Socket
Socket
Sign inDemoInstall

to-ico

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-ico - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

75

index.js
'use strict';
const arrify = require('arrify');
const imageSize = require('image-size');
const parsePng = require('parse-png');
const resizeImg = require('resize-img');

@@ -85,24 +88,60 @@ const constants = {

module.exports = input => Promise.all(input.map(x => parsePng(x))).then(data => {
const header = createHeader(data.length);
const arr = [header];
const generateIco = data => {
return Promise.all(data.map(x => parsePng(x))).then(data => {
const header = createHeader(data.length);
const arr = [header];
let len = header.length;
let offset = constants.headerSize + (constants.directorySize * data.length);
let len = header.length;
let offset = constants.headerSize + (constants.directorySize * data.length);
data.forEach(x => {
const dir = createDirectory(x, offset);
arr.push(dir);
len += dir.length;
offset += x.data.length + constants.bitmapSize;
});
for (const x of data) {
const dir = createDirectory(x, offset);
arr.push(dir);
len += dir.length;
offset += x.data.length + constants.bitmapSize;
}
data.forEach(x => {
const header = createBitmap(x, constants.colorMode);
const dib = createDib(x.data, x.width, x.height, x.bpp);
arr.push(header, dib);
len += header.length + dib.length;
for (const x of data) {
const header = createBitmap(x, constants.colorMode);
const dib = createDib(x.data, x.width, x.height, x.bpp);
arr.push(header, dib);
len += header.length + dib.length;
}
return Buffer.concat(arr, len);
});
};
return Buffer.concat(arr, len);
});
const resizeImages = (data, opts) => {
data = data
.map(x => {
const size = imageSize(x);
return {
data: x,
width: size.width,
height: size.height
};
})
.reduce((a, b) => a.width > b.width ? a : b, {});
return Promise.all(opts.sizes.filter(x => x <= data.width).map(x => resizeImg(data.data, {
width: x,
height: x
})));
};
module.exports = (input, opts) => {
const data = arrify(input);
opts = Object.assign({
resize: false,
sizes: [16, 24, 32, 48, 64, 128, 256]
}, opts);
if (opts.resize) {
return resizeImages(data, opts).then(generateIco);
}
return generateIco(data);
};
{
"name": "to-ico",
"version": "1.0.1",
"version": "1.1.0",
"description": "Convert PNG to ICO in memory",

@@ -29,3 +29,6 @@ "license": "MIT",

"dependencies": {
"parse-png": "^1.0.0"
"arrify": "^1.0.1",
"image-size": "^0.5.0",
"parse-png": "^1.0.0",
"resize-img": "^1.1.0"
},

@@ -32,0 +35,0 @@ "devDependencies": {

@@ -32,14 +32,34 @@ # to-ico [![Build Status](https://travis-ci.org/kevva/to-ico.svg?branch=master)](https://travis-ci.org/kevva/to-ico)

### toIco(input)
### toIco(input, [options])
#### input
*Required*<br>
Type: `array`
Type: `Array` `string`
An array of PNG image buffers. The images must have a size of `16x16`, `24x24`, `32x32`, `48x48`, `64x64`, `128x128` or `256x256`.
An array of PNG image buffers.
#### options
##### resize
Type: `boolean`<br>
Default: `false`
Use the largest image and resize to sizes defined using the [sizes](#sizes) option.
##### sizes
Type: `Array`<br>
Default: `[16, 24, 32, 48, 64, 128, 256]`
Array of sizes to use when resizing.
## Related
* [to-ico-cli](https://github.com/kevva/to-ico-cli) - CLI for this module
## License
MIT © [Kevin Martensson](http://github.com/kevva)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc