1.3.2 • Published 3 months ago

image-color-utils v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

image-color-utils

DESC

Provide pickup color, color similarity comparison, color boundary value calculation and other capabilities。

npm.io

demo

codesandbox

npm.io

Install

npm install image-color-utils --save

Usage

es
import { ImageColorUtils } from 'image-color-utils'
commonjs
const { ImageColorUtils } = require('image-color-utils')

API

# ImageColorUtils

import { ImageColorUtils } from 'image-color-utils'

const params = {
  origin: img,
  width: canvas.width,
  height: canvas.height,
  boundaryValue,
  mockMovePx,
  onload,
}
const imageColorUtils = new ImageColorUtils(params)
Arguments
NameDescTypeDefaultrequired
origin数据源(可以是 http链接 / ImageBitmap / HTMLImageElement )string / HTMLImageElement / ImageBitmap /-true
width画板宽度number-false (不传参将根据图片宽高自适应,origin 为 ImageBitmap / HTMLImageElemen,必填)
height画板高度number-false (不传参将根据图片宽高自适应,origin 为 ImageBitmap / HTMLImageElemen,必填)
mockMovePx边界扫描距离(最大边界扫描距离, 扫描方向由内向外)number30false
boundaryValue色彩边界阈值(作用于色值相似度对比, 阈值越高,相似条件越高)number10false
onload加载完成()=>void-false
Returns
DescType
ImageColorUtils实例Object

# pickColor - 提取单个色值

import { ImageColorUtils } from 'image-color-utils'


const imageColorUtils = new ImageColorUtils({
  origin: img,
  width: canvas.width,
  height: canvas.height
})
const res = imageColorUtils.pickColor(x, y)
Arguments
NameDescTypeDefaultrequired
x目标点距离画布左上角x坐标number-true
y目标点距离画布左上角y坐标number-true
Returns
DescType
目标点 rgb 色值number[]

# pickColors - 提取图片色值

import { ImageColorUtils } from 'image-color-utils'


const imageColorUtils = new ImageColorUtils({
  origin: img,
  width: canvas.width,
  height: canvas.height
})
const res = imageColorUtils.pickColors()
Returns
Returns
DescType
图片色值{rgb: string[], hex: string[] }

# adjust - 色彩边缘计算

import { ImageColorUtils } from 'image-color-utils'

const imageColorUtils = new ImageColorUtils({ 
  origin: img,
  width: canvas.width, 
  height: canvas.height,  
  boundaryValue,
  mockMovePx
})
imageColorUtils.adjust(leftTopPosition, rightBottomPosition)
Arguments
NameDescTypeDefaultrequired
leftTopPosition图片所选区域初始左上角坐标number[][]false
rightBottomPosition图片所选区域初始右下角坐标number[][]false
Returns
DescType
边界计算后左上角坐标(x,y)及区域宽高(width,height)Object:{x: number, y: number, width: number, height: number}

# compare - 色值相似度对比

import { ImageColorUtils } from 'image-color-utils'

const res = ImageColorUtils.compare(color1, color2, boundaryValue, type)
Arguments
NameDescTypeDefaultrequired
color1rgb 色值1number[]-true
color2rgb 色值2number[]-true
boundaryValue色彩边界阈值(作用于色值相似度对比, 阈值越高,相似条件越高)number10false
type颜色模型'rgb' or 'lab''rgb'true
Returns
DescType
是否相似boolean

# hex2rgb - HEX色值转RGB色值

import { hex2rgb } from 'image-color-utils'

const rgb = hex2rgb(hex)
Arguments
NameDescTypeDefaultrequired
hexHEX色值String-true
Returns
DescType
RGB色值number[]

# rgb2hex - RGB色值转HEX色值

import { rgb2hex } from 'image-color-utils'

const hex = rgb2hex(rgb)
Arguments
NameDescTypeDefaultrequired
rgbRGB色值number[]-true
Returns
DescType
HEX色值string

Attribute

import { ImageColorUtils } from 'image-color-utils'

const imageColorUtils = new ImageColorUtils({ 
  origin: img,
  width: canvas.width,
  height: canvas.height,
  boundaryValue,
  mockMovePx
})

console.log(imageColorUtils.canvas)
console.log(imageColorUtils.ctx)
console.log(imageColorUtils.imageData)
NameType
canvasOffscreenCanvas
ctxOffscreenCanvasRenderingContext2D
imageDataImageData
1.3.2

3 months ago

1.3.1

3 months ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.9

2 years ago

1.2.12

2 years ago

1.2.10

2 years ago

1.2.11

2 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.11

4 years ago

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago