pica 6.1.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  pica - high quality image resize in browser
2
2
  ===========================================
3
3
 
4
- [![Build Status](https://travis-ci.org/nodeca/pica.svg?branch=master)](https://travis-ci.org/nodeca/pica)
4
+ [![CI](https://github.com/nodeca/pica/actions/workflows/ci.yml/badge.svg)](https://github.com/nodeca/pica/actions/workflows/ci.yml)
5
5
  [![NPM version](https://img.shields.io/npm/v/pica.svg)](https://www.npmjs.org/package/pica)
6
6
 
7
7
  > Resize images in browser without pixelation and reasonably fast.
@@ -20,7 +20,16 @@ With pica you can:
20
20
 
21
21
  **Note. If you need File/Blob resize (from form's file input), consider use
22
22
  [image-blob-reduce](https://github.com/nodeca/image-blob-reduce).** It has
23
- additional machinery to process orientation, keep EXIF metadata and so on.
23
+ additional machinery to process orientation, keep EXIF metadata and so on.
24
+
25
+
26
+ Migration from pica v6 to pica v7
27
+ ---------------------------------
28
+
29
+ Multiply `unsharpAmount` by 2, divide `unsharpThreshold` by 2, example:
30
+
31
+ - `pica@6`: `pica.resize(a, b, { unsharpAmount: 80, unsharpThreshold: 2 })`
32
+ - `pica@7`: `pica.resize(a, b, { unsharpAmount: 160, unsharpThreshold: 1 })`
24
33
 
25
34
 
26
35
  Prior to use
@@ -32,7 +41,7 @@ Here is a short list of problems you can face:
32
41
  - Due to JS security restrictions, you can process images
33
42
  from the same domain or local files only. If you load images from
34
43
  remote domain use proper `Access-Control-Allow-Origin` header.
35
- - iOS has a memory limits for canvas elements, that may cause
44
+ - iOS has a memory limits for canvas elements, that may cause
36
45
  problems in some cases, [more details](https://github.com/nodeca/pica/wiki/iOS-Memory-Limit).
37
46
  - If your source data is jpeg image, it can be rotated. Consider use
38
47
  [image-blob-reduce](https://github.com/nodeca/image-blob-reduce).
@@ -66,12 +75,8 @@ Use
66
75
  const pica = require('pica')();
67
76
 
68
77
  // Resize from Canvas/Image to another Canvas
69
- pica.resize(from, to, {
70
- unsharpAmount: 80,
71
- unsharpRadius: 0.6,
72
- unsharpThreshold: 2
73
- })
74
- .then(result => console.log('resize done!'));
78
+ pica.resize(from, to)
79
+ .then(result => console.log('resize done!'));
75
80
 
76
81
  // Resize & convert to blob
77
82
  pica.resize(from, to)
@@ -91,7 +96,8 @@ Create resizer instance with given config (optional):
91
96
  to restrict peak memory use. Default 1024.
92
97
  - __features__ - list of features to use. Default is
93
98
  `[ 'js', 'wasm', 'ww' ]`. Can be `[ 'js', 'wasm', 'cib', 'ww' ]`
94
- or `[ 'all' ]`.
99
+ or `[ 'all' ]`. Note, `cib` is buggy in Chrome and not supports default
100
+ `mks2013` filter.
95
101
  - __idle__ - cache timeout, ms. Webworkers create is not fast.
96
102
  This option allow reuse webworkers effectively. Default 2000.
97
103
  - __concurrency__ - max webworkers pool size. Default is autodetected
@@ -101,8 +107,8 @@ Create resizer instance with given config (optional):
101
107
  Default returns a [\<canvas\> element](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API),
102
108
  but this function could return an [OffscreenCanvas](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas)
103
109
  instead (to run pica in a Service Worker). Function signature: createCanvas(width: number, height: number): Canvas
104
-
105
-
110
+
111
+
106
112
  __Important!__ Latest browsers may support resize via [createImageBitmap](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap).
107
113
  This feature is supported (`cib`) but disabled by default and not recommended
108
114
  for use. So:
@@ -122,10 +128,12 @@ taken from source and destination objects.
122
128
  - __from__ - source, can be `Canvas`, `Image` or `ImageBitmap`.
123
129
  - __to__ - destination canvas, its size is supposed to be non-zero.
124
130
  - __options__ - quality (number) or object:
125
- - __quality__ - 0..3. Default = `3` (lanczos, win=3).
131
+ - __quality__ (deprecated, use `.filter` instead) - 0..3.
132
+ - __filter__ - filter name (Default - `mks2013`). See [resize_filter_info.js](https://github.com/nodeca/pica/blob/master/lib/mm_resize/resize_filter_info.js) for details. `mks2013` does both resize and sharpening, it's optimal and not recommended to change.
126
133
  - __alpha__ - use alpha channel. Default = `false`.
127
- - __unsharpAmount__ - >=0, in percents. Default = `0` (off). Usually
128
- between 50 to 100 is good.
134
+ - __unsharpAmount__ - >=0. Default = `0` (off). Usually
135
+ value between 100 to 200 is good. Note, `mks2013` filter already does
136
+ optimal sharpening.
129
137
  - __unsharpRadius__ - 0.5..2.0. By default it's not set. Radius of Gaussian
130
138
  blur. If it is less than 0.5, Unsharp Mask is off. Big values are clamped
131
139
  to 2.0.
@@ -161,10 +169,12 @@ binary data (for example, if you decode jpeg files "manually").
161
169
  - __height__ - src image height.
162
170
  - __toWidth__ - output width, >=0, in pixels.
163
171
  - __toHeight__ - output height, >=0, in pixels.
164
- - __quality__ - 0..3. Default = `3` (lanczos, win=3).
172
+ - __quality__ (deprecated, use `.filter` instead) - 0..3.
173
+ - __filter__ - filter name (Default - `mks2013`). See [resize_filter_info.js](https://github.com/nodeca/pica/blob/master/lib/mm_resize/resize_filter_info.js) for details. `mks2013` does both resize and sharpening, it's optimal and not recommended to change.
165
174
  - __alpha__ - use alpha channel. Default = `false`.
166
- - __unsharpAmount__ - >=0, in percents. Default = `0` (off).
167
- Usually between 50 to 100 is good.
175
+ - __unsharpAmount__ - >=0. Default = `0` (off). Usually
176
+ value between 100 to 200 is good. Note, `mks2013` filter already does
177
+ optimal sharpening.
168
178
  - __unsharpRadius__ - 0.5..2.0. Radius of Gaussian blur.
169
179
  If it is less than 0.5, Unsharp Mask is off. Big values are
170
180
  clamped to 2.0.
@@ -198,10 +208,10 @@ a bit. Pica has built-in "unsharp mask" filter (off by default).
198
208
  Set `unsharpAmount` to positive number to activate the filter.
199
209
 
200
210
  Filter's parameters are similar to ones from Photoshop.
201
- We recommend to start with `unsharpAmount = 80`,
202
- `unsharpRadius = 0.6` and `unsharpThreshold = 2`.
211
+ We recommend to start with `unsharpAmount = 160`,
212
+ `unsharpRadius = 0.6` and `unsharpThreshold = 1`.
203
213
  There is [a correspondence between UnsharpMask parameters
204
- in popular graphics software](https://github.com/nodeca/pica/wiki#editing-unsharp-mask-params-relations-in-pupular-softare).
214
+ in popular graphics software](https://github.com/nodeca/pica/wiki/Unsharp-mask-params-in-popular-softare).
205
215
 
206
216
 
207
217
  Browser support