0.8.0 • Published 4 months ago

handy-img v0.8.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 months ago

handy-img

handy img tool and API

Build Status Coverage Status npm version npm downloads npm license

compress Features

  • target mozjpeg / webp are supported. @squoosh/cli supports more format.
  • Node.js native addon, better performance than squoosh WASM version.
  • batch process, support --files glob or dir mode --dir
  • parallel compress. set your UV_THREADPOOL_SIZE=64 (see this) and handy-img will use this as concurrency.

Install

$ pnpm add -g handy-img

or invoke without install

# pnpm, recommend
pnpm dlx handy-img
# or yarn 2
yarn dlx handy-img

# or npx/pnpx
npx handy-img
pnpx 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 个

himg compress or himg c

$ himg c -h
Compress img

$ handy-img compress

━━━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  -f,--files #0                files as input
  --ignore-case                ignore case for -f,--files, default true
  --glob-cwd #0                cwd used in glob
  -t,--tokens,--show-tokens    show available tokens
  -o,--output #0               output patterns
  --codec #0                   Allowed codec: `mozjpeg` or `webp`
  --metadata                   keep metadata(only available with --codec webp)
  -q,--quality #0              quality
  -d,--dir #0                  compress whole dir, and output to dir_compressed
  --dir-suffix #0              suffix to append to original dir name when using -d,--dir mode
  -y,--yes                     exec commands, default false(only preview commands, aka dry run)

flags

flagdescdefaultremark
-f,--filesspecify input,glob supported, see globby & fast-glob
--ignore-caseignore case when glob inputtrue
--glob-cwdcwd of -f,--files providedpwd
-t,--tokens,--show-tokensshow available tokenshelp you to decide the -o,--output flag, see below
-o,--outputoutput pattern
--codecAllowed codec: mozjpeg or webp or mozjpeg-rawmozjpeg
--metadatakeep metadata(not available with --codec mozjpeg-raw)truekeep exif data
-q,--qualityquality80encode quality, 0-100
-d,--dircompress whole dir, and output to dir_compressed
--dir-suffixsuffix to append to original dir name when using -d,--dir mode_compressed
-O,--other,--other-fileshow to handle other files in dir modemove or copy none img files to newly created dir
-y,--yesexec commands, default false(only preview commands, aka dry run)false

Usage

-d, use dir mode

himg c -d ./your-dir-here -y

glob all imgs in the dir you provided, and output to a new directory, which name is original name + dir suffix and img will keep same structure.

# example
himg c -d dir -q 85 -y

image

about -y,--yes

without this option, you will see what input will be processed and what file will be generated. but the compress action will not really execute. aka dry run.

--------------------------------------------------------------------------------
  current previewing commands. After comfirmed, append -y or --yes flag to execute
--------------------------------------------------------------------------------

it's like a safety guard for a gun

-f,--files, single or multiple files

1.decide input

image

2.then use -t,--tokens,--show-tokens show available tokens

image

3.write your output pattern & preview

example pattern himg c -f './*.jpg' -t -o ':dir/:name_compressed.:ext' image

example pattern himg c -f './*.jpg' -t -o ':dir/compressed/:name.:ext' image

4.use -y,--yes to execute

Which codec & quality should I choose ?

See

Changelog

CHANGELOG.md

License

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