handy-img

handy img tool and API

Usage no npm install needed!

<script type="module">
  import handyImg from 'https://cdn.skypack.dev/handy-img';
</script>

README

handy-img

handy img tool and API

Build Status Coverage Status npm version npm downloads npm license

Install

$ npm i -S handy-img

cli

just type himg or handy-img

$ himg
himg <命令>

命令:
  himg compress <file>  compress file                               [aliases: c]
  himg info <file>      show info for file                          [aliases: i]

选项:
  --version  显示版本号                                                   [布尔]
  --help     显示帮助信息                                                 [布尔]

缺少 non-option 参数:传入了 0 个, 至少需要 1 个

API

const himg = require('handy-img')

metadata(input) -> Promise<Object>

  • use sharp extract img metadata
  • input can be String filepath or Buffer buf

decode(input) -> Promise<ImageDataLike>

  • use sharp decode img
  • input can be String filepath or Buffer buf
  • ImageDataLike has signature
type ImageDataLike = {
  data: Uint8Array
  width: number
  height: number
}

mozjpegEncode

function mozjpegEncode(
  data: Uint8Array,
  width: number,
  height: number,
  options: Object
): Promise<Buffer>

encode the ImageData to compressed jpeg buffer

mozjpegCompress

type Input = string | Buffer
function mozjpegCompress(input: Input, options: Object): Promise<Buffer>

use mozjpeg to compress file

Changelog

CHANGELOG.md

License

the MIT License http://magicdawn.mit-license.org