heic-convert
Advanced tools
Comparing version 1.2.4 to 2.0.0
58
index.js
@@ -1,57 +0,5 @@ | ||
const jpegJs = require('jpeg-js'); | ||
const { PNG } = require('pngjs'); | ||
const decode = require('heic-decode'); | ||
const { one, all } = require('./lib.js')(decode); | ||
const to = { | ||
JPEG: ({ data, width, height, quality }) => jpegJs.encode({ data, width, height }, quality).data, | ||
PNG: ({ data, width, height }) => { | ||
const png = new PNG({ width, height }); | ||
png.data = data; | ||
return PNG.sync.write(png, { | ||
width: width, | ||
height: height, | ||
deflateLevel: 9, | ||
deflateStrategy: 3, | ||
filterType: -1, | ||
colorType: 6, | ||
inputHasAlpha: true | ||
}); | ||
} | ||
}; | ||
const convertImage = async ({ image, format, quality }) => { | ||
return await to[format]({ | ||
width: image.width, | ||
height: image.height, | ||
data: Buffer.from(image.data), | ||
quality: Math.floor(quality * 100) | ||
}); | ||
}; | ||
const convert = async ({ buffer, format, quality, all }) => { | ||
if (!to[format]) { | ||
throw new Error(`output format needs to be one of [${Object.keys(to)}]`); | ||
} | ||
if (!all) { | ||
const image = await decode({ buffer }); | ||
return await convertImage({ image, format, quality }); | ||
} | ||
const images = await decode.all({ buffer }); | ||
return images.map(image => { | ||
return { | ||
convert: async () => await convertImage({ | ||
image: await image.decode(), | ||
format, | ||
quality | ||
}) | ||
}; | ||
}); | ||
}; | ||
module.exports = async ({ buffer, format, quality = 0.92 }) => await convert({ buffer, format, quality, all: false }); | ||
module.exports.all = async ({ buffer, format, quality = 0.92 }) => await convert({ buffer, format, quality, all: true }); | ||
module.exports = one; | ||
module.exports.all = all; |
{ | ||
"name": "heic-convert", | ||
"version": "1.2.4", | ||
"version": "2.0.0", | ||
"description": "Convert HEIC/HEIF images to JPEG and PNG", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"pretest": "node scripts/images.js", | ||
"test": "mocha --timeout 20000 --slow 0 \"test/**/*.js\"" | ||
"test": "mocha --timeout 40000 --slow 0 \"test/**/*.js\"" | ||
}, | ||
@@ -42,9 +42,9 @@ "repository": { | ||
"dependencies": { | ||
"heic-decode": "^1.1.2", | ||
"jpeg-js": "^0.4.1", | ||
"pngjs": "^3.4.0" | ||
"heic-decode": "^2.0.0", | ||
"jpeg-js": "^0.4.4", | ||
"pngjs": "^6.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=12.0.0" | ||
} | ||
} |
@@ -5,8 +5,8 @@ # heic-convert | ||
[![travis][travis.svg]][travis.link] | ||
[![ci][ci.svg]][ci.link] | ||
[![npm-downloads][npm-downloads.svg]][npm.link] | ||
[![npm-version][npm-version.svg]][npm.link] | ||
[travis.svg]: https://travis-ci.com/catdad-experiments/heic-convert.svg?branch=master | ||
[travis.link]: https://travis-ci.com/catdad-experiments/heic-convert | ||
[ci.svg]: https://github.com/catdad-experiments/heic-convert/actions/workflows/ci.yml/badge.svg | ||
[ci.link]: https://github.com/catdad-experiments/heic-convert/actions/workflows/ci.yml | ||
[npm-downloads.svg]: https://img.shields.io/npm/dm/heic-convert.svg | ||
@@ -13,0 +13,0 @@ [npm.link]: https://www.npmjs.com/package/heic-convert |
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
5872
4
55
+ Addedheic-decode@2.0.0(transitive)
+ Addedpngjs@6.0.0(transitive)
- Removedheic-decode@1.1.2(transitive)
- Removedpngjs@3.4.0(transitive)
Updatedheic-decode@^2.0.0
Updatedjpeg-js@^0.4.4
Updatedpngjs@^6.0.0