# l-image

> 可以获取图片主体颜色 A set of ways to get the most contrasting colors in an image and commonly used image information

Latest version **1.1.0** (published 2023-06-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install l-image
pnpm add l-image
yarn add l-image
bun add l-image
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-06-28 |
| First published | 2023-03-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | liangjie |
| Maintainers | liangjie6810168 |
| Keywords | image, colors |

## Links

- npm: https://www.npmjs.com/package/l-image
- Repository: https://gitee.com/Liangjie_piao/l-image
- npm.io page: https://npm.io/package/l-image

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-06-28
- 1.0.0 — 2023-03-27

## README

# 项目说明（illustrate）
--------------------
这是一个简单的图片工具集，内置了一些图片与颜色相关的方法  

This is a simple picture toolset with some color-related methods for pictures built-in

## 引入

```javaScript
    import l-image from 'l-image'

    import {getMainColor} from 'l-image'
```
  
--------------------------
## getImg [获取图片信息]
```javaScript

/**
 * 获取图片信息
 * @param {*} url       String      图片地址
 * @returns             Image       {width,height,size(byte)...}
 */
import {getImg} from 'l-image'
getImg('http://xxxxx.jpg').then(res=>{
     // res = {width,height,size,...}
})  
```

## pxColor [像素点循环方法]

```javaScript
/**
 * 获取目标单个像素颜色
 * @param {*} url           String      图片地址
 * @param {
 *            width:        Number      缩放后宽度(数字越小速度越快，精准度越低)
 *            height:       Number      缩放后高度
 * }          option        
 * @param {*} pxEvent       Function    每个像素点回调
 * @param {*} endEvent      Function    完成后回调
 * @returns                 endEventReturn
 */
import {pxColor} from 'l-image'
pxColor('http://xxxx.jpg',{width: 50,height: 50}, res=>{
    //res = {x,y,r,g,b,i:像素下标}
},res=>{
    //res = {data: canvasImageData}
})
```

## getMainColor [获取图片主体颜色]

```javaScript
/**
 * 获取主体颜色
 * @param {*} url           String      图片地址
 * @param {
 *            width:        Number      缩放后宽度(数字越小速度越快，精准度越低)
 *            height:       Number      缩放后高度
 *            diff:         Number      差值(值越大，全局对比越大)
 * } 
 * @returns                 String      rgb(xxx,xxx,xxx)
 */
import {getMainColor} from 'l-image'
getMainColor('http://xxxx.jpg',{width: 50, height: 50, diff: 30}).then(res=>{
    // res = 'rgb(xxx,xxx,xxx)'
})
```

## sizeImg [获取等比缩放后图片尺寸]

```javaScript
/**
 * 缩放图片，减少计算量 
 * @param {
 *          width:          Number      图片原始宽度
 *          height:         Number      图片原始高度
 *          maxWidth:       Number      缩放后宽度   
 *          maxHeight       Number      缩放后高度
 * }
 * @returns 
 */
import {sizeImg} from 'l-image'
sizeImg({width: 1920,height: 1080, maxWidth: 500, maxHeight: 500}) // {width: 3413.333333333333, height: 500}
sizeImg({width: 200,height: 400, maxWidth: 500, maxHeight: 500}) // {width: 200, height: 400}
```

## rgbToHex[rgb颜色转换16进制颜色]
```javaScript
/**
 * rgb转换16进制颜色
 * @param {*} rgb           String      rgb颜色
 * @returns                 String      16进制颜色
 */
import {rgbToHex} from 'l-image'
rgbToHex('rgb(14,25,118)') // #0e1976
```

---
_Source: https://npm.io/package/l-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
