Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
A dependency-free image color extraction library.
The extraction consists of using K-Means algorithm.
It has a few utility functions as well!
NOTE: This library compiles to Ecmascript modules target.
This picture was downloaded from Unsplash - link
With npm:
npm i color-mage
# or
yarn add color-mage
import { convertImageDataToRgba, kMeansColorExtractor, convertRgbToHex } from 'color-mage'
const canvas = document.getElementById('#canvas') as HTMLCanvasElement
const ctx = canvas.getContext('2d')
// draw your image
ctx.drawImage(image, 0, 0, 640, 480)
// then get the image data from canvas
const imageData = ctx.getImageData(0, 0, 640, 480)
// converts the imageData array into an array of colors
const colors = convertImageDataToRgba(imageData.data)
// RGBA color representation
const palette = kMeansColorExtractor(colors, 5)
// All colors converted into hexadecimal representation
const hexColors = palette.map(convertRgbToHex)
The process might take longer depending on the output size of ctx.getImageData
,
since it will result in more pixels to process.
It might take longer as well if the image has many colors or the maxRuns
in kMeansColorExtractor
parameter is higher.
As you can see in the example below, the maxRuns
is a tradeoff between color accuracy and time to process.
An example using a 8K image:
Extracting 10 colors and maxRuns
equals to 50
imageData extracted with size of 800x450px using ctx.getImageData(0, 0, 800, 450)
Metrics:
The same image and output size, but with maxRuns
equals to 10 (default)
Metrics:
FAQs
A dependency-free image color extraction library.
The npm package color-mage receives a total of 4 weekly downloads. As such, color-mage popularity was classified as not popular.
We found that color-mage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.