
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
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 0 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.