当前位置: 首页 > Web前端 > HTML

推荐一款个人开源的图像色值处理工具image-color-utils

时间:2023-03-27 22:49:20 HTML

image-color-utilsDESC提供颜色选择、颜色值相似度比较、颜色边界值计算等能力。democodesandboxInstallnpminstallimage-color-utils--saveUsageesimport{ImageColorUtils}来自'image-color-utils'commonjsconst{ImageColorUtils}=require('image-color-utils')APIImageColorUtilspickColoradjustcomparehex2rgbrgb2hex\#ImageColorUtilsimport''constparams={origin:img,width:canvas.width,height:canvas.height,boundaryValue,mockMovePx}constimageColorUtils=newImageColorUtils(params)ArgumentsNameDescTypeDefaultrequiredorigin数据源(可以是httplink/ImageBitmap/HTMLImageleElement)string/HTMLImageEImageBitmap/-truewidthArtboardwidthnumber-false(如果不传参数,会自适应图片的宽高,origin为ImageBitmap/HTMLImageElemen,必填)heightArtboardheightnumber-false(如果不传参数,会自适应图片的宽高image,originisImageBitmap/HTMLImageElemen,required)mockMovePx边界扫描距离(最大边界扫描距离,从内部扫描方向tooutside)number30falseboundaryValue颜色边界阈值(作用于颜色值相似度比较,阈值越高,相似度越高)number10falseReturnsDescTypeImageColorUtilsinstanceObject\#pickColor-提取颜色值import{ImageColorUtils}from'image-color-utils'constimageColorUtils=newImageColorUtils({origin:img,width:canvas.width,height:canvas.height})constres=imageColorUtils.pickColor(x,y)ArgumentsNameDescTypeDefaultrequiredx目标点距画布左上角的距离x坐标数-true目标点距画布左上角的距离y坐标数-trueReturnsDescType目标点rgb颜色值数[]\#adjust-颜色边界值计算import{ImageColorUtils}from'image-color-utils'constimageColorUtils=newImageColorUtils({origin:img,width:canvas.width,height:canvas.height,boundaryValue,mockMovePx})imageColorUtils.adjust(leftTopPosition,rightBottomPosition)ArgumentsNameDescTypeDefaultrequiredleftTopPosition初始坐标upperleftcorner[num]selectedleftTopPosition]falserightBottomPositionima选中区域右下角的初始坐标genumber[][]falseReturnsDescType边界计算后的左上角坐标(x,y)和区域宽高(width,height)Object:{x:number,y:number,width:number,height:number}\#compare-颜色值相似度比较import{ImageColorUtils}from'image-color-utils'constres=ImageColorUtils.compare(color1,color2,boundaryValue)ArgumentsNameDescTypeDefaultrequiredcolor1rgbcolorvalue1number[]-truecolor2rgbcolorvalue2number[]-trueboundaryValue颜色边界阈值(作用于颜色值相似性比较,阈值越高,相似性条件越高)number10falseReturnsDescTypesimilarboolean\#hex2rgb-HEX颜色值转换RGB颜色值import{ImageColorUtils}from'image-color-utils'constrgb=ImageColorUtils.hex2rgb(hex)ArgumentsNameDescTypeDefaultrequiredhexHEXcolorvalueString-trueReturnsDescTypeRGB颜色值number[]\#rgb2hex-RGB颜色值到HEX颜色值import{ImageColorUtils}from'image-color-utils'consthex=ImageColorUtils.rgb2hex(rgb)ArgumentsNameDescTypeDefaultrequiredrgbRGB颜色值number[]-trueReturnsDescTypeHEX颜色值stringAttributeimport{ImageColorUtils}from'image-color-utils'constimageColorUtils=newImageColorUtils,{width:canvas.width,高度:canvas.height,boundaryValue,mockMovePx})console.log(imageColorUtils.canvas)console.log(imageColorUtils.ctx)console.log(imageColorUtils.imageData)NameTypecanvasOffscreenCanvasctxOffscreenCanvasRenderingContext2DimageDataImage