# webp



#### Convertisseurs:

- Photoshop 23.2 +
- XnConvert 
- WebPShop
- [cwebp](#cwebp)
- [squoosh-cli](#squoosh)
- [ImageMagick](#ImageMagick)
- WebpConvert



### <a id="cwebp"></a>cwebp

Doc: https://developers.google.com/speed/webp/docs/cwebp

App: https://developers.google.com/speed/webp/docs/precompiled

#### Installation:

```bash
$ brew install webp
```

#### Aide:

```bash
❯ cwebp -longhelp
Usage:
 cwebp [-preset <...>] [options] in_file [-o out_file]

If input size (-s) for an image is not specified, it is
assumed to be a PNG, JPEG, TIFF or WebP file.
Note: Animated PNG and WebP files are not supported.

Options:
  -h / -help ............. short help
  -H / -longhelp ......... long help
  -q <float> ............. quality factor (0:small..100:big), default=75
  -alpha_q <int> ......... transparency-compression quality (0..100),
                           default=100
  -preset <string> ....... preset setting, one of:
                            default, photo, picture,
                            drawing, icon, text
     -preset must come first, as it overwrites other parameters
  -z <int> ............... activates lossless preset with given
                           level in [0:fast, ..., 9:slowest]

  -m <int> ............... compression method (0=fast, 6=slowest), default=4
  -segments <int> ........ number of segments to use (1..4), default=4
  -size <int> ............ target size (in bytes)
  -psnr <float> .......... target PSNR (in dB. typically: 42)

  -s <int> <int> ......... input size (width x height) for YUV
  -sns <int> ............. spatial noise shaping (0:off, 100:max), default=50
  -f <int> ............... filter strength (0=off..100), default=60
  -sharpness <int> ....... filter sharpness (0:most .. 7:least sharp), default=0
  -strong ................ use strong filter instead of simple (default)
  -nostrong .............. use simple filter instead of strong
  -sharp_yuv ............. use sharper (and slower) RGB->YUV conversion
  -partition_limit <int> . limit quality to fit the 512k limit on
                           the first partition (0=no degradation ... 100=full)
  -pass <int> ............ analysis pass number (1..10)
  -qrange <min> <max> .... specifies the permissible quality range
                           (default: 0 100)
  -crop <x> <y> <w> <h> .. crop picture with the given rectangle
  -resize <w> <h> ........ resize picture (after any cropping)
  -mt .................... use multi-threading if available
  -low_memory ............ reduce memory usage (slower encoding)
  -map <int> ............. print map of extra info
  -print_psnr ............ prints averaged PSNR distortion
  -print_ssim ............ prints averaged SSIM distortion
  -print_lsim ............ prints local-similarity distortion
  -d <file.pgm> .......... dump the compressed output (PGM file)
  -alpha_method <int> .... transparency-compression method (0..1), default=1
  -alpha_filter <string> . predictive filtering for alpha plane,
                           one of: none, fast (default) or best
  -exact ................. preserve RGB values in transparent area, default=off
  -blend_alpha <hex> ..... blend colors against background color
                           expressed as RGB values written in
                           hexadecimal, e.g. 0xc0e0d0 for red=0xc0
                           green=0xe0 and blue=0xd0
  -noalpha ............... discard any transparency information
  -lossless .............. encode image losslessly, default=off
  -near_lossless <int> ... use near-lossless image
                           preprocessing (0..100=off), default=100
  -hint <string> ......... specify image characteristics hint,
                           one of: photo, picture or graph

  -metadata <string> ..... comma separated list of metadata to
                           copy from the input to the output if present.
                           Valid values: all, none (default), exif, icc, xmp

  -short ................. condense printed message
  -quiet ................. don't print anything
  -version ............... print version number and exit
  -noasm ................. disable all assembly optimizations
  -v ..................... verbose, e.g. print encoding/decoding times
  -progress .............. report encoding progress

Experimental Options:
  -jpeg_like ............. roughly match expected JPEG size
  -af .................... auto-adjust filter strength
  -pre <int> ............. pre-processing filter
```



#### Usage:

```bash
$ cwebp -q 90 image.png -o image.webp
```

```bash
for infile in Screenshot*.png
do
    echo $infile
    base=$(basename "$infile" .png)
    cwebp -preset picture -v "$infile" -o "$base".webp
done
```

```bash
$ cwebp png/2022-04-16_Brocard_8990_8b.png -q 75 -mt -o cwebp/2022-04-16_Brocard_8990_8b_q75.webp

$ cwebp png/2022-04-16_Brocard_8990_8b.png -preset photo -mt -o cwebp/2022-04-16_Brocard_8990_8b_preset-photo.webp
```

```bash
# lossless

$ cwebp png/2022-04-16_Brocard_8990_8b.png -z 9 -mt -o cwebp/2022-04-16_Brocard_8990_8b.webp

$ cwebp png/2022-04-16_Brocard_8990_8b.png -lossless -m 6 -q 100 -mt -o cwebp/2022-04-16_Brocard_8990_8b.webp
```



### <a id="squoosh"></a>[squoosh-cli](https://www.npmjs.com/package/@squoosh/cli)

Supporte mozjpeg, webp, avif, jxl, wp2

Les options sont visibles dans [codecs.ts](https://github.com/GoogleChromeLabs/squoosh/blob/dev/libsquoosh/src/codecs.ts)

#### Installation:

```bash
$ npm i -g @squoosh/cli
```

#### Usage:

```bash
Usage: squoosh-cli [options] <files...>

Options:
  -d, --output-dir <dir>                                 Output directory (default: ".")
  -s, --suffix <suffix>                                  Append suffix to output files (default: "")
  --max-optimizer-rounds <rounds>                        Maximum number of compressions to use for auto optimizations (default: "6")
  --optimizer-butteraugli-target <butteraugli distance>  Target Butteraugli distance for auto optimizer (default: "1.4")
  --resize [config]                                      Resize the image before compressing
  --quant [config]                                       Reduce the number of colors used (aka. paletting)
  --rotate [config]                                      Rotate image
  --mozjpeg [config]                                     Use MozJPEG to generate a .jpg file with the given configuration
  --webp [config]                                        Use WebP to generate a .webp file with the given configuration
  --avif [config]                                        Use AVIF to generate a .avif file with the given configuration
  --jxl [config]                                         Use JPEG-XL to generate a .jxl file with the given configuration
  --wp2 [config]                                         Use WebP2 to generate a .wp2 file with the given configuration
  --oxipng [config]                                      Use OxiPNG to generate a .png file with the given configuration
  -h, --help                                             display help for command
```

```bash
❯ squoosh-cli --webp true -d webp ./2022-04-28_Biche_8247_8b.png
1/1 ✔ Squoosh results:
 ./2022-04-28_Biche_8247_8b.png: 2.18MB
  └ webp/2022-04-28_Biche_8247_8b.webp → 75.00KB (3.37%)
```

```bash
❯ squoosh-cli --output-dir 'squoosh-cli' --webp '{
  	"quality":75,
    "target_size":0,
    "target_PSNR":0,
    "method":4,
    "sns_strength":50,
    "filter_strength":60,
    "filter_sharpness":0,
    "filter_type":1,
    "partitions":0,
    "segments":4,
    "pass":1,
    "show_compressed":0,
    "preprocessing":0,
    "autofilter":0,
    "partition_limit":0,
    "alpha_compression":1,
    "alpha_filtering":1,
    "alpha_quality":100,
    "lossless":0,
    "exact":0,
    "image_hint":0,
    "emulate_jpeg_size":0,
    "thread_level":0,
    "low_memory":0,
    "near_lossless":100,
    "use_delta_palette":0,
    "use_sharp_yuv":0
    }' png/*.png 
```



### <a id="ImageMagick"></a>ImageMagick

[Webp options](https://imagemagick.org/script/webp.php).

[-define](https://imagemagick.org/script/defines.php) command-line option.

[Command-line tools](https://imagemagick.org/script/command-line-tools.php)

[Command-line Options](https://imagemagick.org/script/command-line-options.php#quality)

#### Usage:

```bash
❯ magick -quality 75 png/2022-04-16_Brocard_8990_8b.png magick/2022-04-16_Brocard_8990_8b.webp

❯ magick -define heic:speed=2 png/2022-04-16_Brocard_8990_8b.png magick/2022-04-16_Brocard_8990_8b_2.webp

❯ convert -define heic:speed=2 png/2022-04-16_Brocard_8990_8b.png magick/2022-04-16_Brocard_8990_8b_2.webp
```

```bash
magick png/2022-04-16_Brocard_8990_8b.png -quality 50 -define webp:lossless=true png/2022-04-16_Brocard_8990_8b_ll-true.webp

magick png/2022-04-16_Brocard_8990_8b.png -quality 90 -define webp:lossless=false  png/2022-04-16_Brocard_8990_8b_ll-false.webp
```



### [WebpConvert](https://github.com/rizqirizqi/webpconvert)

#### Installation:

```bash
$ npm install -g webpconvert
```

#### Options:

```bash
  -p, --prefix   Specify the prefix of output filename.  [chaîne de caractères] [défaut : ""]
  -s, --suffix   Specify the suffix of output filename.  [chaîne de caractères] [défaut : ""]
  -q, --quality  Specify the quality of webp image. Lower values yield better compression but the least image quality.  [nombre] [défaut : 80]
  -m, --mute     Disable output messages.  [booléen] [défaut : false]
  -h, --help     Affiche l'aide  [booléen]
  -v, --version  Affiche le numéro de version  [booléen]
```

#### Usage:

```bash
❯ webpconvert -q 80 --suffix="webpconvert-q80" png/2022-05-10_Cerf_8817_8b.png webpconvert/2022-05-10_Cerf_8817_8b.webp

❯ webpconvert -q 80 --suffix="webpconvert-q80" png/ webpconvert/
```

