Skip to content

Commit

Permalink
v2.6.0 - replace get-pixels dep
Browse files Browse the repository at this point in the history
  • Loading branch information
lokesh committed Oct 9, 2024
1 parent d772790 commit 292d5c1
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 266 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ To run just the Node tests:
- Merge `dev` into `master`
- Pull down `master`
- Update version number in `src/color-thief.js` and `package.json`
- Delete `package-lock.json` and then install deps
- Run `npm run build`
- Confirm tests pass `npm run dev` and `npm run test`
- Commit and push built files back up to `master`
- Create a new Github release along with tag. Naming convention for both ```v2.8.1```
- `npm publish`
18 changes: 11 additions & 7 deletions dist/color-thief.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const getPixels = require('get-pixels');
const { getPixels } = require('ndarray-pixels');
const sharp = require('sharp');
const quantize = require('@lokesh.dhakar/quantize');
const FileType = require('file-type');

Expand Down Expand Up @@ -37,14 +38,17 @@ function validateOptions(options) {
return { colorCount, quality };
}

function loadImg(img) {
const loadImg = (img) => {
const type = Buffer.isBuffer(img) ? FileType.fromBuffer(img).mime : null
return new Promise((resolve, reject) => {
getPixels(img, type, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
sharp(img)
.toBuffer()
.then(buffer => sharp(buffer).metadata()
.then(metadata => ({ buffer, format: metadata.format })))
.then(({ buffer, format }) => getPixels(buffer, format))
.then(resolve)
.catch(reject);
})
}

function getColor(img, quality) {
Expand Down
Loading

0 comments on commit 292d5c1

Please sign in to comment.