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) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6188
118
65
4
+ Addedarrify@^1.0.1
+ Addedimage-size@^0.5.0
+ Addedresize-img@^1.1.0
+ Addedajv@6.12.6(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbignumber.js@2.4.0(transitive)
+ Addedbmp-js@0.0.10.0.3(transitive)
+ Addedbuffer-equal@0.0.1(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcentra@2.7.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddom-walk@0.1.2(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedes6-promise@3.3.1(transitive)
+ Addedexif-parser@0.1.12(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfile-type@3.9.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedget-stream@2.3.1(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedimage-size@0.5.5(transitive)
+ Addedip-regex@1.0.3(transitive)
+ Addedis-function@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjimp@0.2.28(transitive)
+ Addedjpeg-js@0.1.20.2.0(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedload-bmfont@1.4.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.5.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-bmfont-ascii@1.0.6(transitive)
+ Addedparse-bmfont-binary@1.0.6(transitive)
+ Addedparse-bmfont-xml@1.1.6(transitive)
+ Addedparse-headers@2.0.5(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedphin@3.7.1(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpixelmatch@4.0.2(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedread-chunk@1.0.1(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedresize-img@1.1.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstream-to@0.2.2(transitive)
+ Addedstream-to-buffer@0.1.0(transitive)
+ Addedtinycolor2@1.6.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedurl-regex@3.2.0(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxhr@2.6.0(transitive)
+ Addedxml-parse-from-string@1.0.1(transitive)
+ Addedxml2js@0.5.0(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
+ Addedxtend@4.0.2(transitive)