Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
extract-colors
Advanced tools
Extract color palettes from images.
Simple use, < 6kB minified, gzip ≈ 2kB, fast process and no dependencies for browser.
Need image reader dependence for node.js
npm install --save extract-colors
Need to install an ImageData extractor like get-pixels
npm install --save extract-colors get-pixels
import { extractColors } from 'extract-colors'
const src = 'my-image.jpg'
extractColors(src)
.then(console.log)
.catch(console.error)
You can use different types for
src
param (String
for a path of image,HTMLImageElement
orImageData
).
const path = require('path')
const getPixels = require("get-pixels")
const { extractColors } = require('extract-colors')
const src = path.join(__dirname, './my-image.jpg')
getPixels(src, (err, pixels) => {
if(!err) {
const data = [...pixels.data]
const width = Math.round(Math.sqrt(data.length / 4))
const height = width
extractColors({ data, width, height })
.then(console.log)
.catch(console.log)
}
})
This example use
get-pixels
but you can change the lib. Just send and ImageData object toextractColors(imageData)
.
const options = {
pixels: 64000,
distance: 0.22,
colorValidator: (red, green, blue, alpha = 255) => alpha > 250,
saturationDistance: 0.2,
lightnessDistance: 0.2,
hueDistance: 0.083333333
}
extractColors(src, options)
.then(console.log)
.catch(console.error)
pixels
Total pixel number of the resized picture for calculation
Type: Integer
Default: 64000
distance
From 0 to 1 is the color distance to not have near colors (1 distance is between white and black)
Type: Number
Default: 0.22
colorValidator
Test function to enable only some colors
Type: Function
Default: (red, green, blue, alpha = 255) => alpha > 250
crossOrigin
Only for browser, can be 'Anonymous' to avoid client side CORS
(the server side images need authorizations too)
Type: String
Default: null
saturationDistance
Minimum saturation value between two colors otherwise the colors will be merged (from 0 to 1)
Type: String
Default: 0.2
lightnessDistance
Minimum lightness value between two colors otherwise the colors will be merged (from 0 to 1)
Type: String
Default: 0.2
hueDistance
Minimum hue value between two colors otherwise the colors will be merged (from 0 to 1)
Type: String
Default: 0.083333333
Array of colors with the followed properties:
[
{
hex: "#858409",
red: 133,
green: 132,
blue: 9,
hue: 0.16532258064516128,
intensity: 0.4862745098039216,
lightness: 0.2784313725490196,
saturation: 0.8732394366197184,
area: 0.0004
},
...
]
Field | Example | Type | Description |
---|---|---|---|
hex | #858409 | String | color in hexadecimal string |
red | 133 | Integer | red canal from 0 to 255 |
green | 132 | Integer | green canal from 0 to 255 |
blue | 9 | Integer | blue canal from 0 to 255 |
hue | 0.1653 | Number | color tone from 0 to 1 |
intensity | 0.4862 | Number | color intensity from 0 to 1 |
lightness | 0.2784 | Number | color lightness from 0 to 1 |
saturation | 0.8732 | Number | color saturation from 0 to 1 |
area | 0.0004 | Number | area of the color and his neighbouring colors from 0 to 1 |
Copyright (C) 2019 Damien Doussaud
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
FAQs
Extract color palettes from images
The npm package extract-colors receives a total of 8,543 weekly downloads. As such, extract-colors popularity was classified as popular.
We found that extract-colors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.