diff --git a/README.md b/README.md index 59cd9a1..ce41e45 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ Note: All output files are named in the pattern `@w.=0.6.0", + "xmlbuilder": "~11.0.0" + } + }, + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" + }, + "xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true } } } diff --git a/package.json b/package.json index 6d192a7..02d90c4 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "homepage": "https://github.com/dkaoster/rollup-generate-image-sizes#readme", "dependencies": { "globby": "^11.0.1", - "sharp": "^0.28.3" + "jimp": "^0.16.1" }, "devDependencies": { "eslint": "^7.14.0", diff --git a/src/index.js b/src/index.js index 8f19732..7fd9442 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,10 @@ import fs from 'fs'; import globby from 'globby'; -import sharp from 'sharp'; +import jimp from 'jimp'; /** * Generate different image sizes on all images found within a directory, - * based on the configuration given. Uses sharp as the image processing module. + * based on the configuration given. Uses jimp as the image processing module. */ // A helper function for transform single items to array @@ -47,7 +47,7 @@ export default (options = {}) => { `${dirGlob}/**/!(*@*|*#*).{${inputFormat.join(',')}}`, ) .then((images) => Promise.allSettled( - // Map them into sharp objects + // Map them into jimp objects images.map((image) => { // generate the output path const imagePathSplit = image.split('.'); @@ -83,11 +83,8 @@ export default (options = {}) => { // //////////////////////////////////////////// // Everything below is expensive, so we want to short-circuit this as much as possible // load in the image - const sharpObj = sharp(image); - - // Read the sharp metadata so we know what the input width is. - return sharpObj.metadata() - .then((metadata) => Promise.allSettled( + return jimp.read(image) + .then((err, jimpObj) => Promise.allSettled( outputs // Get only the sizes that we need to generate .reduce((acc, val) => { @@ -97,7 +94,9 @@ export default (options = {}) => { .map((scaleWidth) => { // If the width we want to scale to is larger than the original // width and forceUpscale is not set, we skip this. - if (scaleWidth > metadata.width && !forceUpscale) return Promise.resolve(); + if (scaleWidth > jimpObj.bitmap.width && !forceUpscale) { + return Promise.resolve(); + } // Save all of the output images return Promise.all( @@ -105,11 +104,11 @@ export default (options = {}) => { // only get the outputs of the current width .filter((d) => d.scaleWidth === scaleWidth) .map((d) => d.format) - .map((format) => sharpObj + .map((format) => jimpObj .clone() - .resize(scaleWidth) - .toFormat(format, { quality }) - .toFile(`${imagePathPre}@${scaleWidth}w.${format}`)), + .resize(scaleWidth, jimp.AUTO) + .quality(quality) + .write(`${imagePathPre}@${scaleWidth}w.${format}`)), ); }), ));