mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 13:46:19 +01:00
Compare commits
1503 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcb22af034 | ||
|
|
d04dc62666 | ||
|
|
c30d355f97 | ||
|
|
49cb148b38 | ||
|
|
3bc31a8b20 | ||
|
|
c28523e70e | ||
|
|
278f393f74 | ||
|
|
cbf68c1395 | ||
|
|
45e8071599 | ||
|
|
b96389d975 | ||
|
|
a77ac6ae25 | ||
|
|
9bcf399b4c | ||
|
|
4aacee8055 | ||
|
|
0b18aeff62 | ||
|
|
bed1c2ac18 | ||
|
|
8cd832656b | ||
|
|
0499f59e71 | ||
|
|
1fa59bf9b3 | ||
|
|
db40ee6912 | ||
|
|
02b98b8e1b | ||
|
|
31fef216e4 | ||
|
|
77ab5d7a51 | ||
|
|
cd5cf7ce2d | ||
|
|
39cb9d9a6c | ||
|
|
4919bc5134 | ||
|
|
a4e64eb01f | ||
|
|
328b18df88 | ||
|
|
5e7bf32e5e | ||
|
|
04403f4e5f | ||
|
|
420e0822b4 | ||
|
|
f7a3ea6415 | ||
|
|
f28e79ef4f | ||
|
|
5cd787bf85 | ||
|
|
021d637fd6 | ||
|
|
2e14096af7 | ||
|
|
fe2b298a2f | ||
|
|
c9e3996007 | ||
|
|
3a0c375692 | ||
|
|
c5eaeb2ddb | ||
|
|
19fa4cd1d3 | ||
|
|
0adf7ef16f | ||
|
|
8f7fb96a44 | ||
|
|
9e3b021b1a | ||
|
|
25164d4cef | ||
|
|
516b1ec332 | ||
|
|
95ba045a69 | ||
|
|
6e02f9288e | ||
|
|
a584ae093e | ||
|
|
1592f96b7b | ||
|
|
004fff975f | ||
|
|
4d049ee8f5 | ||
|
|
c80e92fa16 | ||
|
|
545e09fad2 | ||
|
|
133dc56ff4 | ||
|
|
9c877d93fa | ||
|
|
7ad86fed03 | ||
|
|
31cf07f0ba | ||
|
|
4ffb48711a | ||
|
|
3da96a86e6 | ||
|
|
45ed9ea9bf | ||
|
|
61057f25bc | ||
|
|
68ef72cb61 | ||
|
|
ef32dccb83 | ||
|
|
e78200cc84 | ||
|
|
3f7313d031 | ||
|
|
139e4b9f65 | ||
|
|
9680f00ddd | ||
|
|
0b0ebfe6f8 | ||
|
|
5aadb8294c | ||
|
|
ace1681886 | ||
|
|
75ef61a958 | ||
|
|
2dba5b5451 | ||
|
|
a8f68ba7f0 | ||
|
|
475bf16b09 | ||
|
|
67f49a8dcd | ||
|
|
074004392c | ||
|
|
8c5a493f68 | ||
|
|
cccd1635c5 | ||
|
|
1915c1387e | ||
|
|
4a37a27cca | ||
|
|
ab8a4ed532 | ||
|
|
12fd512b83 | ||
|
|
239435a6dc | ||
|
|
7c1551bdc9 | ||
|
|
bdcf02695f | ||
|
|
d206fd5392 | ||
|
|
0bd1715f36 | ||
|
|
2e7c60675b | ||
|
|
7caaa8e22b | ||
|
|
839c92bf3d | ||
|
|
28aa176957 | ||
|
|
0f24f0f214 | ||
|
|
655da113c8 | ||
|
|
159b986cdd | ||
|
|
069d1786f5 | ||
|
|
f43829a16a | ||
|
|
65e61ad001 | ||
|
|
0107a4de81 | ||
|
|
337ce7b1c2 | ||
|
|
3719f79065 | ||
|
|
8d1747aa6a | ||
|
|
de9bdcba0a | ||
|
|
f8b6cb6d5b | ||
|
|
e6942805b4 | ||
|
|
47e76c9981 | ||
|
|
68fa84ef6f | ||
|
|
ff2fb18c76 | ||
|
|
28a9b1e9fa | ||
|
|
6377d5a73a | ||
|
|
80e4707af1 | ||
|
|
ab00e34d0d | ||
|
|
7c2f883b67 | ||
|
|
9b5eecba8f | ||
|
|
4b028edfe9 | ||
|
|
7e25dd7be1 | ||
|
|
09460d7af4 | ||
|
|
3b22640077 | ||
|
|
946976ba8f | ||
|
|
29a83250a4 | ||
|
|
3f54ef7525 | ||
|
|
4dc2467f49 | ||
|
|
f54ceb0973 | ||
|
|
8d033ae341 | ||
|
|
f7da2e5970 | ||
|
|
51e56f994c | ||
|
|
68ac12292c | ||
|
|
a9aa7339ce | ||
|
|
08108f5fad | ||
|
|
58e3c4c70e | ||
|
|
f8cf25ca56 | ||
|
|
ca95979ecc | ||
|
|
392f6afb5e | ||
|
|
7c97aabaf8 | ||
|
|
fcc7e84bee | ||
|
|
226a9a13ef | ||
|
|
4d3c9ae3d1 | ||
|
|
f31011d759 | ||
|
|
7cf4ae5648 | ||
|
|
9161c605e1 | ||
|
|
70ac6905c7 | ||
|
|
265d70111a | ||
|
|
59327bdd53 | ||
|
|
3043e01171 | ||
|
|
36feb7551b | ||
|
|
a41c62be2b | ||
|
|
854ed65016 | ||
|
|
8f63d131a4 | ||
|
|
70a3067963 | ||
|
|
aabbe1fa08 | ||
|
|
0f8bb9196e | ||
|
|
efee9f1779 | ||
|
|
61c5cb4669 | ||
|
|
e618c17bd0 | ||
|
|
6578118f32 | ||
|
|
ba20b8ada4 | ||
|
|
eefaa99872 | ||
|
|
dbce6fab79 | ||
|
|
af0fcb37c2 | ||
|
|
c6f54e59da | ||
|
|
846563e45f | ||
|
|
9c217ab580 | ||
|
|
e7381e522e | ||
|
|
4340d60ccf | ||
|
|
7f64d464de | ||
|
|
67e927bdb6 | ||
|
|
9c7713ed54 | ||
|
|
8be6da1def | ||
|
|
95635683ac | ||
|
|
44a0ee3fd3 | ||
|
|
ccd51c8cbf | ||
|
|
bb7469b2d1 | ||
|
|
a2cac61209 | ||
|
|
5c19f6dd9b | ||
|
|
3d01775972 | ||
|
|
87562a5111 | ||
|
|
2829e17743 | ||
|
|
ffefbd2ecc | ||
|
|
bc8f983329 | ||
|
|
440936a699 | ||
|
|
0bc79cdb95 | ||
|
|
9a66e25f53 | ||
|
|
8370935ccf | ||
|
|
f908987f35 | ||
|
|
aea368a3a0 | ||
|
|
7ecbc20d3d | ||
|
|
cb0e2a91c4 | ||
|
|
739b317a6f | ||
|
|
a0e1c39785 | ||
|
|
85b26dab68 | ||
|
|
66f7cef253 | ||
|
|
863174f201 | ||
|
|
bcd865cc96 | ||
|
|
16ea04fe80 | ||
|
|
9c547dc321 | ||
|
|
5522060e9e | ||
|
|
d2f0fa855b | ||
|
|
2bb3ea8170 | ||
|
|
3434eef5b9 | ||
|
|
2f67823c3d | ||
|
|
38c760cdd7 | ||
|
|
14c3346800 | ||
|
|
0da55bab7e | ||
|
|
cfb659f576 | ||
|
|
cc5ac5385f | ||
|
|
93fafb0c18 | ||
|
|
41e3c8ca09 | ||
|
|
da61ea0199 | ||
|
|
7e6a70af44 | ||
|
|
f5845c7e61 | ||
|
|
eb1e53db83 | ||
|
|
3340120aea | ||
|
|
de0fc07092 | ||
|
|
dc4b39f73f | ||
|
|
e873978e53 | ||
|
|
5255964c79 | ||
|
|
dea319daf6 | ||
|
|
a2ca678854 | ||
|
|
e98993a6e2 | ||
|
|
90abd927c9 | ||
|
|
4d7957a043 | ||
|
|
bf9bb56367 | ||
|
|
8408e99aa3 | ||
|
|
a39f959dcc | ||
|
|
d08baa20e6 | ||
|
|
391018ad3d | ||
|
|
afed876f90 | ||
|
|
d6b60a60c6 | ||
|
|
5f8646d937 | ||
|
|
b763801d68 | ||
|
|
2e0f789c9b | ||
|
|
a8645f0f38 | ||
|
|
7b58ad9360 | ||
|
|
9ebbcc3701 | ||
|
|
e87204b92c | ||
|
|
a4c6eba7d4 | ||
|
|
b9c3851515 | ||
|
|
97cf69c26a | ||
|
|
d5be024bfd | ||
|
|
de01fc44e7 | ||
|
|
ca102ebd6c | ||
|
|
b9d4c30a9f | ||
|
|
148760fe55 | ||
|
|
98ed237734 | ||
|
|
b55e58f31e | ||
|
|
0af070ed93 | ||
|
|
9fbb4fcaef | ||
|
|
6008ff8a08 | ||
|
|
cd5e11bd50 | ||
|
|
08d6822265 | ||
|
|
8b8a815fbb | ||
|
|
a44da850c1 | ||
|
|
c5ef4677b1 | ||
|
|
f8a430bdd3 | ||
|
|
cd419a261b | ||
|
|
d7776e3b98 | ||
|
|
1eefd4e562 | ||
|
|
0a16d26ec7 | ||
|
|
fc03fba602 | ||
|
|
c87fe512b4 | ||
|
|
2eaab59c48 | ||
|
|
4ec883eaa0 | ||
|
|
0063df4d4f | ||
|
|
6c61ad256f | ||
|
|
b90474affa | ||
|
|
34cbc6dec3 | ||
|
|
bb8de0cc26 | ||
|
|
863e37455a | ||
|
|
6f0e6f2e65 | ||
|
|
ebf4ccd124 | ||
|
|
b96c8e8ba4 | ||
|
|
42d2f07e44 | ||
|
|
a2988c9edc | ||
|
|
24b3344937 | ||
|
|
9608f219bd | ||
|
|
4798d9da64 | ||
|
|
8d8c6b70eb | ||
|
|
9e2207f376 | ||
|
|
802f560b9b | ||
|
|
a532659b0f | ||
|
|
25c6da2bcd | ||
|
|
02f855d57a | ||
|
|
c150263ef1 | ||
|
|
9f79f80a93 | ||
|
|
069803b83d | ||
|
|
f79760b4f2 | ||
|
|
aa5f0f4e40 | ||
|
|
286a322622 | ||
|
|
6d404f4d2c | ||
|
|
bdc50e1d6e | ||
|
|
a9bd0e79f8 | ||
|
|
a1e464cc5e | ||
|
|
081debd055 | ||
|
|
ef849fd639 | ||
|
|
a42a975c46 | ||
|
|
e8273580af | ||
|
|
5be36c2deb | ||
|
|
6cda090ce2 | ||
|
|
eac6e8b261 | ||
|
|
844deaf480 | ||
|
|
efbb0c22fd | ||
|
|
da0b594900 | ||
|
|
78dada9126 | ||
|
|
15f5cd4671 | ||
|
|
9eb2e94404 | ||
|
|
e40b068628 | ||
|
|
2c46528269 | ||
|
|
584807b4f5 | ||
|
|
a7fa7014ef | ||
|
|
f92e33fbff | ||
|
|
0f1e7ef6f6 | ||
|
|
89e204d824 | ||
|
|
2a71f1830f | ||
|
|
def99a294a | ||
|
|
9d760f3958 | ||
|
|
0265d305fe | ||
|
|
a472aea025 | ||
|
|
01ffa80338 | ||
|
|
789d4851ea | ||
|
|
4490a93430 | ||
|
|
ac0dc10bd5 | ||
|
|
5740f4545e | ||
|
|
a9d692fb43 | ||
|
|
df971207b8 | ||
|
|
3a64a0529a | ||
|
|
76cda885fb | ||
|
|
1a563360c6 | ||
|
|
ca22af203f | ||
|
|
9fa516e849 | ||
|
|
12f472126d | ||
|
|
18be09f1d7 | ||
|
|
b3c3290f90 | ||
|
|
123f95c85a | ||
|
|
5b0fba4c01 | ||
|
|
37f7ccfff4 | ||
|
|
51811d06e2 | ||
|
|
181731f8f4 | ||
|
|
ae79d26ead | ||
|
|
eacb8337fa | ||
|
|
99bf279de8 | ||
|
|
1b0eb6ab53 | ||
|
|
891cf67d0b | ||
|
|
eaf8a86bf2 | ||
|
|
3400976d61 | ||
|
|
2d49f0e93e | ||
|
|
b0c69f1ee9 | ||
|
|
27d0c35a01 | ||
|
|
32a22b5420 | ||
|
|
d1004eed02 | ||
|
|
70e6bb0162 | ||
|
|
32aa3b4b20 | ||
|
|
df24b30755 | ||
|
|
4de74bea94 | ||
|
|
28b87db760 | ||
|
|
fbd4970b57 | ||
|
|
f5da147a58 | ||
|
|
eee0dd36d9 | ||
|
|
f7b29d7b59 | ||
|
|
0b806187fc | ||
|
|
c1393daa70 | ||
|
|
31c1cfb049 | ||
|
|
afc35c2208 | ||
|
|
6eb2add3bf | ||
|
|
5cdb2b83d5 | ||
|
|
1eb66c0944 | ||
|
|
55c4d8807c | ||
|
|
9a54a034e1 | ||
|
|
f5109560d6 | ||
|
|
953a94885b | ||
|
|
0e3bd46ca3 | ||
|
|
4b38f56d02 | ||
|
|
0fe857c5ac | ||
|
|
1bf06bd5b4 | ||
|
|
6e3f4c3c92 | ||
|
|
8583eb1235 | ||
|
|
c3a852eecf | ||
|
|
3a44748f49 | ||
|
|
e1bc8674fd | ||
|
|
a618ce7a15 | ||
|
|
a44168c8c7 | ||
|
|
74e3f73934 | ||
|
|
b9261c243c | ||
|
|
cc9f91f37c | ||
|
|
212a6e7519 | ||
|
|
e547eaa180 | ||
|
|
9a0d9eed74 | ||
|
|
dd56a9699e | ||
|
|
ea7cf2a2ef | ||
|
|
76c4c51e2a | ||
|
|
b46ab510da | ||
|
|
3e327a586c | ||
|
|
974fab946e | ||
|
|
f998a8f249 | ||
|
|
be331e958e | ||
|
|
254944f8ab | ||
|
|
f1e640d231 | ||
|
|
c295f06a6f | ||
|
|
6288c7bced | ||
|
|
d247c02762 | ||
|
|
1b84ccbbe9 | ||
|
|
e4160c684d | ||
|
|
905518fab0 | ||
|
|
8ff33763ce | ||
|
|
cbf741cac7 | ||
|
|
6c2e2be41d | ||
|
|
e0d3c6e05d | ||
|
|
e3cab7f10f | ||
|
|
204463ffbb | ||
|
|
1bcd3700c5 | ||
|
|
c99a11cff5 | ||
|
|
81c74f57e0 | ||
|
|
7a8ab452c5 | ||
|
|
bb91912883 | ||
|
|
afc4c5bf79 | ||
|
|
e40a881ab4 | ||
|
|
c1b13adac3 | ||
|
|
29e09898f7 | ||
|
|
853a20358e | ||
|
|
8bb30d7801 | ||
|
|
a333b87f5d | ||
|
|
4662527a17 | ||
|
|
b10d8f89ca | ||
|
|
f903e1465e | ||
|
|
a75718565c | ||
|
|
4d82331bf6 | ||
|
|
b91875d3d9 | ||
|
|
a0568ec0c3 | ||
|
|
48e3ea5e29 | ||
|
|
93b29057e4 | ||
|
|
db654de385 | ||
|
|
a6aeef612b | ||
|
|
7bf6cbd669 | ||
|
|
04c31b35a7 | ||
|
|
ee9cdb6598 | ||
|
|
8960eb8309 | ||
|
|
54d9dc46f5 | ||
|
|
51b4a7c564 | ||
|
|
5b03579e5c | ||
|
|
58c2af3251 | ||
|
|
ee948ac6fa | ||
|
|
66a3ce5e55 | ||
|
|
75e5afcd42 | ||
|
|
d396a4e65d | ||
|
|
ae1dbcdf4e | ||
|
|
4c29368b51 | ||
|
|
36e55969d2 | ||
|
|
985e881e7a | ||
|
|
0b116715aa | ||
|
|
9deac83322 | ||
|
|
5d36f5f699 | ||
|
|
926572b41e | ||
|
|
d0c8e95641 | ||
|
|
b0ca23c3e7 | ||
|
|
c3a0d5f5d0 | ||
|
|
1d36936954 | ||
|
|
b609df4b48 | ||
|
|
c567d3b9ab | ||
|
|
27d9fe2a4e | ||
|
|
ac883c5215 | ||
|
|
e8720c9374 | ||
|
|
42e45d842a | ||
|
|
72fd8abe2c | ||
|
|
ac18bbbc7c | ||
|
|
fcbe4e1e01 | ||
|
|
9280742385 | ||
|
|
7a1a1cf9e8 | ||
|
|
ea599ade10 | ||
|
|
1de49f3ed8 | ||
|
|
4ac65054bc | ||
|
|
23033e2050 | ||
|
|
dd3b78272a | ||
|
|
80d169b7c2 | ||
|
|
003279a0b0 | ||
|
|
af80d7e389 | ||
|
|
21a960796c | ||
|
|
fc3b4a683d | ||
|
|
808133e7dc | ||
|
|
801b6fea6c | ||
|
|
c2ecde6a16 | ||
|
|
55efe5602b | ||
|
|
c62002554b | ||
|
|
7f83ecd255 | ||
|
|
dc5f4dcd28 | ||
|
|
735793ba99 | ||
|
|
47792df689 | ||
|
|
5c6cdfaece | ||
|
|
115a6b10f6 | ||
|
|
4feee506cf | ||
|
|
83db5f8a2a | ||
|
|
7eb5efa3a3 | ||
|
|
5a9f89fe06 | ||
|
|
02e0c2dfc9 | ||
|
|
968d9d7008 | ||
|
|
7faacd91b0 | ||
|
|
154eaff4ec | ||
|
|
424660278d | ||
|
|
2b01951306 | ||
|
|
83bb6a4554 | ||
|
|
c72d42816d | ||
|
|
35a81a7af2 | ||
|
|
9dc8db4370 | ||
|
|
47ae1f52db | ||
|
|
ec17d7f580 | ||
|
|
da5453a7c0 | ||
|
|
f7bed69ffb | ||
|
|
7aa340232e | ||
|
|
68823a5edb | ||
|
|
1c3ba303ea | ||
|
|
76f8112952 | ||
|
|
24150eac89 | ||
|
|
51121a1440 | ||
|
|
3b370b6c01 | ||
|
|
884947a069 | ||
|
|
f8340e1a82 | ||
|
|
5101f4e79c | ||
|
|
161d127bf3 | ||
|
|
638d540371 | ||
|
|
d8f1298511 | ||
|
|
d67e09ba7c | ||
|
|
4c3a8a7007 | ||
|
|
92399ee5e2 | ||
|
|
96992845ed | ||
|
|
2b8e4d20de | ||
|
|
dd6583044b | ||
|
|
446e4e3c3a | ||
|
|
3b492ea423 | ||
|
|
3da258f6fb | ||
|
|
9755629cfd | ||
|
|
5bb6702717 | ||
|
|
8c0660d71e | ||
|
|
513fb40f40 | ||
|
|
659cdabd8e | ||
|
|
add4c7928f | ||
|
|
336856dfc2 | ||
|
|
e1ba2a7fd8 | ||
|
|
2b1f5cbe07 | ||
|
|
72025051c5 | ||
|
|
140eeebb3d | ||
|
|
407bfcb42a | ||
|
|
549219f32a | ||
|
|
afab0d34dd | ||
|
|
2deced0fb9 | ||
|
|
2a0077c481 | ||
|
|
f7f3e43490 | ||
|
|
b876abaf88 | ||
|
|
dcd9a3c558 | ||
|
|
a06b8c296a | ||
|
|
602f988aba | ||
|
|
079bd7b9f5 | ||
|
|
1ff84b20b7 | ||
|
|
97655d2dfd | ||
|
|
d10d7b02d4 | ||
|
|
2ffdae2914 | ||
|
|
342de36973 | ||
|
|
b33231d4bd | ||
|
|
319db21f29 | ||
|
|
d359331426 | ||
|
|
7ae151362b | ||
|
|
648a1e05da | ||
|
|
b9f211fe34 | ||
|
|
e475d9e47f | ||
|
|
f37ca8249a | ||
|
|
1dd4be670d | ||
|
|
197d4cf835 | ||
|
|
83eed86b53 | ||
|
|
bbf612cb9e | ||
|
|
2679bb567b | ||
|
|
481e350f39 | ||
|
|
50c7a08754 | ||
|
|
9a0bb60737 | ||
|
|
deb5d81221 | ||
|
|
916b04dbac | ||
|
|
52307fad5d | ||
|
|
afb21135c2 | ||
|
|
b7fbffb3f7 | ||
|
|
5d98bcd8d8 | ||
|
|
e044788f63 | ||
|
|
4a9267ce12 | ||
|
|
104464c2e0 | ||
|
|
60adc110f5 | ||
|
|
2031d7d112 | ||
|
|
3402656ec5 | ||
|
|
4e84f743e4 | ||
|
|
17e50de5f0 | ||
|
|
978a788f40 | ||
|
|
6e91d55971 | ||
|
|
d4ce0a1e36 | ||
|
|
148608b377 | ||
|
|
f725f4acb7 | ||
|
|
d07a549438 | ||
|
|
551441cedd | ||
|
|
46c14e939b | ||
|
|
6084647795 | ||
|
|
e0a598ae62 | ||
|
|
28833eb04a | ||
|
|
b24c9c86d1 | ||
|
|
b7add480c7 | ||
|
|
eabb671b10 | ||
|
|
513ed02b76 | ||
|
|
b7ddbe71f7 | ||
|
|
21d1a7ca62 | ||
|
|
4c2d28a7ad | ||
|
|
2afec9e3ed | ||
|
|
69790421b7 | ||
|
|
3f08f6a359 | ||
|
|
719c2db8da | ||
|
|
a9aa55c32d | ||
|
|
3f6d9d6ee9 | ||
|
|
b32568159f | ||
|
|
bb48d0d857 | ||
|
|
536412515f | ||
|
|
fcc6eaadd3 | ||
|
|
7dc78e8796 | ||
|
|
c65de3fe6d | ||
|
|
d000f57773 | ||
|
|
75cddbdb6d | ||
|
|
e418d91511 | ||
|
|
6c2e6c5432 | ||
|
|
8c6d9fdc62 | ||
|
|
468e95427e | ||
|
|
6d7a5ace6b | ||
|
|
cbaec198a5 | ||
|
|
7467fa8b50 | ||
|
|
61640fb5c7 | ||
|
|
19cb4b62b0 | ||
|
|
81ee8bc30f | ||
|
|
9f384e1c6c | ||
|
|
35e8c8b25e | ||
|
|
dc53f1baff | ||
|
|
70139600b5 | ||
|
|
1b4d1521e0 | ||
|
|
ed3377cb2d | ||
|
|
d72852b3aa | ||
|
|
4b6b6189bf | ||
|
|
b69a54fc75 | ||
|
|
81e388a4cc | ||
|
|
5bd5e5052a | ||
|
|
a2d3fa729f | ||
|
|
cb6811bc47 | ||
|
|
53c6e80869 | ||
|
|
e71dca586c | ||
|
|
b3cd48db5f | ||
|
|
476448b9d4 | ||
|
|
070534df5b | ||
|
|
9a1e8ed574 | ||
|
|
309918a878 | ||
|
|
cac83b94c1 | ||
|
|
9c06df08a1 | ||
|
|
52e4543d31 | ||
|
|
a688468378 | ||
|
|
e1760d64fb | ||
|
|
84d4e3cf8f | ||
|
|
f8a76372ad | ||
|
|
4237f5520f | ||
|
|
8c0c01c702 | ||
|
|
9c100830e0 | ||
|
|
ed5d753b89 | ||
|
|
d1ca756bd8 | ||
|
|
16cf9f0ef2 | ||
|
|
133f69d66c | ||
|
|
bc60daff9e | ||
|
|
43a085d1ae | ||
|
|
8c33d0aa56 | ||
|
|
fe0767df13 | ||
|
|
08a25a0c8f | ||
|
|
cd410080bd | ||
|
|
7555378e3b | ||
|
|
80c95ee66a | ||
|
|
31563b210d | ||
|
|
861cd93324 | ||
|
|
abb344bb1a | ||
|
|
6147491d9e | ||
|
|
f1f18fbb4a | ||
|
|
9fc611f257 | ||
|
|
34a2e14a14 | ||
|
|
83fe65b9e9 | ||
|
|
ec26c8aa49 | ||
|
|
da43a3055f | ||
|
|
a38126c82f | ||
|
|
cb592ce588 | ||
|
|
d69c58a6da | ||
|
|
bdb1986e08 | ||
|
|
55356c78a8 | ||
|
|
a0f55252b1 | ||
|
|
013f5cffa9 | ||
|
|
d5d008f568 | ||
|
|
3b02134cdc | ||
|
|
a57d7b51b1 | ||
|
|
1a3c38d35f | ||
|
|
00aece0538 | ||
|
|
5a9cc835b3 | ||
|
|
58526cc849 | ||
|
|
955b5f43a5 | ||
|
|
447aec3fde | ||
|
|
473260a836 | ||
|
|
4d2784c10c | ||
|
|
d9af897595 | ||
|
|
23a48be315 | ||
|
|
ce8f48e5d1 | ||
|
|
6aaf839662 | ||
|
|
984a9e653e | ||
|
|
8dffa28b4d | ||
|
|
b05a4bdadd | ||
|
|
36087fe518 | ||
|
|
5eed87ec4d | ||
|
|
af66a73225 | ||
|
|
dcf913c17e | ||
|
|
68ccba8f74 | ||
|
|
956f7e29db | ||
|
|
4264c0577e | ||
|
|
cc37b59309 | ||
|
|
9f2f92095d | ||
|
|
0c1075c089 | ||
|
|
9c64710c8b | ||
|
|
f6f16b91db | ||
|
|
1986b5cfe6 | ||
|
|
6445b72d41 | ||
|
|
df7b8ba738 | ||
|
|
202083999e | ||
|
|
315f519e1d | ||
|
|
d7d580ae6f | ||
|
|
7017af303d | ||
|
|
0dc325daa4 | ||
|
|
6dffb47973 | ||
|
|
b19dad69d6 | ||
|
|
94c5ac64e9 | ||
|
|
c4bcd088fb | ||
|
|
aeecbe9396 | ||
|
|
171aade9cd | ||
|
|
67213ae86c | ||
|
|
24d9e53c3f | ||
|
|
573ed5f4b5 | ||
|
|
ceff628add | ||
|
|
0bb8cb9203 | ||
|
|
98349bde28 | ||
|
|
f09be932eb | ||
|
|
4c57ac2bbe | ||
|
|
1dd93c1b6b | ||
|
|
c9f85fe27f | ||
|
|
419cbe50f6 | ||
|
|
5031c8323f | ||
|
|
762d5913ce | ||
|
|
290df1b1c7 | ||
|
|
79170afc51 | ||
|
|
bba00c2bfe | ||
|
|
f7e2b3688f | ||
|
|
8d49b7dde1 | ||
|
|
138e60adb3 | ||
|
|
d6376c31e0 | ||
|
|
a7003e93c8 | ||
|
|
4821a11223 | ||
|
|
bf1b326988 | ||
|
|
39ddb6a175 | ||
|
|
b2a0b8c0f0 | ||
|
|
4debc46d0e | ||
|
|
f4e259d10f | ||
|
|
774d78228e | ||
|
|
0e62bde5c3 | ||
|
|
2bbd9b23e6 | ||
|
|
02676140e8 | ||
|
|
182beaa4a1 | ||
|
|
7c08a09529 | ||
|
|
ef964b5472 | ||
|
|
ee54ce9913 | ||
|
|
e59e146887 | ||
|
|
103ec0d58f | ||
|
|
a0d89ed514 | ||
|
|
c10888e6fe | ||
|
|
93455f8eb5 | ||
|
|
65acd96c8d | ||
|
|
fabe720b9b | ||
|
|
53dd313e97 | ||
|
|
2678d7a660 | ||
|
|
46718102c6 | ||
|
|
0f473fe3b1 | ||
|
|
2872602c9e | ||
|
|
ab653cae33 | ||
|
|
e6a035e575 | ||
|
|
fbe48d75dd | ||
|
|
20ba0f49dd | ||
|
|
c213e9878d | ||
|
|
9704ca4c18 | ||
|
|
49dce6219e | ||
|
|
260ff6c94f | ||
|
|
3ec281d104 | ||
|
|
c4c43d525b | ||
|
|
6c5cde363a | ||
|
|
d46b4d950f | ||
|
|
b369c4bb8a | ||
|
|
c3898487c4 | ||
|
|
ca3c5b400f | ||
|
|
97772b176c | ||
|
|
08a2965f1c | ||
|
|
76dcddfa3d | ||
|
|
79f476ae4d | ||
|
|
d406cb619c | ||
|
|
4f3890f1e4 | ||
|
|
7a9d58cc51 | ||
|
|
eef87da0e1 | ||
|
|
00e65f6f14 | ||
|
|
866e9824d1 | ||
|
|
482e6078e2 | ||
|
|
bc7ab296ef | ||
|
|
a5f4f53b56 | ||
|
|
b1227f526d | ||
|
|
78b42c8306 | ||
|
|
4b6d45ab8e | ||
|
|
7980341923 | ||
|
|
3917efdebd | ||
|
|
eaecb7347b | ||
|
|
05ca7d3129 | ||
|
|
4beae0de71 | ||
|
|
b711661784 | ||
|
|
0c4a45b1f4 | ||
|
|
ec2beb0039 | ||
|
|
cafb3e8bac | ||
|
|
e896d5e920 | ||
|
|
42d4228595 | ||
|
|
341ea3e4ea | ||
|
|
cb1baede87 | ||
|
|
45653ca2e7 | ||
|
|
77c861b74b | ||
|
|
b586c2146f | ||
|
|
4d42bed4f8 | ||
|
|
ea54c119ab | ||
|
|
d95b124771 | ||
|
|
61ccf09e6f | ||
|
|
8da30f0b41 | ||
|
|
90a57e7664 | ||
|
|
c42de19d2a | ||
|
|
dcc42f8514 | ||
|
|
3150fad909 | ||
|
|
ba17db3ab3 | ||
|
|
7c1c48327e | ||
|
|
85459e0ec6 | ||
|
|
13bdb68366 | ||
|
|
c91373fba3 | ||
|
|
e8149f5295 | ||
|
|
ab015ef90f | ||
|
|
fdfc89e577 | ||
|
|
e647e1f7bd | ||
|
|
a05d735e31 | ||
|
|
4470048ba4 | ||
|
|
0f58f956a7 | ||
|
|
20284757a6 | ||
|
|
df6efa0285 | ||
|
|
3c10e118e3 | ||
|
|
19980190f7 | ||
|
|
8f5495a446 | ||
|
|
9431029917 | ||
|
|
17ea70a102 | ||
|
|
7f142bddb3 | ||
|
|
98e0516ac1 | ||
|
|
7717516d1d | ||
|
|
760550ca0d | ||
|
|
f8144dd89c | ||
|
|
ac4070cb49 | ||
|
|
25b964e3df | ||
|
|
17ec6c72df | ||
|
|
a7b1185602 | ||
|
|
c76ae06fd1 | ||
|
|
b3dd54d550 | ||
|
|
d248eadb06 | ||
|
|
507eef3053 | ||
|
|
fc2f672337 | ||
|
|
6f49be8f26 | ||
|
|
dad7f1e1f6 | ||
|
|
c3a9384dcf | ||
|
|
0ee08bfe46 | ||
|
|
0872f495f9 | ||
|
|
33ac8b93a9 | ||
|
|
bbff1c222d | ||
|
|
b534f99870 | ||
|
|
86acf2460e | ||
|
|
40c00035ee | ||
|
|
4673abae7d | ||
|
|
ef8a705957 | ||
|
|
48255fa009 | ||
|
|
ed6269bc9c | ||
|
|
16b8d9afe5 | ||
|
|
f29fcb1f73 | ||
|
|
b36ad25030 | ||
|
|
edf3fe24c9 | ||
|
|
5a1bdf0eb1 | ||
|
|
d8e24d7e76 | ||
|
|
786c5330e9 | ||
|
|
70e730bb67 | ||
|
|
1d6ef630a5 | ||
|
|
1eedb22ef5 | ||
|
|
6ed1f49ad3 | ||
|
|
ecd01afad3 | ||
|
|
8bd8709f2b | ||
|
|
e82a585cec | ||
|
|
c1d4a68558 | ||
|
|
eff36dc09f | ||
|
|
031a58f817 | ||
|
|
cf39fc4fb1 | ||
|
|
c9bff94e17 | ||
|
|
e78e919925 | ||
|
|
76bb25262e | ||
|
|
d8426b1ed5 | ||
|
|
4894c10dd9 | ||
|
|
24285bb0e0 | ||
|
|
bf75501262 | ||
|
|
9e214a17f0 | ||
|
|
0aae1ecd9b | ||
|
|
062f990315 | ||
|
|
22685e44c0 | ||
|
|
8d66433e7c | ||
|
|
82863f48f6 | ||
|
|
51b14329d6 | ||
|
|
14dc7681ed | ||
|
|
258c9e86eb | ||
|
|
03dad5f2b2 | ||
|
|
86264e7733 | ||
|
|
95eae905f0 | ||
|
|
a90dbcc808 | ||
|
|
e9b21f2211 | ||
|
|
409e5174bb | ||
|
|
8b3c0daab2 | ||
|
|
c17807c995 | ||
|
|
4abb4edf64 | ||
|
|
d5ecc537af | ||
|
|
c7a49054fd | ||
|
|
a2314c4aa0 | ||
|
|
1717173f17 | ||
|
|
e44c12f029 | ||
|
|
1a98c390fc | ||
|
|
91902740e4 | ||
|
|
6aa6a93b44 | ||
|
|
b4135ac9b3 | ||
|
|
78906e6551 | ||
|
|
ba29ba1ab7 | ||
|
|
e0fa15f5cb | ||
|
|
82a1ff359d | ||
|
|
18e1f10a94 | ||
|
|
4828a17643 | ||
|
|
3b4f95597a | ||
|
|
bd52e93fca | ||
|
|
6fdc79d569 | ||
|
|
7dbad7206e | ||
|
|
a8a0c1e935 | ||
|
|
00bcf60566 | ||
|
|
4a745f2d2e | ||
|
|
057074b238 | ||
|
|
4b8cc13a05 | ||
|
|
a4e8586b59 | ||
|
|
095b37db6a | ||
|
|
efff650314 | ||
|
|
0764ca8fde | ||
|
|
403160434b | ||
|
|
730ab14faa | ||
|
|
51d70c4574 | ||
|
|
765ccd2aaa | ||
|
|
5399332f81 | ||
|
|
43b7f9fc0e | ||
|
|
3925689435 | ||
|
|
96a994a4c0 | ||
|
|
84c20373ec | ||
|
|
a216d2945b | ||
|
|
755a0caf3d | ||
|
|
703d90e663 | ||
|
|
e230ce41d7 | ||
|
|
596b38a3bb | ||
|
|
d31a91a599 | ||
|
|
400ef71b6f | ||
|
|
bb15cd9067 | ||
|
|
6ee6a226e1 | ||
|
|
94d51a94c8 | ||
|
|
d0feb4156c | ||
|
|
0d1278dade | ||
|
|
1b401b1195 | ||
|
|
11daa3b4d1 | ||
|
|
88a3919ce0 | ||
|
|
c41b87303d | ||
|
|
833aaead56 | ||
|
|
ff98d2e44a | ||
|
|
fcf05f608a | ||
|
|
9baf38db44 | ||
|
|
69050ef1c8 | ||
|
|
b35b9f7850 | ||
|
|
500ae97cac | ||
|
|
d5b7040557 | ||
|
|
ca52894651 | ||
|
|
4009acdd30 | ||
|
|
147c93ecd3 | ||
|
|
8e04e4b07f | ||
|
|
e7413ea1e5 | ||
|
|
220bb03a32 | ||
|
|
20f512fe5f | ||
|
|
efb3523eaa | ||
|
|
2f2276e091 | ||
|
|
08a6597626 | ||
|
|
d82a6ee4fc | ||
|
|
e627f6d68d | ||
|
|
e650f58bd8 | ||
|
|
5a9b6c8afd | ||
|
|
075771d1e9 | ||
|
|
4fcf091fef | ||
|
|
0e66454fe4 | ||
|
|
aa3ce760bb | ||
|
|
ba46ad1fd9 | ||
|
|
11214bab5d | ||
|
|
d87c289b4a | ||
|
|
af45c03b6f | ||
|
|
7d6fadce6b | ||
|
|
6b560f7a85 | ||
|
|
5d4221460d | ||
|
|
d42c383992 | ||
|
|
9c7f6fcb2b | ||
|
|
14af0bda61 | ||
|
|
fb5c393fbd | ||
|
|
69fe21a7ec | ||
|
|
da4e05c118 | ||
|
|
e4333ff6b0 | ||
|
|
4ae8999f62 | ||
|
|
3fa91bb4ce | ||
|
|
23b2e541ab | ||
|
|
5bfcf61a6f | ||
|
|
0778c112a9 | ||
|
|
2c300754a7 | ||
|
|
c610e306df | ||
|
|
417cca6e0d | ||
|
|
2ed4b5ae83 | ||
|
|
16e429cf2c | ||
|
|
6b7ce8a605 | ||
|
|
ba4ce75377 | ||
|
|
76ded7fd28 | ||
|
|
a0d1a7be50 | ||
|
|
690bc43abe | ||
|
|
50b461024d | ||
|
|
6cf0b3240d | ||
|
|
233b015d77 | ||
|
|
28de243c11 | ||
|
|
36e8a3da88 | ||
|
|
119d16cad3 | ||
|
|
38402d3185 | ||
|
|
6c02949fc1 | ||
|
|
b737d4601e | ||
|
|
3ff3353550 | ||
|
|
946d3c81a5 | ||
|
|
628996846d | ||
|
|
631a3597c7 | ||
|
|
cfa4f7d45c | ||
|
|
05d76eeadf | ||
|
|
28a6c53da0 | ||
|
|
6fcd2153c5 | ||
|
|
7ae0512b9b | ||
|
|
0890b59c32 | ||
|
|
df3ce450d9 | ||
|
|
bb0257b318 | ||
|
|
9c3597670d | ||
|
|
aa9b328778 | ||
|
|
159e8dace2 | ||
|
|
3be4d5bb45 | ||
|
|
af7caa7b25 | ||
|
|
b4ede75522 | ||
|
|
9d98114074 | ||
|
|
4ac51899c3 | ||
|
|
90a0382317 | ||
|
|
687795c801 | ||
|
|
2e0fbbb942 | ||
|
|
0a3512d066 | ||
|
|
6032171f91 | ||
|
|
fc178de309 | ||
|
|
3f4398457f | ||
|
|
b494b2e872 | ||
|
|
18afcf5f90 | ||
|
|
87a422942d | ||
|
|
ac515121e5 | ||
|
|
2bfea0ad76 | ||
|
|
83cdb558f6 | ||
|
|
9ee377963e | ||
|
|
9cc06c887b | ||
|
|
7457b50373 | ||
|
|
6387fb79b1 | ||
|
|
54e5514b9a | ||
|
|
1e4597c284 | ||
|
|
7cafd4386c | ||
|
|
e3549ba28c | ||
|
|
d1bbe62e52 | ||
|
|
36af74a09b | ||
|
|
5afe02be60 | ||
|
|
2262959673 | ||
|
|
ba3f914445 | ||
|
|
770be35c44 | ||
|
|
cc9f2b90fd | ||
|
|
4aff57b071 | ||
|
|
1df8d82fe0 | ||
|
|
98e90784f4 | ||
|
|
87ea54cc66 | ||
|
|
d5e98bc8ad | ||
|
|
fa69ff773a | ||
|
|
a183bb1cac | ||
|
|
cf62372cab | ||
|
|
56fa9c95a1 | ||
|
|
32a34a8841 | ||
|
|
98797445de | ||
|
|
bd377438b6 | ||
|
|
9dd6510de6 | ||
|
|
93ad9d4a4a | ||
|
|
4c01a099ea | ||
|
|
8e70579e47 | ||
|
|
ee8bfa3980 | ||
|
|
c5dfa49cae | ||
|
|
0822404129 | ||
|
|
144f39cd45 | ||
|
|
87f191fd05 | ||
|
|
37ed436202 | ||
|
|
88e490356d | ||
|
|
7c631c0787 | ||
|
|
f5d3721fe0 | ||
|
|
cc633589d9 | ||
|
|
cc1d4c1a6d | ||
|
|
30ca424942 | ||
|
|
813831acf0 | ||
|
|
a54fe9f77c | ||
|
|
8c6da5548a | ||
|
|
a2aa7d69e7 | ||
|
|
34d5252242 | ||
|
|
f31e4d2869 | ||
|
|
c695c40abc | ||
|
|
fd1ca1dbb2 | ||
|
|
f25dbd5f61 | ||
|
|
541e7104fd | ||
|
|
94945cf6ac | ||
|
|
db76e655f8 | ||
|
|
d43c7b581d | ||
|
|
383b933e26 | ||
|
|
d26ccf6294 | ||
|
|
6f9699f605 | ||
|
|
1e9093d781 | ||
|
|
9dc6492e52 | ||
|
|
d22f7cae6a | ||
|
|
473afaab45 | ||
|
|
dcd68303a4 | ||
|
|
03394556b5 | ||
|
|
1c4f6f75f3 | ||
|
|
f00928dedb | ||
|
|
a48f8fbb61 | ||
|
|
1fa388370e | ||
|
|
95ef6b3f71 | ||
|
|
de11d36d00 | ||
|
|
d77c2adabe | ||
|
|
c89c055ae0 | ||
|
|
dac8117f32 | ||
|
|
937b091bab | ||
|
|
019e6a1bfe | ||
|
|
1565e58fcf | ||
|
|
c22e2a17ef | ||
|
|
fd2a10ccea | ||
|
|
0725378257 | ||
|
|
c431909f35 | ||
|
|
db4df6f0b2 | ||
|
|
17f942c802 | ||
|
|
60438ebfe5 | ||
|
|
21fbe546b8 | ||
|
|
11900945eb | ||
|
|
ea5270221b | ||
|
|
a64844689e | ||
|
|
6007e13a22 | ||
|
|
c3274e480b | ||
|
|
3c54eeda5b | ||
|
|
6236e4b97d | ||
|
|
796738da65 | ||
|
|
37d385fafa | ||
|
|
db2af42ee7 | ||
|
|
24b42ef192 | ||
|
|
2ce166ab0a | ||
|
|
71755b69e4 | ||
|
|
1106aac2d8 | ||
|
|
93aac660a3 | ||
|
|
0ce8ad7130 | ||
|
|
deacd553bf | ||
|
|
c8ff7e11a9 | ||
|
|
4cff62258c | ||
|
|
0144358afb | ||
|
|
136097efe7 | ||
|
|
374c6959d7 | ||
|
|
7d48a5ccf4 | ||
|
|
bf3254cb16 | ||
|
|
5bed3a7d52 | ||
|
|
ece111280b | ||
|
|
a15a9b956b | ||
|
|
42860c2f83 | ||
|
|
b5b95e5ae1 | ||
|
|
d705cffdd6 | ||
|
|
23a4bc103e | ||
|
|
c14434f9e7 | ||
|
|
25bd2cea3e | ||
|
|
532de4ecab | ||
|
|
bfdd27eeef | ||
|
|
bd9f238ab4 | ||
|
|
75556bb57c | ||
|
|
2de062a34a | ||
|
|
4589b15dea | ||
|
|
8b75ce6786 | ||
|
|
7bbc5176a1 | ||
|
|
5cb35485f1 | ||
|
|
80189ed689 | ||
|
|
3d7e8ef432 | ||
|
|
1999c7103c | ||
|
|
9c20ae383e | ||
|
|
76c41eaf05 | ||
|
|
873aa6700f | ||
|
|
0d9590a9a0 | ||
|
|
94607b585a | ||
|
|
da0b0348a2 | ||
|
|
09263455b5 | ||
|
|
ddc23493d4 | ||
|
|
54a71fc142 | ||
|
|
b1a9bf10a2 | ||
|
|
97cfbe1b63 | ||
|
|
0ee8c63551 | ||
|
|
0ac5a9ad82 | ||
|
|
6e51f2d608 | ||
|
|
f23a8dc9dc | ||
|
|
d09fe6178c | ||
|
|
ae2cfcc4f3 | ||
|
|
853cc65e32 | ||
|
|
5d140d949f | ||
|
|
6d2da2b3ba | ||
|
|
165e337e44 | ||
|
|
b154cd0418 | ||
|
|
8ef1532691 | ||
|
|
771e44f2a7 | ||
|
|
8933f1128d | ||
|
|
dbac4b9a63 | ||
|
|
bdac5b5807 | ||
|
|
b0961b5213 | ||
|
|
0d7c3fc4d8 | ||
|
|
8dac256096 | ||
|
|
8320da39c3 | ||
|
|
875937e3d8 | ||
|
|
f880adbaac | ||
|
|
48c5f86adb | ||
|
|
f60f7dab12 | ||
|
|
8f690236ed | ||
|
|
430a4297aa | ||
|
|
69e3ab02c4 | ||
|
|
b87a20b881 | ||
|
|
0e6f2d16ab | ||
|
|
498b061819 | ||
|
|
5ab6f599fb | ||
|
|
8b80626035 | ||
|
|
f86ae79fdb | ||
|
|
1a4e68096f | ||
|
|
d599d1f29e | ||
|
|
73edfb3d2c | ||
|
|
ebae68d579 | ||
|
|
573836e2b8 | ||
|
|
da5deb8177 | ||
|
|
8fca89e876 | ||
|
|
d5295a2d0c | ||
|
|
c4df115948 | ||
|
|
8afcb16d8e | ||
|
|
3764d63244 | ||
|
|
c82914df30 | ||
|
|
84ba921f5b | ||
|
|
8e74668e3c | ||
|
|
707c05b5f5 | ||
|
|
9bd2cec199 | ||
|
|
358b8fe8b6 | ||
|
|
7115ae5375 | ||
|
|
13997ca653 | ||
|
|
9fa04a0b93 | ||
|
|
0894145284 | ||
|
|
927b77700d | ||
|
|
1d7a0ea99e | ||
|
|
d6aee8e5ba | ||
|
|
dfaa39fa5d | ||
|
|
8fe3b59efe | ||
|
|
47237b1f15 | ||
|
|
053e727bd5 | ||
|
|
2ce9e81d80 | ||
|
|
50848ee462 | ||
|
|
ef06d560cd | ||
|
|
2abf9f96c7 | ||
|
|
a91686b4cd | ||
|
|
1be424cd47 | ||
|
|
929ea10f76 | ||
|
|
11d1f39e3d | ||
|
|
fc233ed4ff | ||
|
|
efd2e893cf | ||
|
|
2a18b9a8f7 | ||
|
|
6aa214181b | ||
|
|
7067beda99 | ||
|
|
e0f0baf164 | ||
|
|
1fec132dee | ||
|
|
ba521fccb4 | ||
|
|
965a97105e | ||
|
|
3c88c84998 | ||
|
|
d0f66c3734 | ||
|
|
ebc2a741f6 | ||
|
|
d46512af1c | ||
|
|
b4d72bd544 | ||
|
|
382d476271 | ||
|
|
80c240b54a | ||
|
|
21f99d88ab | ||
|
|
d5873a00d5 | ||
|
|
99076edc89 | ||
|
|
7b6c80327e | ||
|
|
57946ed672 | ||
|
|
aad16ac50d | ||
|
|
bbe897e607 | ||
|
|
eca0e66e23 | ||
|
|
3511723914 | ||
|
|
6a1c7b7588 | ||
|
|
18fd6ef119 | ||
|
|
0004f5d2ff | ||
|
|
5f29d1ba9c | ||
|
|
791fd35c35 | ||
|
|
e0d622d347 | ||
|
|
6b34e8a804 | ||
|
|
eb8773fe3e | ||
|
|
b40e3fa1f1 | ||
|
|
d25d761b55 | ||
|
|
d6051dd714 | ||
|
|
53ff061efa | ||
|
|
72b0efd393 | ||
|
|
df97ef23d9 | ||
|
|
f6373971bd | ||
|
|
ec617f2489 | ||
|
|
502ae78579 | ||
|
|
49297d6afb | ||
|
|
29354badd8 | ||
|
|
3c4de796c8 | ||
|
|
c7f4488e77 | ||
|
|
d8765f955d | ||
|
|
9f20037dad | ||
|
|
2ebb090df2 | ||
|
|
110fff3ab9 | ||
|
|
f42a1ceab7 | ||
|
|
9e39a7fa95 | ||
|
|
c879df3b31 | ||
|
|
361ed98353 | ||
|
|
d45f8ef2d3 | ||
|
|
d6a63d11d7 | ||
|
|
4c6804eadc | ||
|
|
99810c0311 | ||
|
|
d15fb1ab1b | ||
|
|
0a6d8b37ad | ||
|
|
f78ffdb9ce | ||
|
|
b7b6fdbdf5 | ||
|
|
e398b471e1 | ||
|
|
48f69f3d88 | ||
|
|
95850d75f6 | ||
|
|
c41d755441 | ||
|
|
39a21787b7 | ||
|
|
36078f9903 | ||
|
|
2f534dc01c | ||
|
|
c8e59f08ec | ||
|
|
19dd6a997f | ||
|
|
4d1a1694cd | ||
|
|
52bea15ad7 | ||
|
|
6592361c5a | ||
|
|
f3f83494f5 | ||
|
|
1169afbe90 | ||
|
|
301bfbd271 | ||
|
|
46aec7eabc | ||
|
|
4cd3b66761 | ||
|
|
567e3dd258 | ||
|
|
fcf853712c | ||
|
|
088d36b47b | ||
|
|
27fb864ac4 | ||
|
|
4001c4a48a | ||
|
|
f64c18ef15 | ||
|
|
f8e72f443d | ||
|
|
5e015cc3ca | ||
|
|
9707f8c5d2 | ||
|
|
6b1d698448 | ||
|
|
72f69dda30 | ||
|
|
8b5d8a0577 | ||
|
|
1aa053ce6f | ||
|
|
701b1c4216 | ||
|
|
f1c4cef781 | ||
|
|
6fe5b307b1 | ||
|
|
679ce08998 | ||
|
|
eeb923eb5b | ||
|
|
142c431745 | ||
|
|
81f5589411 | ||
|
|
04f5c884a4 | ||
|
|
d8df503404 | ||
|
|
d241efcdbe | ||
|
|
a1b8efe721 | ||
|
|
815d076b35 | ||
|
|
86b4816b3f | ||
|
|
473055468a | ||
|
|
c6a28db8b1 | ||
|
|
971f567571 | ||
|
|
7e2eca3d1e | ||
|
|
86b0053bf0 | ||
|
|
cfc4b282f0 | ||
|
|
b85d2aa565 | ||
|
|
70a3d4fb5e | ||
|
|
d9b667e346 | ||
|
|
3a1db53d5a | ||
|
|
4858ebe051 | ||
|
|
d2455267a8 | ||
|
|
61721bb086 | ||
|
|
3e76ee25e3 | ||
|
|
a71e562ff7 | ||
|
|
850fc9adf9 | ||
|
|
d3c78f825c | ||
|
|
7231d92d1f | ||
|
|
93e14484da | ||
|
|
d7d03b1ca2 | ||
|
|
dfd6d95209 | ||
|
|
e4e7384f99 | ||
|
|
effa77afee | ||
|
|
6ccccf8c39 | ||
|
|
dd9d66ef20 | ||
|
|
bc84d1e47a | ||
|
|
6b426014ad | ||
|
|
c6f12fe033 | ||
|
|
bb096ac617 | ||
|
|
734df539dd | ||
|
|
27b9481452 | ||
|
|
945706c2a4 | ||
|
|
a7b024d4fa | ||
|
|
9911863441 | ||
|
|
deb978bf57 | ||
|
|
55998707a5 | ||
|
|
4af702ee11 | ||
|
|
8717ecc429 | ||
|
|
552cfd6ff1 | ||
|
|
928edfd1dd | ||
|
|
98fb2e73f9 | ||
|
|
de09577342 | ||
|
|
cbdbbe535a | ||
|
|
36e636dca1 | ||
|
|
3f5e38bb62 | ||
|
|
eb30f6ceff | ||
|
|
1051fcd278 | ||
|
|
1a0030e086 | ||
|
|
114ce370ed | ||
|
|
207dcbeaa4 | ||
|
|
d4a1722863 | ||
|
|
18b9991fe7 | ||
|
|
739178dd74 | ||
|
|
dcd1392a85 | ||
|
|
07d66da57b | ||
|
|
28ce33feb3 | ||
|
|
86039a3f2b | ||
|
|
af9d09f8ae | ||
|
|
7c06a48ec0 | ||
|
|
7ada9dbd0d | ||
|
|
5c5d74a903 | ||
|
|
72354d55a8 | ||
|
|
fc2002fbd0 | ||
|
|
82ec2715f1 | ||
|
|
ef6e90fb3c | ||
|
|
475f0bf120 | ||
|
|
e68a14c94c | ||
|
|
da0dc28bc4 | ||
|
|
e6bfa52b0b | ||
|
|
36bfbdee0d | ||
|
|
7a9a4127a0 | ||
|
|
4f1472d4ff | ||
|
|
032bb7e96b | ||
|
|
9ddc817a09 | ||
|
|
a5bd68ef8c | ||
|
|
a2ec3642bf | ||
|
|
9647fe1b9f | ||
|
|
762cda75a9 | ||
|
|
c39a9b8de9 | ||
|
|
15a577863a | ||
|
|
2d500554c1 | ||
|
|
c42fb97419 | ||
|
|
d1d6155fd1 | ||
|
|
ff8c42e894 | ||
|
|
e10aeb29eb | ||
|
|
fee3d882c7 | ||
|
|
d17e8d3450 | ||
|
|
99f960bf56 | ||
|
|
83d8847f57 | ||
|
|
f672f86b53 | ||
|
|
b69627891d | ||
|
|
673d8278b5 | ||
|
|
8dd554b935 | ||
|
|
65b7f7d7d5 | ||
|
|
a982cfdb20 | ||
|
|
7689fbe54d | ||
|
|
c9d32e22d3 | ||
|
|
278273b5c3 | ||
|
|
a5d85b8a54 | ||
|
|
4c172d25f6 | ||
|
|
b70a7d9a3b | ||
|
|
ba5a8b44ed | ||
|
|
91e1ed1314 | ||
|
|
85f20c6e1b | ||
|
|
4b98dbb454 | ||
|
|
c3ad4fbdaa | ||
|
|
2e9cd83ed2 | ||
|
|
f1ead06645 | ||
|
|
d486eaad03 | ||
|
|
7d261a147d | ||
|
|
61038888c4 | ||
|
|
39040fb9a0 | ||
|
|
4f3262c328 | ||
|
|
69126a7c5f | ||
|
|
62554b766f | ||
|
|
e699e36270 | ||
|
|
331926dc3c |
105
.circleci/config.yml
Normal file
105
.circleci/config.yml
Normal file
@@ -0,0 +1,105 @@
|
||||
version: 2.1
|
||||
|
||||
workflows:
|
||||
build:
|
||||
jobs:
|
||||
- linux-arm64-glibc-node-18:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
- linux-arm64-musl-node-18:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
- linux-arm64-glibc-node-20:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
- linux-arm64-musl-node-20:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
|
||||
jobs:
|
||||
linux-arm64-glibc-node-18:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2004:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl fonts-noto-core"
|
||||
sudo docker exec sharp sh -c "mkdir -p /etc/apt/keyrings"
|
||||
sudo docker exec sharp sh -c "curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg"
|
||||
sudo docker exec sharp sh -c "echo 'deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main' | tee /etc/apt/sources.list.d/nodesource.list"
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linux-arm64=file:./npm/linux-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"cd src && ln -s ../package.json && npx prebuild --upload=$prebuild_upload\" || true"
|
||||
linux-arm64-glibc-node-20:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2004:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --workdir /mnt/sharp arm64v8/debian:bullseye
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl fonts-noto-core"
|
||||
sudo docker exec sharp sh -c "mkdir -p /etc/apt/keyrings"
|
||||
sudo docker exec sharp sh -c "curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg"
|
||||
sudo docker exec sharp sh -c "echo 'deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main' | tee /etc/apt/sources.list.d/nodesource.list"
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
||||
sudo docker exec sharp sh -c "mkdir -p /mnt/sharp"
|
||||
sudo docker cp . sharp:/mnt/sharp/.
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linux-arm64=file:./npm/linux-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
linux-arm64-musl-node-18:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2004:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:18-alpine3.17
|
||||
sudo docker exec sharp sh -c "apk add build-base git python3 font-noto --update-cache"
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"cd src && ln -s ../package.json && npx prebuild --upload=$prebuild_upload\" || true"
|
||||
linux-arm64-musl-node-20:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2004:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --workdir /mnt/sharp node:20-alpine3.18
|
||||
sudo docker exec sharp sh -c "apk add build-base git python3 font-noto --update-cache"
|
||||
sudo docker exec sharp sh -c "mkdir -p /mnt/sharp"
|
||||
sudo docker cp . sharp:/mnt/sharp/.
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
17
.cirrus.yml
Normal file
17
.cirrus.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
freebsd_instance:
|
||||
image_family: freebsd-14-0-snap
|
||||
|
||||
task:
|
||||
name: FreeBSD
|
||||
env:
|
||||
IGNORE_OSVERSION: yes
|
||||
skip_notifications: true
|
||||
prerequisites_script:
|
||||
- pkg update -f
|
||||
- pkg upgrade -y
|
||||
- pkg install -y devel/git devel/pkgconf graphics/vips www/node20 www/npm
|
||||
- pkg-config --modversion vips-cpp
|
||||
install_script:
|
||||
- npm install --build-from-source
|
||||
test_script:
|
||||
- npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||
60
CONTRIBUTING.md → .github/CONTRIBUTING.md
vendored
60
CONTRIBUTING.md → .github/CONTRIBUTING.md
vendored
@@ -12,47 +12,46 @@ New bugs are assigned a `triage` label whilst under investigation.
|
||||
|
||||
## Submit a new feature request
|
||||
|
||||
If a [similar request](https://github.com/lovell/sharp/labels/enhancement) exists, it's probably fastest to add a comment to it about your requirement.
|
||||
If a [similar request](https://github.com/lovell/sharp/labels/enhancement) exists,
|
||||
it's probably fastest to add a comment to it about your requirement.
|
||||
|
||||
Implementation is usually straightforward if _libvips_ [already supports](http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/ch03.html) the feature you need.
|
||||
Implementation is usually straightforward if libvips
|
||||
[already supports](https://www.libvips.org/API/current/func-list.html)
|
||||
the feature you need.
|
||||
|
||||
## Submit a Pull Request to fix a bug
|
||||
|
||||
Thank you! To prevent the problem occurring again, please add unit tests that would have failed.
|
||||
|
||||
Please select the `master` branch as the destination for your Pull Request so your fix can be included in the next minor release.
|
||||
Please select the `main` branch as the destination for your Pull Request so your fix can be included in the next minor release.
|
||||
|
||||
Please squash your changes into a single commit using a command like `git rebase -i upstream/master`.
|
||||
Please squash your changes into a single commit using a command like `git rebase -i upstream/main`.
|
||||
|
||||
To test C++ changes, you can compile the module using `npm install` and then run the tests using `npm test`.
|
||||
To test C++ changes, you can compile the module using `npm install --build-from-source` and then run the tests using `npm test`.
|
||||
|
||||
## Submit a Pull Request with a new feature
|
||||
|
||||
Please add JavaScript [unit tests](https://github.com/lovell/sharp/tree/master/test/unit) to cover your new feature.
|
||||
Please add JavaScript [unit tests](https://github.com/lovell/sharp/tree/main/test/unit) to cover your new feature.
|
||||
A test coverage report for the JavaScript code is generated in the `coverage/lcov-report` directory.
|
||||
Please also update the [TypeScript definitions](https://github.com/lovell/sharp/tree/main/lib/index.d.ts), along with the [type definition tests](https://github.com/lovell/sharp/tree/main/test/types/sharp.test-d.ts).
|
||||
|
||||
Where possible, the functional tests use gradient-based perceptual hashes
|
||||
based on [dHash](http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html)
|
||||
to compare expected vs actual images.
|
||||
|
||||
You deserve to add your details to the [list of contributors](https://github.com/lovell/sharp/blob/master/package.json#L5).
|
||||
You deserve to add your details to the [list of contributors](https://github.com/lovell/sharp/blob/main/package.json#L5).
|
||||
|
||||
Any change that modifies the existing public API should be added to the relevant work-in-progress branch for inclusion in the next major release.
|
||||
|
||||
| Release | WIP branch |
|
||||
| ------: | :--------- |
|
||||
| v0.16.0 | pencil |
|
||||
| v0.17.0 | quill |
|
||||
|
||||
Please squash your changes into a single commit using a command like `git rebase -i upstream/<wip-branch>`.
|
||||
|
||||
### Add a new public method
|
||||
|
||||
The API tries to be as fluent as possible. Image processing concepts follow the naming conventions from _libvips_ and, to a lesser extent, _ImageMagick_.
|
||||
The API tries to be as fluent as possible.
|
||||
Image processing concepts follow the naming conventions from libvips and, to a lesser extent, ImageMagick.
|
||||
|
||||
Most methods have optional parameters and assume sensible defaults. Methods with mandatory parameters often have names like `doSomethingWith(X)`.
|
||||
|
||||
Please ensure backwards compatibility where possible. Methods to modify previously default behaviour often have names like `withoutOptionY()` or `withExtraZ()`.
|
||||
Most methods have optional parameters and assume sensible defaults.
|
||||
Please ensure backwards compatibility where possible.
|
||||
|
||||
Feel free to create a [new issue](https://github.com/lovell/sharp/issues/new) to gather feedback on a potential API change.
|
||||
|
||||
@@ -60,7 +59,18 @@ Feel free to create a [new issue](https://github.com/lovell/sharp/issues/new) to
|
||||
|
||||
A method to be removed should be deprecated in the next major version then removed in the following major version.
|
||||
|
||||
By way of example, the [bilinearInterpolation method](https://github.com/lovell/sharp/blob/v0.6.0/index.js#L155) present in v0.5.0 was deprecated in v0.6.0 and removed in v0.7.0.
|
||||
By way of example, the `background()` method present in v0.20.0 was deprecated in v0.21.0 and removed in v0.22.0.
|
||||
|
||||
## Documentation
|
||||
|
||||
The public API is documented with [JSDoc](http://usejsdoc.org/) annotated comments.
|
||||
|
||||
These can be converted to Markdown by running:
|
||||
```sh
|
||||
npm run docs-build
|
||||
```
|
||||
|
||||
Please include documentation updates in any Pull Request that modifies the public API.
|
||||
|
||||
## Run the tests
|
||||
|
||||
@@ -78,15 +88,11 @@ Requires [Valgrind](http://valgrind.org/).
|
||||
npm run test-leak
|
||||
```
|
||||
|
||||
### Packaging tests
|
||||
|
||||
Tests the installation on a number of Linux-based operating systems.
|
||||
Requires docker.
|
||||
|
||||
```sh
|
||||
npm run test-packaging
|
||||
```
|
||||
|
||||
## Finally
|
||||
|
||||
Please feel free to ask any questions via a [new issue](https://github.com/lovell/sharp/issues/new) or contact me by [e-mail](https://github.com/lovell/sharp/blob/master/package.json#L4).
|
||||
Please feel free to ask any questions via a
|
||||
[new issue](https://github.com/lovell/sharp/issues/new).
|
||||
|
||||
If you're unable to post details publicly, please
|
||||
[e-mail](https://github.com/lovell/sharp/blob/main/package.json#L5)
|
||||
for private, paid consulting.
|
||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
open_collective: libvips
|
||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Documentation
|
||||
url: https://sharp.pixelplumbing.com/
|
||||
about: Installation instructions, complete API documentation with examples, changelog
|
||||
28
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
28
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea
|
||||
labels: enhancement
|
||||
|
||||
---
|
||||
|
||||
## Feature request
|
||||
|
||||
### What are you trying to achieve?
|
||||
|
||||
<!-- Please provide context here. -->
|
||||
|
||||
### When you searched for similar feature requests, what did you find that might be related?
|
||||
|
||||
<!-- Please demonstrate your research here. -->
|
||||
|
||||
### What would you expect the API to look like?
|
||||
|
||||
<!-- Please provide your suggestions here. -->
|
||||
|
||||
### What alternatives have you considered?
|
||||
|
||||
<!-- Please provide your ideas here. -->
|
||||
|
||||
### Please provide sample image(s) that help explain this feature
|
||||
|
||||
<!-- Please provide links to one or more images here. -->
|
||||
69
.github/ISSUE_TEMPLATE/installation.md
vendored
Normal file
69
.github/ISSUE_TEMPLATE/installation.md
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
---
|
||||
name: Installation
|
||||
about: Something went wrong during either 'npm install sharp' or 'require("sharp")'
|
||||
labels: installation
|
||||
|
||||
---
|
||||
|
||||
<!-- Please try to answer as many of these questions as possible. -->
|
||||
|
||||
## Possible install-time or require-time problem
|
||||
|
||||
<!-- Please place an [x] in the box to confirm. -->
|
||||
|
||||
- [ ] I have read and understood all of the [documentation relating to installation](https://sharp.pixelplumbing.com/install).
|
||||
- [ ] I have searched for known bugs relating to this problem in my choice of package manager.
|
||||
|
||||
You must confirm both of these before continuing.
|
||||
|
||||
### Are you using the latest version of sharp?
|
||||
|
||||
<!-- Please place an [x] in the box to confirm. -->
|
||||
|
||||
- [ ] I am using the latest version of `sharp` as reported by `npm view sharp dist-tags.latest`.
|
||||
|
||||
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
|
||||
|
||||
If you are using another package which depends on a version of `sharp` that is not the latest,
|
||||
please open an issue against that package instead.
|
||||
|
||||
### Are you using a supported runtime?
|
||||
|
||||
<!-- Please place an [x] in the relevant box to confirm. -->
|
||||
|
||||
- [ ] I am using Node.js with a version that satisfies `^18.17.0 || ^20.3.0 || >=21.0.0`
|
||||
- [ ] I am using Deno
|
||||
- [ ] I am using Bun
|
||||
|
||||
If you cannot confirm any of these,
|
||||
please upgrade to the latest version
|
||||
and try again before opening an issue.
|
||||
|
||||
### Are you using a supported package manager and installing optional dependencies?
|
||||
|
||||
<!-- Please place an [x] in the relevant box to confirm. -->
|
||||
|
||||
- [ ] I am using npm >= 9.6.5 with `--include=optional`
|
||||
- [ ] I am using yarn >= 3.2.0
|
||||
- [ ] I am using pnpm >= 7.1.0 with `--no-optional=false`
|
||||
- [ ] I am using Deno
|
||||
- [ ] I am using Bun
|
||||
|
||||
If you cannot confirm any of these, please upgrade to the latest version of your chosen package manager
|
||||
and ensure you are allowing the installation of optional or multi-platform dependencies before opening an issue.
|
||||
|
||||
### What is the complete error message, including the full stack trace?
|
||||
|
||||
<!-- Please provide the error message and stack trace here. -->
|
||||
|
||||
### What is the complete output of running `npm install --verbose --foreground-scripts sharp` in an empty directory?
|
||||
|
||||
<details>
|
||||
|
||||
<!-- Please provide output of `npm install --verbose --foreground-scripts sharp` in an empty directory here. -->
|
||||
|
||||
</details>
|
||||
|
||||
### What is the output of running `npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp`?
|
||||
|
||||
<!-- Please provide output of `npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp` here. -->
|
||||
49
.github/ISSUE_TEMPLATE/possible-bug.md
vendored
Normal file
49
.github/ISSUE_TEMPLATE/possible-bug.md
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: Possible bug
|
||||
about: Installation of sharp was successful but then something unexpected occurred using one of its features
|
||||
labels: triage
|
||||
|
||||
---
|
||||
|
||||
<!-- If this issue relates to installation, please use https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md instead. -->
|
||||
|
||||
## Possible bug
|
||||
|
||||
### Is this a possible bug in a feature of sharp, unrelated to installation?
|
||||
|
||||
<!-- Please place an [x] in the box to confirm. -->
|
||||
|
||||
- [ ] Running `npm install sharp` completes without error.
|
||||
- [ ] Running `node -e "require('sharp')"` completes without error.
|
||||
|
||||
If you cannot confirm both of these, please open an [installation issue](https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md) instead.
|
||||
|
||||
### Are you using the latest version of sharp?
|
||||
|
||||
<!-- Please place an [x] in the box to confirm. -->
|
||||
|
||||
- [ ] I am using the latest version of `sharp` as reported by `npm view sharp dist-tags.latest`.
|
||||
|
||||
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
|
||||
|
||||
If you are using another package which depends on a version of `sharp` that is not the latest, please open an issue against that package instead.
|
||||
|
||||
### What is the output of running `npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp`?
|
||||
|
||||
<!-- Please provide output of the above command here. -->
|
||||
|
||||
### What are the steps to reproduce?
|
||||
|
||||
<!-- Please enter steps to reproduce here. -->
|
||||
|
||||
### What is the expected behaviour?
|
||||
|
||||
<!-- Please enter the expected behaviour here. -->
|
||||
|
||||
### Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
|
||||
|
||||
<!-- Please provide either formatted code or a link to a repo/gist that allows someone else to reproduce here. -->
|
||||
|
||||
### Please provide sample image(s) that help explain this problem
|
||||
|
||||
<!-- Please provide links to one or more images here. -->
|
||||
26
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: Question
|
||||
about: For help understanding an existing feature
|
||||
labels: question
|
||||
|
||||
---
|
||||
|
||||
<!-- If this issue relates to installation, please use https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md instead. -->
|
||||
|
||||
## Question about an existing feature
|
||||
|
||||
### What are you trying to achieve?
|
||||
|
||||
<!-- Please provide context here. -->
|
||||
|
||||
### When you searched for similar issues, what did you find that might be related?
|
||||
|
||||
<!-- Please demonstrate your research here. -->
|
||||
|
||||
### Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
|
||||
|
||||
<!-- Please provide either formatted code or a link to a repo/gist that helps someone else understand here. -->
|
||||
|
||||
### Please provide sample image(s) that help explain this question
|
||||
|
||||
<!-- Please provide links to one or more images here. -->
|
||||
18
.github/SECURITY.md
vendored
Normal file
18
.github/SECURITY.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
The latest version of `sharp` as published to npm
|
||||
and reported by `npm view sharp dist-tags.latest`
|
||||
is supported with security updates.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please use
|
||||
[e-mail](https://github.com/lovell/sharp/blob/main/package.json#L5)
|
||||
to report a vulnerability.
|
||||
|
||||
You can expect a response within 48 hours
|
||||
if you are a human reporting a genuine issue.
|
||||
|
||||
Thank you in advance.
|
||||
240
.github/workflows/ci.yml
vendored
Normal file
240
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
name: CI
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
permissions: {}
|
||||
jobs:
|
||||
github-runner:
|
||||
permissions:
|
||||
contents: write
|
||||
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} ${{ matrix.prebuild && '- prebuild' }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-22.04
|
||||
container: rockylinux:8
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: linux-x64
|
||||
prebuild: true
|
||||
- os: ubuntu-22.04
|
||||
container: rockylinux:8
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: linux-x64
|
||||
- os: ubuntu-22.04
|
||||
container: node:18-alpine3.17
|
||||
nodejs_version_major: 18
|
||||
platform: linuxmusl-x64
|
||||
prebuild: true
|
||||
- os: ubuntu-22.04
|
||||
container: node:20-alpine3.18
|
||||
nodejs_version_major: 20
|
||||
platform: linuxmusl-x64
|
||||
- os: macos-11
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: darwin-x64
|
||||
prebuild: true
|
||||
- os: macos-11
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: darwin-x64
|
||||
- os: windows-2019
|
||||
nodejs_arch: x86
|
||||
nodejs_version: "18.18.2" # pinned to avoid 18.19.0 and npm 10
|
||||
nodejs_version_major: 18
|
||||
platform: win32-ia32
|
||||
prebuild: true
|
||||
- os: windows-2019
|
||||
nodejs_arch: x86
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: win32-ia32
|
||||
- os: windows-2019
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: win32-x64
|
||||
prebuild: true
|
||||
- os: windows-2019
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: win32-x64
|
||||
steps:
|
||||
- name: Dependencies (Rocky Linux glibc)
|
||||
if: contains(matrix.container, 'rockylinux')
|
||||
run: |
|
||||
dnf install -y gcc-toolset-11-gcc-c++ make git python3 fontconfig google-noto-sans-fonts
|
||||
echo "/opt/rh/gcc-toolset-11/root/usr/bin" >> $GITHUB_PATH
|
||||
- name: Dependencies (Linux musl)
|
||||
if: contains(matrix.container, 'alpine')
|
||||
run: apk add build-base git python3 font-noto --update-cache
|
||||
- name: Dependencies (Python 3.11 - macOS, Windows)
|
||||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Dependencies (Node.js)
|
||||
if: "!contains(matrix.platform, 'linuxmusl')"
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.nodejs_version }}
|
||||
architecture: ${{ matrix.nodejs_arch }}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install
|
||||
run: npm install --build-from-source
|
||||
- name: Test
|
||||
run: npm test
|
||||
- name: Test packaging
|
||||
run: |
|
||||
npm run package-from-local-build
|
||||
npm pkg set "optionalDependencies.@img/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
||||
npm run clean
|
||||
npm install --ignore-scripts
|
||||
npm test
|
||||
- name: Prebuild
|
||||
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
|
||||
env:
|
||||
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
node -e "require('fs').cpSync('package.json', 'src/package.json')"
|
||||
cd src
|
||||
npx prebuild
|
||||
github-runner-qemu:
|
||||
permissions:
|
||||
contents: write
|
||||
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} - prebuild
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- platform: linux-arm
|
||||
run_on_arch: armv6
|
||||
nodejs_arch: armv6l
|
||||
nodejs_hostname: unofficial-builds.nodejs.org
|
||||
nodejs_version: "18.17.0"
|
||||
nodejs_version_major: 18
|
||||
- platform: linux-s390x
|
||||
run_on_arch: s390x
|
||||
nodejs_arch: s390x
|
||||
nodejs_hostname: nodejs.org
|
||||
nodejs_version: "18.17.0"
|
||||
nodejs_version_major: 18
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: uraimo/run-on-arch-action@v2
|
||||
with:
|
||||
arch: ${{ matrix.run_on_arch }}
|
||||
distro: buster
|
||||
env: |
|
||||
prebuild_upload: "${{ startsWith(github.ref, 'refs/tags/') && secrets.GITHUB_TOKEN || '' }}"
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y curl g++ git libatomic1 make python3 xz-utils
|
||||
mkdir /opt/nodejs
|
||||
curl --silent https://${{ matrix.nodejs_hostname }}/download/release/v${{ matrix.nodejs_version}}/node-v${{ matrix.nodejs_version}}-linux-${{ matrix.nodejs_arch }}.tar.xz | tar xJC /opt/nodejs --strip-components=1
|
||||
export PATH=$PATH:/opt/nodejs/bin
|
||||
npm install --build-from-source
|
||||
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||
npm run package-from-local-build
|
||||
npm pkg set "optionalDependencies.@img/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
||||
npm run clean
|
||||
npm install --ignore-scripts
|
||||
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||
[[ -n $prebuild_upload ]] && cd src && ln -s ../package.json && npx prebuild || true
|
||||
github-runner-emscripten:
|
||||
permissions:
|
||||
contents: write
|
||||
name: wasm32 - prebuild
|
||||
runs-on: ubuntu-22.04
|
||||
container: "emscripten/emsdk:3.1.51"
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Dependencies
|
||||
run: apt-get update && apt-get install -y pkg-config
|
||||
- name: Dependencies (Node.js)
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "20"
|
||||
- name: Install
|
||||
run: emmake npm install --build-from-source
|
||||
- name: Verify emscripten versions match
|
||||
run: |
|
||||
EMSCRIPTEN_VERSION_LIBVIPS=$(node -p "require('@img/sharp-libvips-dev-wasm32/versions').emscripten")
|
||||
EMSCRIPTEN_VERSION_SHARP=$(emcc -dumpversion)
|
||||
echo "libvips built with emscripten $EMSCRIPTEN_VERSION_LIBVIPS"
|
||||
echo "sharp built with emscripten $EMSCRIPTEN_VERSION_SHARP"
|
||||
test "$EMSCRIPTEN_VERSION_LIBVIPS" = "$EMSCRIPTEN_VERSION_SHARP"
|
||||
- name: Test
|
||||
run: emmake npm test
|
||||
- name: Test packaging
|
||||
run: |
|
||||
emmake npm run package-from-local-build
|
||||
npm pkg set "optionalDependencies.@img/sharp-wasm32=file:./npm/wasm32"
|
||||
npm run clean
|
||||
rm -rf node_modules/@img/sharp-linux-x64
|
||||
npm install --cpu=wasm32
|
||||
npm test
|
||||
- name: Prebuild
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
env:
|
||||
npm_config_nodedir: emscripten
|
||||
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: cd src && ln -s ../package.json && emmake npx prebuild --platform=emscripten --arch=wasm32 --strip=0
|
||||
macstadium-runner:
|
||||
permissions:
|
||||
contents: write
|
||||
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} ${{ matrix.prebuild && '- prebuild' }}
|
||||
runs-on: macos-m1
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: darwin-x64
|
||||
- nodejs_arch: arm64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: darwin-arm64
|
||||
prebuild: true
|
||||
defaults:
|
||||
run:
|
||||
shell: /usr/bin/arch -arch arm64e /bin/bash -l {0}
|
||||
steps:
|
||||
- name: Dependencies (Node.js)
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.nodejs_version }}
|
||||
architecture: ${{ matrix.nodejs_arch }}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install
|
||||
run: npm install --build-from-source
|
||||
- name: Test
|
||||
run: npm test
|
||||
- name: Test packaging
|
||||
run: |
|
||||
npm run package-from-local-build
|
||||
npm pkg set "optionalDependencies.@img/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
||||
npm run clean
|
||||
npm install --ignore-scripts
|
||||
npm test
|
||||
- name: Prebuild
|
||||
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
|
||||
env:
|
||||
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: cd src && ln -s ../package.json && npx prebuild
|
||||
174
.github/workflows/npm.yml
vendored
Normal file
174
.github/workflows/npm.yml
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
name: "CI: npm smoke test"
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v**"
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
release-smoke-test:
|
||||
name: "${{ github.ref_name }} ${{ matrix.name }}"
|
||||
runs-on: ${{ matrix.runs-on }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: linux-x64-node-npm
|
||||
runs-on: ubuntu-22.04
|
||||
runtime: node
|
||||
package-manager: npm
|
||||
- name: linux-x64-node-pnpm
|
||||
runs-on: ubuntu-22.04
|
||||
runtime: node
|
||||
package-manager: pnpm
|
||||
- name: linux-x64-node-yarn
|
||||
runs-on: ubuntu-22.04
|
||||
runtime: node
|
||||
package-manager: yarn
|
||||
- name: linux-x64-node-yarn-pnp
|
||||
runs-on: ubuntu-22.04
|
||||
runtime: node
|
||||
package-manager: yarn-pnp
|
||||
- name: linux-x64-deno
|
||||
runs-on: ubuntu-22.04
|
||||
runtime: deno
|
||||
- name: linux-x64-bun
|
||||
runs-on: ubuntu-22.04
|
||||
runtime: bun
|
||||
|
||||
- name: darwin-x64-node-npm
|
||||
runs-on: macos-11
|
||||
runtime: node
|
||||
package-manager: npm
|
||||
- name: darwin-x64-node-pnpm
|
||||
runs-on: macos-11
|
||||
runtime: node
|
||||
package-manager: pnpm
|
||||
- name: darwin-x64-node-yarn
|
||||
runs-on: macos-11
|
||||
runtime: node
|
||||
package-manager: yarn
|
||||
- name: darwin-x64-node-yarn-pnp
|
||||
runs-on: macos-11
|
||||
runtime: node
|
||||
package-manager: yarn-pnp
|
||||
- name: darwin-x64-deno
|
||||
runs-on: macos-11
|
||||
runtime: deno
|
||||
- name: darwin-x64-bun
|
||||
runs-on: macos-11
|
||||
runtime: bun
|
||||
|
||||
- name: win32-x64-node-npm
|
||||
runs-on: windows-2019
|
||||
runtime: node
|
||||
package-manager: npm
|
||||
- name: win32-x64-node-pnpm
|
||||
runs-on: windows-2019
|
||||
runtime: node
|
||||
package-manager: pnpm
|
||||
- name: win32-x64-node-yarn
|
||||
runs-on: windows-2019
|
||||
runtime: node
|
||||
package-manager: yarn
|
||||
- name: win32-x64-node-yarn-pnp
|
||||
runs-on: windows-2019
|
||||
runtime: node
|
||||
package-manager: yarn-pnp
|
||||
- name: win32-x64-deno
|
||||
runs-on: windows-2019
|
||||
runtime: deno
|
||||
|
||||
steps:
|
||||
- name: Install Node.js
|
||||
if: ${{ matrix.runtime == 'node' }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 20
|
||||
- name: Install pnpm
|
||||
if: ${{ matrix.package-manager == 'pnpm' }}
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
- name: Install Deno
|
||||
if: ${{ matrix.runtime == 'deno' }}
|
||||
uses: denoland/setup-deno@v1
|
||||
with:
|
||||
deno-version: v1.x
|
||||
- name: Install Bun
|
||||
if: ${{ matrix.runtime == 'bun' }}
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Version
|
||||
id: version
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
core.setOutput('semver', context.ref.replace('refs/tags/v',''))
|
||||
- name: Create package.json
|
||||
uses: DamianReeves/write-file-action@v1.2
|
||||
with:
|
||||
path: package.json
|
||||
contents: |
|
||||
{
|
||||
"dependencies": {
|
||||
"sharp": "${{ steps.version.outputs.semver }}"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
- name: Create release.mjs
|
||||
uses: DamianReeves/write-file-action@v1.2
|
||||
with:
|
||||
path: release.mjs
|
||||
contents: |
|
||||
import { deepStrictEqual } from 'node:assert';
|
||||
import sharp from 'sharp';
|
||||
deepStrictEqual(['.jpg', '.jpeg', '.jpe', '.jfif'], sharp.format.jpeg.input.fileSuffix);
|
||||
|
||||
- name: Run with Node.js + npm
|
||||
if: ${{ matrix.package-manager == 'npm' }}
|
||||
run: |
|
||||
npm install --ignore-scripts
|
||||
node release.mjs
|
||||
|
||||
- name: Run with Node.js + pnpm
|
||||
if: ${{ matrix.package-manager == 'pnpm' }}
|
||||
run: |
|
||||
pnpm install --ignore-scripts
|
||||
node release.mjs
|
||||
|
||||
- name: Run with Node.js + yarn
|
||||
if: ${{ matrix.package-manager == 'yarn' }}
|
||||
run: |
|
||||
corepack enable
|
||||
yarn set version stable
|
||||
yarn config set enableImmutableInstalls false
|
||||
yarn config set enableScripts false
|
||||
yarn config set nodeLinker node-modules
|
||||
yarn install
|
||||
node release.mjs
|
||||
|
||||
- name: Run with Node.js + yarn pnp
|
||||
if: ${{ matrix.package-manager == 'yarn-pnp' }}
|
||||
run: |
|
||||
corepack enable
|
||||
yarn set version stable
|
||||
yarn config set enableImmutableInstalls false
|
||||
yarn config set enableScripts false
|
||||
yarn config set nodeLinker pnp
|
||||
yarn install
|
||||
yarn node release.mjs
|
||||
|
||||
- name: Run with Deno
|
||||
if: ${{ matrix.runtime == 'deno' }}
|
||||
run: deno run --allow-read --allow-ffi release.mjs
|
||||
|
||||
- name: Run with Bun
|
||||
if: ${{ matrix.runtime == 'bun' }}
|
||||
run: |
|
||||
bun install --ignore-scripts
|
||||
bun release.mjs
|
||||
17
.gitignore
vendored
17
.gitignore
vendored
@@ -1,11 +1,16 @@
|
||||
build
|
||||
src/build
|
||||
src/node_modules
|
||||
node_modules
|
||||
coverage
|
||||
/coverage
|
||||
npm/*/*
|
||||
!npm/*/package.json
|
||||
test/bench/node_modules
|
||||
test/fixtures/output*
|
||||
test/fixtures/vips-properties.xml
|
||||
test/leak/libvips.supp
|
||||
lib
|
||||
include
|
||||
packaging/libvips*
|
||||
packaging/*.log
|
||||
.DS_Store
|
||||
.nyc_output
|
||||
.vscode/
|
||||
package-lock.json
|
||||
.idea
|
||||
.firebase
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
node_modules
|
||||
test/bench/node_modules
|
||||
coverage
|
||||
12
.jshintrc
12
.jshintrc
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"strict": true,
|
||||
"node": true,
|
||||
"maxparams": 4,
|
||||
"maxcomplexity": 13,
|
||||
"globals": {
|
||||
"beforeEach": true,
|
||||
"afterEach": true,
|
||||
"describe": true,
|
||||
"it": true
|
||||
}
|
||||
}
|
||||
7
.mocharc.jsonc
Normal file
7
.mocharc.jsonc
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"parallel": true,
|
||||
"slow": 1000,
|
||||
"timeout": 30000,
|
||||
"require": "./test/beforeEach.js",
|
||||
"spec": "./test/unit/*.js"
|
||||
}
|
||||
16
.npmignore
16
.npmignore
@@ -1,16 +0,0 @@
|
||||
build
|
||||
node_modules
|
||||
coverage
|
||||
.editorconfig
|
||||
.jshintignore
|
||||
.jshintrc
|
||||
.gitignore
|
||||
test
|
||||
.travis.yml
|
||||
appveyor.yml
|
||||
circle.yml
|
||||
mkdocs.yml
|
||||
lib
|
||||
include
|
||||
packaging
|
||||
preinstall.sh
|
||||
6
.prebuildrc
Normal file
6
.prebuildrc
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"runtime": "napi",
|
||||
"include-regex": "(sharp-.+\\.node|libvips-.+\\.dll)",
|
||||
"prerelease": true,
|
||||
"strip": true
|
||||
}
|
||||
23
.travis.yml
23
.travis.yml
@@ -1,23 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4"
|
||||
- "5"
|
||||
- "6"
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
sudo: false
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
||||
osx_image: xcode7.3
|
||||
before_install:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install homebrew/science/vips; fi
|
||||
after_success:
|
||||
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
|
||||
106
README.md
106
README.md
@@ -1,11 +1,18 @@
|
||||
# sharp
|
||||
|
||||
The typical use case for this high speed Node.js module
|
||||
<img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
||||
|
||||
The typical use case for this high speed Node-API module
|
||||
is to convert large images in common formats to
|
||||
smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
||||
smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
|
||||
|
||||
It can be used with all JavaScript runtimes
|
||||
that provide support for Node-API v9, including
|
||||
Node.js (^18.17.0 or >= 20.3.0), Deno and Bun.
|
||||
|
||||
Resizing an image is typically 4x-5x faster than using the
|
||||
quickest ImageMagick and GraphicsMagick settings.
|
||||
quickest ImageMagick and GraphicsMagick settings
|
||||
due to its use of [libvips](https://github.com/libvips/libvips).
|
||||
|
||||
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
||||
Lanczos resampling ensures quality is not sacrificed for speed.
|
||||
@@ -13,35 +20,96 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
||||
As well as image resizing, operations such as
|
||||
rotation, extraction, compositing and gamma correction are available.
|
||||
|
||||
Most Windows (x64), Linux and ARMv6+ systems do not require
|
||||
the installation of any external runtime dependencies.
|
||||
Most modern macOS, Windows and Linux systems
|
||||
do not require any additional install or runtime dependencies.
|
||||
|
||||
Use with OS X is as simple as running `brew install homebrew/science/vips`
|
||||
to install the libvips dependency.
|
||||
## Documentation
|
||||
|
||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||
Visit [sharp.pixelplumbing.com](https://sharp.pixelplumbing.com/) for complete
|
||||
[installation instructions](https://sharp.pixelplumbing.com/install),
|
||||
[API documentation](https://sharp.pixelplumbing.com/api-constructor),
|
||||
[benchmark tests](https://sharp.pixelplumbing.com/performance) and
|
||||
[changelog](https://sharp.pixelplumbing.com/changelog).
|
||||
|
||||
### Documentation
|
||||
## Examples
|
||||
|
||||
Visit [sharp.dimens.io](http://sharp.dimens.io/) for complete
|
||||
[installation instructions](http://sharp.dimens.io/page/install),
|
||||
[API documentation](http://sharp.dimens.io/page/api),
|
||||
[benchmark tests](http://sharp.dimens.io/page/performance) and
|
||||
[changelog](http://sharp.dimens.io/page/changelog).
|
||||
```sh
|
||||
npm install sharp
|
||||
```
|
||||
|
||||
### Contributing
|
||||
```javascript
|
||||
const sharp = require('sharp');
|
||||
```
|
||||
|
||||
A [guide for contributors](https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md)
|
||||
### Callback
|
||||
|
||||
```javascript
|
||||
sharp(inputBuffer)
|
||||
.resize(320, 240)
|
||||
.toFile('output.webp', (err, info) => { ... });
|
||||
```
|
||||
|
||||
### Promise
|
||||
|
||||
```javascript
|
||||
sharp('input.jpg')
|
||||
.rotate()
|
||||
.resize(200)
|
||||
.jpeg({ mozjpeg: true })
|
||||
.toBuffer()
|
||||
.then( data => { ... })
|
||||
.catch( err => { ... });
|
||||
```
|
||||
|
||||
### Async/await
|
||||
|
||||
```javascript
|
||||
const semiTransparentRedPng = await sharp({
|
||||
create: {
|
||||
width: 48,
|
||||
height: 48,
|
||||
channels: 4,
|
||||
background: { r: 255, g: 0, b: 0, alpha: 0.5 }
|
||||
}
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
### Stream
|
||||
|
||||
```javascript
|
||||
const roundedCorners = Buffer.from(
|
||||
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
|
||||
);
|
||||
|
||||
const roundedCornerResizer =
|
||||
sharp()
|
||||
.resize(200, 200)
|
||||
.composite([{
|
||||
input: roundedCorners,
|
||||
blend: 'dest-in'
|
||||
}])
|
||||
.png();
|
||||
|
||||
readableStream
|
||||
.pipe(roundedCornerResizer)
|
||||
.pipe(writableStream);
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
A [guide for contributors](https://github.com/lovell/sharp/blob/main/.github/CONTRIBUTING.md)
|
||||
covers reporting bugs, requesting features and submitting code changes.
|
||||
|
||||
### Licence
|
||||
## Licensing
|
||||
|
||||
Copyright 2013, 2014, 2015, 2016 Lovell Fuller and contributors.
|
||||
Copyright 2013 Lovell Fuller and others.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
||||
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
||||
16
appveyor.yml
16
appveyor.yml
@@ -1,16 +0,0 @@
|
||||
os: Visual Studio 2015
|
||||
version: "{build}"
|
||||
build: off
|
||||
platform: x64
|
||||
environment:
|
||||
VIPS_WARNING: 0
|
||||
matrix:
|
||||
- nodejs_version: "0.12"
|
||||
- nodejs_version: "4"
|
||||
- nodejs_version: "5"
|
||||
- nodejs_version: "6"
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version x64
|
||||
- npm install
|
||||
test_script:
|
||||
- npm run-script test-win
|
||||
256
binding.gyp
256
binding.gyp
@@ -1,256 +0,0 @@
|
||||
{
|
||||
'targets': [{
|
||||
'target_name': 'libvips-cpp',
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
||||
'type': 'shared_library',
|
||||
'variables': {
|
||||
'download_vips': '<!(node -e "require(\'./binding\').download_vips()")'
|
||||
},
|
||||
'defines': [
|
||||
'VIPS_CPLUSPLUS_EXPORTS',
|
||||
'_ALLOW_KEYWORD_MACROS'
|
||||
],
|
||||
'sources': [
|
||||
'src/libvips/cplusplus/VError.cpp',
|
||||
'src/libvips/cplusplus/VInterpolate.cpp',
|
||||
'src/libvips/cplusplus/VImage.cpp'
|
||||
],
|
||||
'include_dirs': [
|
||||
'<(module_root_dir)/include',
|
||||
'<(module_root_dir)/include/glib-2.0',
|
||||
'<(module_root_dir)/lib/glib-2.0/include'
|
||||
],
|
||||
'libraries': [
|
||||
'<(module_root_dir)/lib/libvips.lib',
|
||||
'<(module_root_dir)/lib/libglib-2.0.lib',
|
||||
'<(module_root_dir)/lib/libgobject-2.0.lib'
|
||||
],
|
||||
'configurations': {
|
||||
'Release': {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'ExceptionHandling': 1
|
||||
}
|
||||
},
|
||||
'msvs_disabled_warnings': [
|
||||
4275
|
||||
]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
# Ignore this target for non-Windows
|
||||
'type': 'none'
|
||||
}]
|
||||
]
|
||||
}, {
|
||||
'target_name': 'sharp',
|
||||
'dependencies': [
|
||||
'libvips-cpp'
|
||||
],
|
||||
# Nested variables "pattern" borrowed from http://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi
|
||||
'variables': {
|
||||
'variables': {
|
||||
'variables': {
|
||||
'conditions': [
|
||||
['OS != "win"', {
|
||||
# Build the PKG_CONFIG_PATH environment variable with all possible combinations
|
||||
'pkg_config_path': '<!(which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR || true):$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig'
|
||||
}, {
|
||||
'pkg_config_path': ''
|
||||
}]
|
||||
],
|
||||
},
|
||||
'conditions': [
|
||||
['OS != "win"', {
|
||||
# Which version, if any, of libvips is available globally via pkg-config?
|
||||
'global_vips_version': '<!(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --modversion vips-cpp 2>/dev/null || true)'
|
||||
}, {
|
||||
'global_vips_version': ''
|
||||
}]
|
||||
],
|
||||
'pkg_config_path%': '<(pkg_config_path)'
|
||||
},
|
||||
'pkg_config_path%': '<(pkg_config_path)',
|
||||
'runtime_link%': 'shared',
|
||||
'conditions': [
|
||||
['OS != "win"', {
|
||||
# Does the globally available version of libvips, if any, meet the minimum version requirement?
|
||||
'use_global_vips': '<!(GLOBAL_VIPS_VERSION="<(global_vips_version)" node -e "require(\'./binding\').use_global_vips()")'
|
||||
}, {
|
||||
'use_global_vips': ''
|
||||
}]
|
||||
]
|
||||
},
|
||||
'sources': [
|
||||
'src/common.cc',
|
||||
'src/metadata.cc',
|
||||
'src/operations.cc',
|
||||
'src/pipeline.cc',
|
||||
'src/sharp.cc',
|
||||
'src/utilities.cc'
|
||||
],
|
||||
'defines': [
|
||||
'_GLIBCXX_USE_CXX11_ABI=0',
|
||||
'_ALLOW_KEYWORD_MACROS'
|
||||
],
|
||||
'include_dirs': [
|
||||
'<!(node -e "require(\'nan\')")'
|
||||
],
|
||||
'conditions': [
|
||||
['use_global_vips == "true"', {
|
||||
# Use pkg-config for include and lib
|
||||
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
|
||||
'conditions': [
|
||||
['runtime_link == "static"', {
|
||||
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs --static vips-cpp)']
|
||||
}, {
|
||||
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)']
|
||||
}]
|
||||
]
|
||||
}, {
|
||||
# Attempt to download pre-built libvips and install locally within node_modules
|
||||
'include_dirs': [
|
||||
'<(module_root_dir)/include',
|
||||
'<(module_root_dir)/include/glib-2.0',
|
||||
'<(module_root_dir)/lib/glib-2.0/include'
|
||||
],
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
'libraries': [
|
||||
'<(module_root_dir)/lib/libvips.lib',
|
||||
'<(module_root_dir)/lib/libglib-2.0.lib',
|
||||
'<(module_root_dir)/lib/libgobject-2.0.lib'
|
||||
]
|
||||
}],
|
||||
['OS == "linux"', {
|
||||
'variables': {
|
||||
'download_vips': '<!(LDD_VERSION="<!(ldd --version 2>&1 || true)" node -e "require(\'./binding\').download_vips()")'
|
||||
},
|
||||
'libraries': [
|
||||
'<(module_root_dir)/lib/libvips-cpp.so',
|
||||
'<(module_root_dir)/lib/libvips.so',
|
||||
'<(module_root_dir)/lib/libglib-2.0.so',
|
||||
'<(module_root_dir)/lib/libgobject-2.0.so',
|
||||
# Dependencies of dependencies, included for openSUSE support
|
||||
'<(module_root_dir)/lib/libcairo.so',
|
||||
'<(module_root_dir)/lib/libcroco-0.6.so',
|
||||
'<(module_root_dir)/lib/libexif.so',
|
||||
'<(module_root_dir)/lib/libffi.so',
|
||||
'<(module_root_dir)/lib/libfontconfig.so',
|
||||
'<(module_root_dir)/lib/libfreetype.so',
|
||||
'<(module_root_dir)/lib/libgdk_pixbuf-2.0.so',
|
||||
'<(module_root_dir)/lib/libgif.so',
|
||||
'<(module_root_dir)/lib/libgio-2.0.so',
|
||||
'<(module_root_dir)/lib/libgmodule-2.0.so',
|
||||
'<(module_root_dir)/lib/libgsf-1.so',
|
||||
'<(module_root_dir)/lib/libgthread-2.0.so',
|
||||
'<(module_root_dir)/lib/libharfbuzz.so',
|
||||
'<(module_root_dir)/lib/libjpeg.so',
|
||||
'<(module_root_dir)/lib/liblcms2.so',
|
||||
'<(module_root_dir)/lib/liborc-0.4.so',
|
||||
'<(module_root_dir)/lib/libpango-1.0.so',
|
||||
'<(module_root_dir)/lib/libpangocairo-1.0.so',
|
||||
'<(module_root_dir)/lib/libpangoft2-1.0.so',
|
||||
'<(module_root_dir)/lib/libpixman-1.so',
|
||||
'<(module_root_dir)/lib/libpng.so',
|
||||
'<(module_root_dir)/lib/libpng16.so',
|
||||
'<(module_root_dir)/lib/librsvg-2.so',
|
||||
'<(module_root_dir)/lib/libtiff.so',
|
||||
'<(module_root_dir)/lib/libwebp.so',
|
||||
'<(module_root_dir)/lib/libxml2.so',
|
||||
'<(module_root_dir)/lib/libz.so',
|
||||
# Ensure runtime linking is relative to sharp.node
|
||||
'-Wl,-rpath=\'$${ORIGIN}/../../lib\''
|
||||
]
|
||||
}]
|
||||
]
|
||||
}]
|
||||
],
|
||||
'cflags_cc': [
|
||||
'-std=c++0x',
|
||||
'-fexceptions',
|
||||
'-Wall',
|
||||
'-O3'
|
||||
],
|
||||
'xcode_settings': {
|
||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
||||
'CLANG_CXX_LIBRARY': 'libc++',
|
||||
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
||||
'GCC_ENABLE_CPP_RTTI': 'YES',
|
||||
'OTHER_CPLUSPLUSFLAGS': [
|
||||
'-fexceptions',
|
||||
'-Wall',
|
||||
'-O3'
|
||||
]
|
||||
},
|
||||
'configurations': {
|
||||
'Release': {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'ExceptionHandling': 1
|
||||
}
|
||||
},
|
||||
'msvs_disabled_warnings': [
|
||||
4275
|
||||
]
|
||||
}
|
||||
},
|
||||
}, {
|
||||
'target_name': 'win_copy_dlls',
|
||||
'type': 'none',
|
||||
'dependencies': [
|
||||
'sharp'
|
||||
],
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
# Windows lacks support for rpath
|
||||
'copies': [{
|
||||
'destination': '<(module_root_dir)/build/Release',
|
||||
'files': [
|
||||
'<(module_root_dir)/lib/GNU.Gettext.dll',
|
||||
'<(module_root_dir)/lib/libasprintf-0.dll',
|
||||
'<(module_root_dir)/lib/libcairo-2.dll',
|
||||
'<(module_root_dir)/lib/libcairo-gobject-2.dll',
|
||||
'<(module_root_dir)/lib/libcairo-script-interpreter-2.dll',
|
||||
'<(module_root_dir)/lib/libcroco-0.6-3.dll',
|
||||
'<(module_root_dir)/lib/libexif-12.dll',
|
||||
'<(module_root_dir)/lib/libexpat-1.dll',
|
||||
'<(module_root_dir)/lib/libffi-6.dll',
|
||||
'<(module_root_dir)/lib/libfftw3-3.dll',
|
||||
'<(module_root_dir)/lib/libfontconfig-1.dll',
|
||||
'<(module_root_dir)/lib/libfreetype-6.dll',
|
||||
'<(module_root_dir)/lib/libgcc_s_seh-1.dll',
|
||||
'<(module_root_dir)/lib/libgdk_pixbuf-2.0-0.dll',
|
||||
'<(module_root_dir)/lib/libgif-4.dll',
|
||||
'<(module_root_dir)/lib/libgio-2.0-0.dll',
|
||||
'<(module_root_dir)/lib/libglib-2.0-0.dll',
|
||||
'<(module_root_dir)/lib/libgmodule-2.0-0.dll',
|
||||
'<(module_root_dir)/lib/libgobject-2.0-0.dll',
|
||||
'<(module_root_dir)/lib/libgsf-1-114.dll',
|
||||
'<(module_root_dir)/lib/libgthread-2.0-0.dll',
|
||||
'<(module_root_dir)/lib/libintl-8.dll',
|
||||
'<(module_root_dir)/lib/libjpeg-62.dll',
|
||||
'<(module_root_dir)/lib/liblcms2-2.dll',
|
||||
'<(module_root_dir)/lib/libpango-1.0-0.dll',
|
||||
'<(module_root_dir)/lib/libpangocairo-1.0-0.dll',
|
||||
'<(module_root_dir)/lib/libpangowin32-1.0-0.dll',
|
||||
'<(module_root_dir)/lib/libpixman-1-0.dll',
|
||||
'<(module_root_dir)/lib/libpng16-16.dll',
|
||||
'<(module_root_dir)/lib/libquadmath-0.dll',
|
||||
'<(module_root_dir)/lib/librsvg-2-2.dll',
|
||||
'<(module_root_dir)/lib/libssp-0.dll',
|
||||
'<(module_root_dir)/lib/libstdc++-6.dll',
|
||||
'<(module_root_dir)/lib/libtiff-5.dll',
|
||||
'<(module_root_dir)/lib/libvips-42.dll',
|
||||
'<(module_root_dir)/lib/libwebp-6.dll',
|
||||
'<(module_root_dir)/lib/libxml2-2.dll',
|
||||
'<(module_root_dir)/lib/zlib1.dll'
|
||||
]
|
||||
}]
|
||||
}]
|
||||
]
|
||||
}]
|
||||
}
|
||||
134
binding.js
134
binding.js
@@ -1,134 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var zlib = require('zlib');
|
||||
|
||||
var semver = require('semver');
|
||||
var request = require('request');
|
||||
var tar = require('tar');
|
||||
|
||||
var tmp = require('os').tmpdir();
|
||||
|
||||
var distBaseUrl = 'https://dl.bintray.com/lovell/sharp/';
|
||||
|
||||
// Use NPM-provided environment variable where available, falling back to require-based method for Electron
|
||||
var minimumLibvipsVersion = process.env.npm_package_config_libvips || require('./package.json').config.libvips;
|
||||
|
||||
var vipsHeaderPath = path.join(__dirname, 'include', 'vips', 'vips.h');
|
||||
|
||||
// -- Helpers
|
||||
|
||||
// Does this file exist?
|
||||
var isFile = function(file) {
|
||||
var exists = false;
|
||||
try {
|
||||
exists = fs.statSync(file).isFile();
|
||||
} catch (err) {}
|
||||
return exists;
|
||||
};
|
||||
|
||||
var unpack = function(tarPath, done) {
|
||||
var extractor = tar.Extract({
|
||||
path: __dirname
|
||||
});
|
||||
extractor.on('error', error);
|
||||
extractor.on('end', function() {
|
||||
if (!isFile(vipsHeaderPath)) {
|
||||
error('Could not unpack ' + tarPath);
|
||||
}
|
||||
if (typeof done === 'function') {
|
||||
done();
|
||||
}
|
||||
});
|
||||
fs.createReadStream(tarPath).on('error', error)
|
||||
.pipe(zlib.Unzip())
|
||||
.pipe(extractor);
|
||||
};
|
||||
|
||||
// Error
|
||||
var error = function(msg) {
|
||||
if (msg instanceof Error) {
|
||||
msg = msg.message;
|
||||
}
|
||||
process.stderr.write('ERROR: ' + msg + '\n');
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
// -- Binary downloaders
|
||||
|
||||
module.exports.download_vips = function() {
|
||||
// Has vips been installed locally?
|
||||
if (!isFile(vipsHeaderPath)) {
|
||||
// Ensure Intel 64-bit or ARM
|
||||
if (process.arch === 'ia32') {
|
||||
error('Intel Architecture 32-bit systems require manual installation - please see http://sharp.dimens.io/en/stable/install/');
|
||||
}
|
||||
// Ensure glibc >= 2.15
|
||||
var lddVersion = process.env.LDD_VERSION;
|
||||
if (lddVersion) {
|
||||
if (/(glibc|gnu libc)/i.test(lddVersion)) {
|
||||
var glibcVersion = lddVersion ? lddVersion.split(/\n/)[0].split(' ').slice(-1)[0].trim() : '';
|
||||
if (glibcVersion && semver.lt(glibcVersion + '.0', '2.13.0')) {
|
||||
error('glibc version ' + glibcVersion + ' requires manual installation - please see http://sharp.dimens.io/en/stable/install/');
|
||||
}
|
||||
} else {
|
||||
error(lddVersion.split(/\n/)[0] + ' requires manual installation - please see http://sharp.dimens.io/en/stable/install/');
|
||||
}
|
||||
}
|
||||
// Arch/platform-specific .tar.gz
|
||||
var platform = (process.arch === 'arm') ? 'arm' : process.platform.substr(0, 3);
|
||||
var tarFilename = ['libvips', minimumLibvipsVersion, platform].join('-') + '.tar.gz';
|
||||
var tarPath = path.join(__dirname, 'packaging', tarFilename);
|
||||
if (isFile(tarPath)) {
|
||||
unpack(tarPath);
|
||||
} else {
|
||||
// Download to per-process temporary file
|
||||
tarPath = path.join(tmp, process.pid + '-' + tarFilename);
|
||||
var tmpFile = fs.createWriteStream(tarPath).on('finish', function() {
|
||||
unpack(tarPath, function() {
|
||||
// Attempt to remove temporary file
|
||||
try {
|
||||
fs.unlinkSync(tarPath);
|
||||
} catch (err) {}
|
||||
});
|
||||
});
|
||||
var options = {
|
||||
url: distBaseUrl + tarFilename
|
||||
};
|
||||
if (process.env.npm_config_https_proxy) {
|
||||
// Use the NPM-configured HTTPS proxy
|
||||
options.proxy = process.env.npm_config_https_proxy;
|
||||
}
|
||||
request(options).on('response', function(response) {
|
||||
if (response.statusCode !== 200) {
|
||||
error(distBaseUrl + tarFilename + ' status code ' + response.statusCode);
|
||||
}
|
||||
}).on('error', function(err) {
|
||||
error('Download from ' + distBaseUrl + tarFilename + ' failed: ' + err.message);
|
||||
}).pipe(tmpFile);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.use_global_vips = function() {
|
||||
var useGlobalVips = false;
|
||||
var globalVipsVersion = process.env.GLOBAL_VIPS_VERSION;
|
||||
if (globalVipsVersion) {
|
||||
useGlobalVips = semver.gte(
|
||||
globalVipsVersion,
|
||||
minimumLibvipsVersion
|
||||
);
|
||||
}
|
||||
if (process.platform === 'darwin' && !useGlobalVips) {
|
||||
if (globalVipsVersion) {
|
||||
error(
|
||||
'Found libvips ' + globalVipsVersion + ' but require ' + minimumLibvipsVersion +
|
||||
'\nPlease upgrade libvips by running: brew update && brew upgrade'
|
||||
);
|
||||
} else {
|
||||
error('Please install libvips by running: brew install homebrew/science/vips --with-webp --with-graphicsmagick');
|
||||
}
|
||||
}
|
||||
process.stdout.write(useGlobalVips ? 'true' : 'false');
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
machine:
|
||||
services:
|
||||
- docker
|
||||
test:
|
||||
override:
|
||||
- ./packaging/test.sh
|
||||
92
docs/README.md
Normal file
92
docs/README.md
Normal file
@@ -0,0 +1,92 @@
|
||||
# sharp
|
||||
|
||||
<img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
||||
|
||||
The typical use case for this high speed Node-API module
|
||||
is to convert large images in common formats to
|
||||
smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
|
||||
|
||||
It can be used with all JavaScript runtimes
|
||||
that provide support for Node-API v9, including
|
||||
Node.js >= 18.17.0, Deno and Bun.
|
||||
|
||||
Resizing an image is typically 4x-5x faster than using the
|
||||
quickest ImageMagick and GraphicsMagick settings
|
||||
due to its use of [libvips](https://github.com/libvips/libvips).
|
||||
|
||||
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
||||
Lanczos resampling ensures quality is not sacrificed for speed.
|
||||
|
||||
As well as image resizing, operations such as
|
||||
rotation, extraction, compositing and gamma correction are available.
|
||||
|
||||
Most modern macOS, Windows and Linux systems
|
||||
do not require any additional install or runtime dependencies.
|
||||
|
||||
### Formats
|
||||
|
||||
This module supports reading JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG images.
|
||||
|
||||
Output images can be in JPEG, PNG, WebP, GIF, AVIF and TIFF formats as well as uncompressed raw pixel data.
|
||||
|
||||
Streams, Buffer objects and the filesystem can be used for input and output.
|
||||
|
||||
A single input Stream can be split into multiple processing pipelines and output Streams.
|
||||
|
||||
Deep Zoom image pyramids can be generated,
|
||||
suitable for use with "slippy map" tile viewers like
|
||||
[OpenSeadragon](https://github.com/openseadragon/openseadragon).
|
||||
|
||||
### Fast
|
||||
|
||||
This module is powered by the blazingly fast
|
||||
[libvips](https://github.com/libvips/libvips) image processing library,
|
||||
originally created in 1989 at Birkbeck College
|
||||
and currently maintained by a small team led by
|
||||
[John Cupitt](https://github.com/jcupitt).
|
||||
|
||||
Only small regions of uncompressed image data
|
||||
are held in memory and processed at a time,
|
||||
taking full advantage of multiple CPU cores and L1/L2/L3 cache.
|
||||
|
||||
Everything remains non-blocking thanks to _libuv_,
|
||||
no child processes are spawned and Promises/async/await are supported.
|
||||
|
||||
### Optimal
|
||||
|
||||
The features of `mozjpeg` and `pngquant` can be used
|
||||
to optimise the file size of JPEG and PNG images respectively,
|
||||
without having to invoke separate `imagemin` processes.
|
||||
|
||||
Huffman tables are optimised when generating JPEG output images
|
||||
without having to use separate command line tools like
|
||||
[jpegoptim](https://github.com/tjko/jpegoptim) and
|
||||
[jpegtran](http://jpegclub.org/jpegtran/).
|
||||
|
||||
PNG filtering is disabled by default,
|
||||
which for diagrams and line art often produces the same result
|
||||
as [pngcrush](https://pmt.sourceforge.io/pngcrush/).
|
||||
|
||||
The file size of animated GIF output is optimised
|
||||
without having to use separate command line tools such as
|
||||
[gifsicle](https://www.lcdf.org/gifsicle/).
|
||||
|
||||
### Contributing
|
||||
|
||||
A [guide for contributors](https://github.com/lovell/sharp/blob/main/.github/CONTRIBUTING.md)
|
||||
covers reporting bugs, requesting features and submitting code changes.
|
||||
|
||||
### Licensing
|
||||
|
||||
Copyright 2013 Lovell Fuller and others.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
136
docs/api-channel.md
Normal file
136
docs/api-channel.md
Normal file
@@ -0,0 +1,136 @@
|
||||
## removeAlpha
|
||||
> removeAlpha() ⇒ <code>Sharp</code>
|
||||
|
||||
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||
|
||||
See also [flatten](/api-operation#flatten).
|
||||
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp('rgba.png')
|
||||
.removeAlpha()
|
||||
.toFile('rgb.png', function(err, info) {
|
||||
// rgb.png is a 3 channel image without an alpha channel
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## ensureAlpha
|
||||
> ensureAlpha([alpha]) ⇒ <code>Sharp</code>
|
||||
|
||||
Ensure the output image has an alpha transparency channel.
|
||||
If missing, the added alpha channel will have the specified
|
||||
transparency level, defaulting to fully-opaque (1).
|
||||
This is a no-op if the image already has an alpha channel.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid alpha transparency level
|
||||
|
||||
**Since**: 0.21.2
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [alpha] | <code>number</code> | <code>1</code> | alpha transparency level (0=fully-transparent, 1=fully-opaque) |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// rgba.png will be a 4 channel image with a fully-opaque alpha channel
|
||||
await sharp('rgb.jpg')
|
||||
.ensureAlpha()
|
||||
.toFile('rgba.png')
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// rgba is a 4 channel image with a fully-transparent alpha channel
|
||||
const rgba = await sharp(rgb)
|
||||
.ensureAlpha(0)
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## extractChannel
|
||||
> extractChannel(channel) ⇒ <code>Sharp</code>
|
||||
|
||||
Extract a single channel from a multi-channel image.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid channel
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| channel | <code>number</code> \| <code>string</code> | zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// green.jpg is a greyscale image containing the green channel of the input
|
||||
await sharp(input)
|
||||
.extractChannel('green')
|
||||
.toFile('green.jpg');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// red1 is the red value of the first pixel, red2 the second pixel etc.
|
||||
const [red1, red2, ...] = await sharp(input)
|
||||
.extractChannel(0)
|
||||
.raw()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## joinChannel
|
||||
> joinChannel(images, options) ⇒ <code>Sharp</code>
|
||||
|
||||
Join one or more channels to the image.
|
||||
The meaning of the added channels depends on the output colourspace, set with `toColourspace()`.
|
||||
By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||
Channel ordering follows vips convention:
|
||||
- sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
||||
- CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
||||
|
||||
Buffers may be any of the image formats supported by sharp.
|
||||
For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| images | <code>Array.<(string\|Buffer)></code> \| <code>string</code> \| <code>Buffer</code> | one or more images (file paths, Buffers). |
|
||||
| options | <code>Object</code> | image options, see `sharp()` constructor. |
|
||||
|
||||
|
||||
|
||||
## bandbool
|
||||
> bandbool(boolOp) ⇒ <code>Sharp</code>
|
||||
|
||||
Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| boolOp | <code>string</code> | one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp('3-channel-rgb-input.png')
|
||||
.bandbool(sharp.bool.and)
|
||||
.toFile('1-channel-output.png', function (err, info) {
|
||||
// The output will be a single channel image where each pixel `P = R & G & B`.
|
||||
// If `I(1,1) = [247, 170, 14] = [0b11110111, 0b10101010, 0b00001111]`
|
||||
// then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
|
||||
});
|
||||
```
|
||||
147
docs/api-colour.md
Normal file
147
docs/api-colour.md
Normal file
@@ -0,0 +1,147 @@
|
||||
## tint
|
||||
> tint(tint) ⇒ <code>Sharp</code>
|
||||
|
||||
Tint the image using the provided colour.
|
||||
An alpha channel may be present and will be unchanged by the operation.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameter
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| tint | <code>string</code> \| <code>Object</code> | Parsed by the [color](https://www.npmjs.org/package/color) module. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.tint({ r: 255, g: 240, b: 16 })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## greyscale
|
||||
> greyscale([greyscale]) ⇒ <code>Sharp</code>
|
||||
|
||||
Convert to 8-bit greyscale; 256 shades of grey.
|
||||
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||
By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
||||
This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
||||
which will produce an output image containing one color channel.
|
||||
An alpha channel may be present, and will be unchanged by the operation.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| [greyscale] | <code>Boolean</code> | <code>true</code> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input).greyscale().toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## grayscale
|
||||
> grayscale([grayscale]) ⇒ <code>Sharp</code>
|
||||
|
||||
Alternative spelling of `greyscale`.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| [grayscale] | <code>Boolean</code> | <code>true</code> |
|
||||
|
||||
|
||||
|
||||
## pipelineColourspace
|
||||
> pipelineColourspace([colourspace]) ⇒ <code>Sharp</code>
|
||||
|
||||
Set the pipeline colourspace.
|
||||
|
||||
The input image will be converted to the provided colourspace at the start of the pipeline.
|
||||
All operations will use this colourspace before converting to the output colourspace,
|
||||
as defined by [toColourspace](#tocolourspace).
|
||||
|
||||
This feature is experimental and has not yet been fully-tested with all operations.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.29.0
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [colourspace] | <code>string</code> | pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774) |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
|
||||
await sharp(input)
|
||||
.pipelineColourspace('rgb16')
|
||||
.toColourspace('srgb')
|
||||
.toFile('16bpc-pipeline-to-8bpc-output.png')
|
||||
```
|
||||
|
||||
|
||||
## pipelineColorspace
|
||||
> pipelineColorspace([colorspace]) ⇒ <code>Sharp</code>
|
||||
|
||||
Alternative spelling of `pipelineColourspace`.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [colorspace] | <code>string</code> | pipeline colorspace. |
|
||||
|
||||
|
||||
|
||||
## toColourspace
|
||||
> toColourspace([colourspace]) ⇒ <code>Sharp</code>
|
||||
|
||||
Set the output colourspace.
|
||||
By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [colourspace] | <code>string</code> | output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794) |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Output 16 bits per pixel RGB
|
||||
await sharp(input)
|
||||
.toColourspace('rgb16')
|
||||
.toFile('16-bpp.png')
|
||||
```
|
||||
|
||||
|
||||
## toColorspace
|
||||
> toColorspace([colorspace]) ⇒ <code>Sharp</code>
|
||||
|
||||
Alternative spelling of `toColourspace`.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [colorspace] | <code>string</code> | output colorspace. |
|
||||
97
docs/api-composite.md
Normal file
97
docs/api-composite.md
Normal file
@@ -0,0 +1,97 @@
|
||||
## composite
|
||||
> composite(images) ⇒ <code>Sharp</code>
|
||||
|
||||
Composite image(s) over the processed (resized, extracted etc.) image.
|
||||
|
||||
The images to composite must be the same size or smaller than the processed image.
|
||||
If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||
|
||||
Any resize, rotate or extract operations in the same processing pipeline
|
||||
will always be applied to the input image before composition.
|
||||
|
||||
The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||
`dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||
`xor`, `add`, `saturate`, `multiply`, `screen`, `overlay`, `darken`, `lighten`,
|
||||
`colour-dodge`, `color-dodge`, `colour-burn`,`color-burn`,
|
||||
`hard-light`, `soft-light`, `difference`, `exclusion`.
|
||||
|
||||
More information about blend modes can be found at
|
||||
https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode
|
||||
and https://www.cairographics.org/operators/
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.22.0
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| images | <code>Array.<Object></code> | | Ordered list of images to composite |
|
||||
| [images[].input] | <code>Buffer</code> \| <code>String</code> | | Buffer containing image data, String containing the path to an image file, or Create object (see below) |
|
||||
| [images[].input.create] | <code>Object</code> | | describes a blank overlay to be created. |
|
||||
| [images[].input.create.width] | <code>Number</code> | | |
|
||||
| [images[].input.create.height] | <code>Number</code> | | |
|
||||
| [images[].input.create.channels] | <code>Number</code> | | 3-4 |
|
||||
| [images[].input.create.background] | <code>String</code> \| <code>Object</code> | | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||
| [images[].input.text] | <code>Object</code> | | describes a new text image to be created. |
|
||||
| [images[].input.text.text] | <code>string</code> | | text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. |
|
||||
| [images[].input.text.font] | <code>string</code> | | font name to render with. |
|
||||
| [images[].input.text.fontfile] | <code>string</code> | | absolute filesystem path to a font file that can be used by `font`. |
|
||||
| [images[].input.text.width] | <code>number</code> | <code>0</code> | integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. |
|
||||
| [images[].input.text.height] | <code>number</code> | <code>0</code> | integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. |
|
||||
| [images[].input.text.align] | <code>string</code> | <code>"'left'"</code> | text alignment (`'left'`, `'centre'`, `'center'`, `'right'`). |
|
||||
| [images[].input.text.justify] | <code>boolean</code> | <code>false</code> | set this to true to apply justification to the text. |
|
||||
| [images[].input.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
||||
| [images[].input.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`. |
|
||||
| [images[].input.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
||||
| [images[].blend] | <code>String</code> | <code>'over'</code> | how to blend this image with the image below. |
|
||||
| [images[].gravity] | <code>String</code> | <code>'centre'</code> | gravity at which to place the overlay. |
|
||||
| [images[].top] | <code>Number</code> | | the pixel offset from the top edge. |
|
||||
| [images[].left] | <code>Number</code> | | the pixel offset from the left edge. |
|
||||
| [images[].tile] | <code>Boolean</code> | <code>false</code> | set to true to repeat the overlay image across the entire image with the given `gravity`. |
|
||||
| [images[].premultiplied] | <code>Boolean</code> | <code>false</code> | set to true to avoid premultiplying the image below. Equivalent to the `--premultiplied` vips option. |
|
||||
| [images[].density] | <code>Number</code> | <code>72</code> | number representing the DPI for vector overlay image. |
|
||||
| [images[].raw] | <code>Object</code> | | describes overlay when using raw pixel data. |
|
||||
| [images[].raw.width] | <code>Number</code> | | |
|
||||
| [images[].raw.height] | <code>Number</code> | | |
|
||||
| [images[].raw.channels] | <code>Number</code> | | |
|
||||
| [images[].animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image. |
|
||||
| [images[].failOn] | <code>string</code> | <code>"'warning'"</code> | @see [constructor parameters](/api-constructor#parameters) |
|
||||
| [images[].limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | @see [constructor parameters](/api-constructor#parameters) |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
await sharp(background)
|
||||
.composite([
|
||||
{ input: layer1, gravity: 'northwest' },
|
||||
{ input: layer2, gravity: 'southeast' },
|
||||
])
|
||||
.toFile('combined.png');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp('input.gif', { animated: true })
|
||||
.composite([
|
||||
{ input: 'overlay.png', tile: true, blend: 'saturate' }
|
||||
])
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp('input.png')
|
||||
.rotate(180)
|
||||
.resize(300)
|
||||
.flatten( { background: '#ff6600' } )
|
||||
.composite([{ input: 'overlay.png', gravity: 'southeast' }])
|
||||
.sharpen()
|
||||
.withMetadata()
|
||||
.webp( { quality: 90 } )
|
||||
.toBuffer()
|
||||
.then(function(outputBuffer) {
|
||||
// outputBuffer contains upside down, 300px wide, alpha channel flattened
|
||||
// onto orange background, composited with overlay.png with SE gravity,
|
||||
// sharpened, with metadata, 90% quality WebP image data. Phew!
|
||||
});
|
||||
```
|
||||
232
docs/api-constructor.md
Normal file
232
docs/api-constructor.md
Normal file
@@ -0,0 +1,232 @@
|
||||
## Sharp
|
||||
> Sharp
|
||||
|
||||
|
||||
**Emits**: <code>Sharp#event:info</code>, <code>Sharp#event:warning</code>
|
||||
<a name="new_Sharp_new"></a>
|
||||
|
||||
### new
|
||||
> new Sharp([input], [options])
|
||||
|
||||
Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
||||
|
||||
JPEG, PNG, WebP, GIF, AVIF or TIFF format image data can be streamed out from this object.
|
||||
When using Stream based output, derived attributes are available from the `info` event.
|
||||
|
||||
Non-critical problems encountered during processing are emitted as `warning` events.
|
||||
|
||||
Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||
|
||||
When loading more than one page/frame of an animated image,
|
||||
these are combined as a vertically-stacked "toilet roll" image
|
||||
where the overall height is the `pageHeight` multiplied by the number of `pages`.
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [input] | <code>Buffer</code> \| <code>ArrayBuffer</code> \| <code>Uint8Array</code> \| <code>Uint8ClampedArray</code> \| <code>Int8Array</code> \| <code>Uint16Array</code> \| <code>Int16Array</code> \| <code>Uint32Array</code> \| <code>Int32Array</code> \| <code>Float32Array</code> \| <code>Float64Array</code> \| <code>string</code> | | if present, can be a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or a TypedArray containing raw pixel image data, or a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file. JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present. |
|
||||
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||
| [options.failOn] | <code>string</code> | <code>"'warning'"</code> | When to abort processing of invalid pixel data, one of (in order of sensitivity, least to most): 'none', 'truncated', 'error', 'warning'. Higher levels imply lower levels. Invalid metadata will always abort. |
|
||||
| [options.limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). |
|
||||
| [options.unlimited] | <code>boolean</code> | <code>false</code> | Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). |
|
||||
| [options.sequentialRead] | <code>boolean</code> | <code>true</code> | Set this to `false` to use random access rather than sequential read. Some operations will do this automatically. |
|
||||
| [options.density] | <code>number</code> | <code>72</code> | number representing the DPI for vector images in the range 1 to 100000. |
|
||||
| [options.ignoreIcc] | <code>number</code> | <code>false</code> | should the embedded ICC profile, if any, be ignored. |
|
||||
| [options.pages] | <code>number</code> | <code>1</code> | Number of pages to extract for multi-page input (GIF, WebP, TIFF), use -1 for all pages. |
|
||||
| [options.page] | <code>number</code> | <code>0</code> | Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based. |
|
||||
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
|
||||
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
|
||||
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`. |
|
||||
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
|
||||
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
|
||||
| [options.raw.height] | <code>number</code> | | integral number of pixels high. |
|
||||
| [options.raw.channels] | <code>number</code> | | integral number of channels, between 1 and 4. |
|
||||
| [options.raw.premultiplied] | <code>boolean</code> | | specifies that the raw input has already been premultiplied, set to `true` to avoid sharp premultiplying the image. (optional, default `false`) |
|
||||
| [options.create] | <code>Object</code> | | describes a new image to be created. |
|
||||
| [options.create.width] | <code>number</code> | | integral number of pixels wide. |
|
||||
| [options.create.height] | <code>number</code> | | integral number of pixels high. |
|
||||
| [options.create.channels] | <code>number</code> | | integral number of channels, either 3 (RGB) or 4 (RGBA). |
|
||||
| [options.create.background] | <code>string</code> \| <code>Object</code> | | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||
| [options.create.noise] | <code>Object</code> | | describes a noise to be created. |
|
||||
| [options.create.noise.type] | <code>string</code> | | type of generated noise, currently only `gaussian` is supported. |
|
||||
| [options.create.noise.mean] | <code>number</code> | | mean of pixels in generated noise. |
|
||||
| [options.create.noise.sigma] | <code>number</code> | | standard deviation of pixels in generated noise. |
|
||||
| [options.text] | <code>Object</code> | | describes a new text image to be created. |
|
||||
| [options.text.text] | <code>string</code> | | text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. |
|
||||
| [options.text.font] | <code>string</code> | | font name to render with. |
|
||||
| [options.text.fontfile] | <code>string</code> | | absolute filesystem path to a font file that can be used by `font`. |
|
||||
| [options.text.width] | <code>number</code> | <code>0</code> | Integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. |
|
||||
| [options.text.height] | <code>number</code> | <code>0</code> | Maximum integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. |
|
||||
| [options.text.align] | <code>string</code> | <code>"'left'"</code> | Alignment style for multi-line text (`'left'`, `'centre'`, `'center'`, `'right'`). |
|
||||
| [options.text.justify] | <code>boolean</code> | <code>false</code> | set this to true to apply justification to the text. |
|
||||
| [options.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
||||
| [options.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. |
|
||||
| [options.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
||||
| [options.text.wrap] | <code>string</code> | <code>"'word'"</code> | word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp('input.jpg')
|
||||
.resize(300, 200)
|
||||
.toFile('output.jpg', function(err) {
|
||||
// output.jpg is a 300 pixels wide and 200 pixels high image
|
||||
// containing a scaled and cropped version of input.jpg
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Read image data from readableStream,
|
||||
// resize to 300 pixels wide,
|
||||
// emit an 'info' event with calculated dimensions
|
||||
// and finally write image data to writableStream
|
||||
var transformer = sharp()
|
||||
.resize(300)
|
||||
.on('info', function(info) {
|
||||
console.log('Image height is ' + info.height);
|
||||
});
|
||||
readableStream.pipe(transformer).pipe(writableStream);
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Create a blank 300x200 PNG image of semi-translucent red pixels
|
||||
sharp({
|
||||
create: {
|
||||
width: 300,
|
||||
height: 200,
|
||||
channels: 4,
|
||||
background: { r: 255, g: 0, b: 0, alpha: 0.5 }
|
||||
}
|
||||
})
|
||||
.png()
|
||||
.toBuffer()
|
||||
.then( ... );
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Convert an animated GIF to an animated WebP
|
||||
await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Read a raw array of pixels and save it to a png
|
||||
const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
|
||||
const image = sharp(input, {
|
||||
// because the input does not contain its dimensions or how many channels it has
|
||||
// we need to specify it in the constructor options
|
||||
raw: {
|
||||
width: 2,
|
||||
height: 1,
|
||||
channels: 3
|
||||
}
|
||||
});
|
||||
await image.toFile('my-two-pixels.png');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Generate RGB Gaussian noise
|
||||
await sharp({
|
||||
create: {
|
||||
width: 300,
|
||||
height: 200,
|
||||
channels: 3,
|
||||
noise: {
|
||||
type: 'gaussian',
|
||||
mean: 128,
|
||||
sigma: 30
|
||||
}
|
||||
}
|
||||
}).toFile('noise.png');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Generate an image from text
|
||||
await sharp({
|
||||
text: {
|
||||
text: 'Hello, world!',
|
||||
width: 400, // max width
|
||||
height: 300 // max height
|
||||
}
|
||||
}).toFile('text_bw.png');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Generate an rgba image from text using pango markup and font
|
||||
await sharp({
|
||||
text: {
|
||||
text: '<span foreground="red">Red!</span><span background="cyan">blue</span>',
|
||||
font: 'sans',
|
||||
rgba: true,
|
||||
dpi: 300
|
||||
}
|
||||
}).toFile('text_rgba.png');
|
||||
```
|
||||
|
||||
|
||||
## clone
|
||||
> clone() ⇒ [<code>Sharp</code>](#Sharp)
|
||||
|
||||
Take a "snapshot" of the Sharp instance, returning a new instance.
|
||||
Cloned instances inherit the input of their parent instance.
|
||||
This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
|
||||
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const pipeline = sharp().rotate();
|
||||
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
|
||||
pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
|
||||
readableStream.pipe(pipeline);
|
||||
// firstWritableStream receives auto-rotated, resized readableStream
|
||||
// secondWritableStream receives auto-rotated, extracted region of readableStream
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Create a pipeline that will download an image, resize it and format it to different files
|
||||
// Using Promises to know when the pipeline is complete
|
||||
const fs = require("fs");
|
||||
const got = require("got");
|
||||
const sharpStream = sharp({ failOn: 'none' });
|
||||
|
||||
const promises = [];
|
||||
|
||||
promises.push(
|
||||
sharpStream
|
||||
.clone()
|
||||
.jpeg({ quality: 100 })
|
||||
.toFile("originalFile.jpg")
|
||||
);
|
||||
|
||||
promises.push(
|
||||
sharpStream
|
||||
.clone()
|
||||
.resize({ width: 500 })
|
||||
.jpeg({ quality: 80 })
|
||||
.toFile("optimized-500.jpg")
|
||||
);
|
||||
|
||||
promises.push(
|
||||
sharpStream
|
||||
.clone()
|
||||
.resize({ width: 500 })
|
||||
.webp({ quality: 80 })
|
||||
.toFile("optimized-500.webp")
|
||||
);
|
||||
|
||||
// https://github.com/sindresorhus/got/blob/main/documentation/3-streams.md
|
||||
got.stream("https://www.example.com/some-file.jpg").pipe(sharpStream);
|
||||
|
||||
Promise.all(promises)
|
||||
.then(res => { console.log("Done!", res); })
|
||||
.catch(err => {
|
||||
console.error("Error processing files, let's clean it up", err);
|
||||
try {
|
||||
fs.unlinkSync("originalFile.jpg");
|
||||
fs.unlinkSync("optimized-500.jpg");
|
||||
fs.unlinkSync("optimized-500.webp");
|
||||
} catch (e) {}
|
||||
});
|
||||
```
|
||||
137
docs/api-input.md
Normal file
137
docs/api-input.md
Normal file
@@ -0,0 +1,137 @@
|
||||
## metadata
|
||||
> metadata([callback]) ⇒ <code>Promise.<Object></code> \| <code>Sharp</code>
|
||||
|
||||
Fast access to (uncached) image metadata without decoding any compressed pixel data.
|
||||
|
||||
This is read from the header of the input image.
|
||||
It does not take into consideration any operations to be applied to the output image,
|
||||
such as resize or rotate.
|
||||
|
||||
Dimensions in the response will respect the `page` and `pages` properties of the
|
||||
[constructor parameters](/api-constructor#parameters).
|
||||
|
||||
A `Promise` is returned when `callback` is not provided.
|
||||
|
||||
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||
- `size`: Total size of image in bytes, for Stream and Buffer input only
|
||||
- `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
|
||||
- `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
|
||||
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/VipsImage.html#VipsInterpretation)
|
||||
- `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||
- `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/VipsImage.html#VipsBandFormat)
|
||||
- `density`: Number of pixels per inch (DPI), if present
|
||||
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||
- `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
||||
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||
- `pagePrimary`: Number of the primary page in a HEIF image
|
||||
- `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||
- `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||
- `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||
- `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
||||
- `orientation`: Number value of the EXIF Orientation header, if present
|
||||
- `exif`: Buffer containing raw EXIF data, if present
|
||||
- `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
||||
- `iptc`: Buffer containing raw IPTC data, if present
|
||||
- `xmp`: Buffer containing raw XMP data, if present
|
||||
- `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||
- `formatMagick`: String containing format for images loaded via *magick
|
||||
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [callback] | <code>function</code> | called with the arguments `(err, metadata)` |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const metadata = await sharp(input).metadata();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const image = sharp(inputJpg);
|
||||
image
|
||||
.metadata()
|
||||
.then(function(metadata) {
|
||||
return image
|
||||
.resize(Math.round(metadata.width / 2))
|
||||
.webp()
|
||||
.toBuffer();
|
||||
})
|
||||
.then(function(data) {
|
||||
// data contains a WebP image half the width and height of the original JPEG
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Based on EXIF rotation metadata, get the right-side-up width and height:
|
||||
|
||||
const size = getNormalSize(await sharp(input).metadata());
|
||||
|
||||
function getNormalSize({ width, height, orientation }) {
|
||||
return (orientation || 0) >= 5
|
||||
? { width: height, height: width }
|
||||
: { width, height };
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## stats
|
||||
> stats([callback]) ⇒ <code>Promise.<Object></code>
|
||||
|
||||
Access to pixel-derived image statistics for every channel in the image.
|
||||
A `Promise` is returned when `callback` is not provided.
|
||||
|
||||
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||
- `min` (minimum value in the channel)
|
||||
- `max` (maximum value in the channel)
|
||||
- `sum` (sum of all values in a channel)
|
||||
- `squaresSum` (sum of squared values in a channel)
|
||||
- `mean` (mean of the values in a channel)
|
||||
- `stdev` (standard deviation for the values in a channel)
|
||||
- `minX` (x-coordinate of one of the pixel where the minimum lies)
|
||||
- `minY` (y-coordinate of one of the pixel where the minimum lies)
|
||||
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||
- `isOpaque`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
|
||||
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any.
|
||||
- `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any.
|
||||
- `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram.
|
||||
|
||||
**Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
||||
written to a buffer in order to run `stats` on the result (see third example).
|
||||
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [callback] | <code>function</code> | called with the arguments `(err, stats)` |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const image = sharp(inputJpg);
|
||||
image
|
||||
.stats()
|
||||
.then(function(stats) {
|
||||
// stats contains the channel-wise statistics array and the isOpaque value
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const { entropy, sharpness, dominant } = await sharp(input).stats();
|
||||
const { r, g, b } = dominant;
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const image = sharp(input);
|
||||
// store intermediate result
|
||||
const part = await image.extract(region).toBuffer();
|
||||
// create new instance to obtain statistics of extracted region
|
||||
const stats = await sharp(part).stats();
|
||||
```
|
||||
656
docs/api-operation.md
Normal file
656
docs/api-operation.md
Normal file
@@ -0,0 +1,656 @@
|
||||
## rotate
|
||||
> rotate([angle], [options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Rotate the output image by either an explicit angle
|
||||
or auto-orient based on the EXIF `Orientation` tag.
|
||||
|
||||
If an angle is provided, it is converted to a valid positive degree rotation.
|
||||
For example, `-450` will produce a 270 degree rotation.
|
||||
|
||||
When rotating by an angle other than a multiple of 90,
|
||||
the background colour can be provided with the `background` option.
|
||||
|
||||
If no angle is provided, it is determined from the EXIF data.
|
||||
Mirroring is supported and may infer the use of a flip operation.
|
||||
|
||||
The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
||||
|
||||
Only one rotation can occur per pipeline.
|
||||
Previous calls to `rotate` in the same pipeline will be ignored.
|
||||
|
||||
Multi-page images can only be rotated by 180 degrees.
|
||||
|
||||
Method order is important when rotating, resizing and/or extracting regions,
|
||||
for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [angle] | <code>number</code> | <code>auto</code> | angle of rotation. |
|
||||
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"\"#000000\""</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const pipeline = sharp()
|
||||
.rotate()
|
||||
.resize(null, 200)
|
||||
.toBuffer(function (err, outputBuffer, info) {
|
||||
// outputBuffer contains 200px high JPEG image data,
|
||||
// auto-rotated using EXIF Orientation tag
|
||||
// info.width and info.height contain the dimensions of the resized image
|
||||
});
|
||||
readableStream.pipe(pipeline);
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const rotateThenResize = await sharp(input)
|
||||
.rotate(90)
|
||||
.resize({ width: 16, height: 8, fit: 'fill' })
|
||||
.toBuffer();
|
||||
const resizeThenRotate = await sharp(input)
|
||||
.resize({ width: 16, height: 8, fit: 'fill' })
|
||||
.rotate(90)
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## flip
|
||||
> flip([flip]) ⇒ <code>Sharp</code>
|
||||
|
||||
Mirror the image vertically (up-down) about the x-axis.
|
||||
This always occurs before rotation, if any.
|
||||
|
||||
This operation does not work correctly with multi-page images.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| [flip] | <code>Boolean</code> | <code>true</code> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input).flip().toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## flop
|
||||
> flop([flop]) ⇒ <code>Sharp</code>
|
||||
|
||||
Mirror the image horizontally (left-right) about the y-axis.
|
||||
This always occurs before rotation, if any.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| [flop] | <code>Boolean</code> | <code>true</code> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input).flop().toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## affine
|
||||
> affine(matrix, [options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||
|
||||
You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||
By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||
|
||||
In the case of a 2x2 matrix, the transform is:
|
||||
- X = `matrix[0, 0]` \* (x + `idx`) + `matrix[0, 1]` \* (y + `idy`) + `odx`
|
||||
- Y = `matrix[1, 0]` \* (x + `idx`) + `matrix[1, 1]` \* (y + `idy`) + `ody`
|
||||
|
||||
where:
|
||||
- x and y are the coordinates in input image.
|
||||
- X and Y are the coordinates in output image.
|
||||
- (0,0) is the upper left corner.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.27.0
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| matrix | <code>Array.<Array.<number>></code> \| <code>Array.<number></code> | | affine transformation matrix |
|
||||
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||
| [options.background] | <code>String</code> \| <code>Object</code> | <code>"#000000"</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||
| [options.idx] | <code>Number</code> | <code>0</code> | input horizontal offset |
|
||||
| [options.idy] | <code>Number</code> | <code>0</code> | input vertical offset |
|
||||
| [options.odx] | <code>Number</code> | <code>0</code> | output horizontal offset |
|
||||
| [options.ody] | <code>Number</code> | <code>0</code> | output vertical offset |
|
||||
| [options.interpolator] | <code>String</code> | <code>sharp.interpolators.bicubic</code> | interpolator |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const pipeline = sharp()
|
||||
.affine([[1, 0.3], [0.1, 0.7]], {
|
||||
background: 'white',
|
||||
interpolator: sharp.interpolators.nohalo
|
||||
})
|
||||
.toBuffer((err, outputBuffer, info) => {
|
||||
// outputBuffer contains the transformed image
|
||||
// info.width and info.height contain the new dimensions
|
||||
});
|
||||
|
||||
inputStream
|
||||
.pipe(pipeline);
|
||||
```
|
||||
|
||||
|
||||
## sharpen
|
||||
> sharpen([options], [flat], [jagged]) ⇒ <code>Sharp</code>
|
||||
|
||||
Sharpen the image.
|
||||
|
||||
When used without parameters, performs a fast, mild sharpen of the output image.
|
||||
|
||||
When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
||||
Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
|
||||
|
||||
See [libvips sharpen](https://www.libvips.org/API/current/libvips-convolution.html#vips-sharpen) operation.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> \| <code>number</code> | | if present, is an Object with attributes |
|
||||
| [options.sigma] | <code>number</code> | | the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`, between 0.000001 and 10 |
|
||||
| [options.m1] | <code>number</code> | <code>1.0</code> | the level of sharpening to apply to "flat" areas, between 0 and 1000000 |
|
||||
| [options.m2] | <code>number</code> | <code>2.0</code> | the level of sharpening to apply to "jagged" areas, between 0 and 1000000 |
|
||||
| [options.x1] | <code>number</code> | <code>2.0</code> | threshold between "flat" and "jagged", between 0 and 1000000 |
|
||||
| [options.y2] | <code>number</code> | <code>10.0</code> | maximum amount of brightening, between 0 and 1000000 |
|
||||
| [options.y3] | <code>number</code> | <code>20.0</code> | maximum amount of darkening, between 0 and 1000000 |
|
||||
| [flat] | <code>number</code> | | (deprecated) see `options.m1`. |
|
||||
| [jagged] | <code>number</code> | | (deprecated) see `options.m2`. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const data = await sharp(input).sharpen().toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const data = await sharp(input).sharpen({ sigma: 2 }).toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const data = await sharp(input)
|
||||
.sharpen({
|
||||
sigma: 2,
|
||||
m1: 0,
|
||||
m2: 3,
|
||||
x1: 3,
|
||||
y2: 15,
|
||||
y3: 15,
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## median
|
||||
> median([size]) ⇒ <code>Sharp</code>
|
||||
|
||||
Apply median filter.
|
||||
When used without parameters the default window is 3x3.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [size] | <code>number</code> | <code>3</code> | square mask size: size x size |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input).median().toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input).median(5).toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## blur
|
||||
> blur([sigma]) ⇒ <code>Sharp</code>
|
||||
|
||||
Blur the image.
|
||||
|
||||
When used without parameters, performs a fast 3x3 box blur (equivalent to a box linear filter).
|
||||
|
||||
When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [sigma] | <code>number</code> | a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const boxBlurred = await sharp(input)
|
||||
.blur()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const gaussianBlurred = await sharp(input)
|
||||
.blur(5)
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## flatten
|
||||
> flatten([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
||||
|
||||
See also [removeAlpha](/api-channel#removealpha).
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"{r: 0, g: 0, b: 0}"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
await sharp(rgbaInput)
|
||||
.flatten({ background: '#F0A703' })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## unflatten
|
||||
> unflatten()
|
||||
|
||||
Ensure the image has an alpha channel
|
||||
with all white pixel values made fully transparent.
|
||||
|
||||
Existing alpha channel values for non-white pixels remain unchanged.
|
||||
|
||||
This feature is experimental and the API may change.
|
||||
|
||||
|
||||
**Since**: 0.32.1
|
||||
**Example**
|
||||
```js
|
||||
await sharp(rgbInput)
|
||||
.unflatten()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
await sharp(rgbInput)
|
||||
.threshold(128, { grayscale: false }) // converter bright pixels to white
|
||||
.unflatten()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## gamma
|
||||
> gamma([gamma], [gammaOut]) ⇒ <code>Sharp</code>
|
||||
|
||||
Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma`
|
||||
then increasing the encoding (brighten) post-resize at a factor of `gamma`.
|
||||
This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
||||
when applying a gamma correction.
|
||||
|
||||
Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [gamma] | <code>number</code> | <code>2.2</code> | value between 1.0 and 3.0. |
|
||||
| [gammaOut] | <code>number</code> | | value between 1.0 and 3.0. (optional, defaults to same as `gamma`) |
|
||||
|
||||
|
||||
|
||||
## negate
|
||||
> negate([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Produce the "negative" of the image.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.alpha] | <code>Boolean</code> | <code>true</code> | Whether or not to negate any alpha channel |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.negate()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.negate({ alpha: false })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## normalise
|
||||
> normalise([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Enhance output image contrast by stretching its luminance to cover a full dynamic range.
|
||||
|
||||
Uses a histogram-based approach, taking a default range of 1% to 99% to reduce sensitivity to noise at the extremes.
|
||||
|
||||
Luminance values below the `lower` percentile will be underexposed by clipping to zero.
|
||||
Luminance values above the `upper` percentile will be overexposed by clipping to the max pixel value.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.lower] | <code>number</code> | <code>1</code> | Percentile below which luminance values will be underexposed. |
|
||||
| [options.upper] | <code>number</code> | <code>99</code> | Percentile above which luminance values will be overexposed. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.normalise()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.normalise({ lower: 0, upper: 100 })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## normalize
|
||||
> normalize([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Alternative spelling of normalise.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.lower] | <code>number</code> | <code>1</code> | Percentile below which luminance values will be underexposed. |
|
||||
| [options.upper] | <code>number</code> | <code>99</code> | Percentile above which luminance values will be overexposed. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.normalize()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## clahe
|
||||
> clahe(options) ⇒ <code>Sharp</code>
|
||||
|
||||
Perform contrast limiting adaptive histogram equalization
|
||||
[CLAHE](https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE).
|
||||
|
||||
This will, in general, enhance the clarity of the image by bringing out darker details.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.28.3
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| options | <code>Object</code> | | |
|
||||
| options.width | <code>number</code> | | Integral width of the search window, in pixels. |
|
||||
| options.height | <code>number</code> | | Integral height of the search window, in pixels. |
|
||||
| [options.maxSlope] | <code>number</code> | <code>3</code> | Integral level of brightening, between 0 and 100, where 0 disables contrast limiting. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const output = await sharp(input)
|
||||
.clahe({
|
||||
width: 3,
|
||||
height: 3,
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## convolve
|
||||
> convolve(kernel) ⇒ <code>Sharp</code>
|
||||
|
||||
Convolve the image with the specified kernel.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| kernel | <code>Object</code> | | |
|
||||
| kernel.width | <code>number</code> | | width of the kernel in pixels. |
|
||||
| kernel.height | <code>number</code> | | height of the kernel in pixels. |
|
||||
| kernel.kernel | <code>Array.<number></code> | | Array of length `width*height` containing the kernel values. |
|
||||
| [kernel.scale] | <code>number</code> | <code>sum</code> | the scale of the kernel in pixels. |
|
||||
| [kernel.offset] | <code>number</code> | <code>0</code> | the offset of the kernel in pixels. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.convolve({
|
||||
width: 3,
|
||||
height: 3,
|
||||
kernel: [-1, 0, 1, -2, 0, 2, -1, 0, 1]
|
||||
})
|
||||
.raw()
|
||||
.toBuffer(function(err, data, info) {
|
||||
// data contains the raw pixel data representing the convolution
|
||||
// of the input image with the horizontal Sobel operator
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## threshold
|
||||
> threshold([threshold], [options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [threshold] | <code>number</code> | <code>128</code> | a value in the range 0-255 representing the level at which the threshold will be applied. |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.greyscale] | <code>Boolean</code> | <code>true</code> | convert to single channel greyscale. |
|
||||
| [options.grayscale] | <code>Boolean</code> | <code>true</code> | alternative spelling for greyscale. |
|
||||
|
||||
|
||||
|
||||
## boolean
|
||||
> boolean(operand, operator, [options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Perform a bitwise boolean operation with operand image.
|
||||
|
||||
This operation creates an output image where each pixel is the result of
|
||||
the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| operand | <code>Buffer</code> \| <code>string</code> | Buffer containing image data or string containing the path to an image file. |
|
||||
| operator | <code>string</code> | one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively. |
|
||||
| [options] | <code>Object</code> | |
|
||||
| [options.raw] | <code>Object</code> | describes operand when using raw pixel data. |
|
||||
| [options.raw.width] | <code>number</code> | |
|
||||
| [options.raw.height] | <code>number</code> | |
|
||||
| [options.raw.channels] | <code>number</code> | |
|
||||
|
||||
|
||||
|
||||
## linear
|
||||
> linear([a], [b]) ⇒ <code>Sharp</code>
|
||||
|
||||
Apply the linear formula `a` * input + `b` to the image to adjust image levels.
|
||||
|
||||
When a single number is provided, it will be used for all image channels.
|
||||
When an array of numbers is provided, the array length must match the number of channels.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [a] | <code>number</code> \| <code>Array.<number></code> | <code>[]</code> | multiplier |
|
||||
| [b] | <code>number</code> \| <code>Array.<number></code> | <code>[]</code> | offset |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
await sharp(input)
|
||||
.linear(0.5, 2)
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
await sharp(rgbInput)
|
||||
.linear(
|
||||
[0.25, 0.5, 0.75],
|
||||
[150, 100, 50]
|
||||
)
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## recomb
|
||||
> recomb(inputMatrix) ⇒ <code>Sharp</code>
|
||||
|
||||
Recombine the image with the specified matrix.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.21.1
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| inputMatrix | <code>Array.<Array.<number>></code> | 3x3 Recombination matrix |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.recomb([
|
||||
[0.3588, 0.7044, 0.1368],
|
||||
[0.2990, 0.5870, 0.1140],
|
||||
[0.2392, 0.4696, 0.0912],
|
||||
])
|
||||
.raw()
|
||||
.toBuffer(function(err, data, info) {
|
||||
// data contains the raw pixel data after applying the matrix
|
||||
// With this example input, a sepia filter has been applied
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## modulate
|
||||
> modulate([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Transforms the image using brightness, saturation, hue rotation, and lightness.
|
||||
Brightness and lightness both operate on luminance, with the difference being that
|
||||
brightness is multiplicative whereas lightness is additive.
|
||||
|
||||
|
||||
**Since**: 0.22.1
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | |
|
||||
| [options.brightness] | <code>number</code> | Brightness multiplier |
|
||||
| [options.saturation] | <code>number</code> | Saturation multiplier |
|
||||
| [options.hue] | <code>number</code> | Degrees for hue rotation |
|
||||
| [options.lightness] | <code>number</code> | Lightness addend |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// increase brightness by a factor of 2
|
||||
const output = await sharp(input)
|
||||
.modulate({
|
||||
brightness: 2
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// hue-rotate by 180 degrees
|
||||
const output = await sharp(input)
|
||||
.modulate({
|
||||
hue: 180
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// increase lightness by +50
|
||||
const output = await sharp(input)
|
||||
.modulate({
|
||||
lightness: 50
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// decrease brightness and saturation while also hue-rotating by 90 degrees
|
||||
const output = await sharp(input)
|
||||
.modulate({
|
||||
brightness: 0.5,
|
||||
saturation: 0.5,
|
||||
hue: 90,
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
829
docs/api-output.md
Normal file
829
docs/api-output.md
Normal file
@@ -0,0 +1,829 @@
|
||||
## toFile
|
||||
> toFile(fileOut, [callback]) ⇒ <code>Promise.<Object></code>
|
||||
|
||||
Write output image data to a file.
|
||||
|
||||
If an explicit output format is not selected, it will be inferred from the extension,
|
||||
with JPEG, PNG, WebP, AVIF, TIFF, GIF, DZI, and libvips' V format supported.
|
||||
Note that raw pixel data is only supported for buffer output.
|
||||
|
||||
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||
See [withMetadata](#withmetadata) for control over this.
|
||||
|
||||
The caller is responsible for ensuring directory structures and permissions exist.
|
||||
|
||||
A `Promise` is returned when `callback` is not provided.
|
||||
|
||||
|
||||
**Returns**: <code>Promise.<Object></code> - - when no callback is provided
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| fileOut | <code>string</code> | the path to write the image data to. |
|
||||
| [callback] | <code>function</code> | called on completion with two arguments `(err, info)`. `info` contains the output image `format`, `size` (bytes), `width`, `height`, `channels` and `premultiplied` (indicating if premultiplication was used). When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`. When using the attention crop strategy also contains `attentionX` and `attentionY`, the focal point of the cropped region. May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.toFile('output.png', (err, info) => { ... });
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.toFile('output.png')
|
||||
.then(info => { ... })
|
||||
.catch(err => { ... });
|
||||
```
|
||||
|
||||
|
||||
## toBuffer
|
||||
> toBuffer([options], [callback]) ⇒ <code>Promise.<Buffer></code>
|
||||
|
||||
Write output to a Buffer.
|
||||
JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.
|
||||
|
||||
Use [toFormat](#toformat) or one of the format-specific functions such as [jpeg](#jpeg), [png](#png) etc. to set the output format.
|
||||
|
||||
If no explicit format is set, the output format will match the input image, except SVG input which becomes PNG output.
|
||||
|
||||
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||
See [withMetadata](#withmetadata) for control over this.
|
||||
|
||||
`callback`, if present, gets three arguments `(err, data, info)` where:
|
||||
- `err` is an error, if any.
|
||||
- `data` is the output image data.
|
||||
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||
May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
||||
|
||||
A `Promise` is returned when `callback` is not provided.
|
||||
|
||||
|
||||
**Returns**: <code>Promise.<Buffer></code> - - when no callback is provided
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | |
|
||||
| [options.resolveWithObject] | <code>boolean</code> | Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`. |
|
||||
| [callback] | <code>function</code> | |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.toBuffer((err, data, info) => { ... });
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.toBuffer()
|
||||
.then(data => { ... })
|
||||
.catch(err => { ... });
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.png()
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(({ data, info }) => { ... })
|
||||
.catch(err => { ... });
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const { data, info } = await sharp('my-image.jpg')
|
||||
// output the raw pixels
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
|
||||
// create a more type safe way to work with the raw pixel data
|
||||
// this will not copy the data, instead it will change `data`s underlying ArrayBuffer
|
||||
// so `data` and `pixelArray` point to the same memory location
|
||||
const pixelArray = new Uint8ClampedArray(data.buffer);
|
||||
|
||||
// When you are done changing the pixelArray, sharp takes the `pixelArray` as an input
|
||||
const { width, height, channels } = info;
|
||||
await sharp(pixelArray, { raw: { width, height, channels } })
|
||||
.toFile('my-changed-image.jpg');
|
||||
```
|
||||
|
||||
|
||||
## keepExif
|
||||
> keepExif() ⇒ <code>Sharp</code>
|
||||
|
||||
Keep all EXIF metadata from the input image in the output image.
|
||||
|
||||
EXIF metadata is unsupported for TIFF output.
|
||||
|
||||
|
||||
**Since**: 0.33.0
|
||||
**Example**
|
||||
```js
|
||||
const outputWithExif = await sharp(inputWithExif)
|
||||
.keepExif()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## withExif
|
||||
> withExif(exif) ⇒ <code>Sharp</code>
|
||||
|
||||
Set EXIF metadata in the output image, ignoring any EXIF in the input image.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.33.0
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| exif | <code>Object.<string, Object.<string, string>></code> | Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const dataWithExif = await sharp(input)
|
||||
.withExif({
|
||||
IFD0: {
|
||||
Copyright: 'The National Gallery'
|
||||
},
|
||||
IFD3: {
|
||||
GPSLatitudeRef: 'N',
|
||||
GPSLatitude: '51/1 30/1 3230/100',
|
||||
GPSLongitudeRef: 'W',
|
||||
GPSLongitude: '0/1 7/1 4366/100'
|
||||
}
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## withExifMerge
|
||||
> withExifMerge(exif) ⇒ <code>Sharp</code>
|
||||
|
||||
Update EXIF metadata from the input image in the output image.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.33.0
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| exif | <code>Object.<string, Object.<string, string>></code> | Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const dataWithMergedExif = await sharp(inputWithExif)
|
||||
.withExifMerge({
|
||||
IFD0: {
|
||||
Copyright: 'The National Gallery'
|
||||
}
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## keepIccProfile
|
||||
> keepIccProfile() ⇒ <code>Sharp</code>
|
||||
|
||||
Keep ICC profile from the input image in the output image.
|
||||
|
||||
Where necessary, will attempt to convert the output colour space to match the profile.
|
||||
|
||||
|
||||
**Since**: 0.33.0
|
||||
**Example**
|
||||
```js
|
||||
const outputWithIccProfile = await sharp(inputWithIccProfile)
|
||||
.keepIccProfile()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## withIccProfile
|
||||
> withIccProfile(icc, [options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Transform using an ICC profile and attach to the output image.
|
||||
|
||||
This can either be an absolute filesystem path or
|
||||
built-in profile name (`srgb`, `p3`, `cmyk`).
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
**Since**: 0.33.0
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| icc | <code>string</code> | | Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk). |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.attach] | <code>number</code> | <code>true</code> | Should the ICC profile be included in the output image metadata? |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const outputWithP3 = await sharp(input)
|
||||
.withIccProfile('p3')
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## keepMetadata
|
||||
> keepMetadata() ⇒ <code>Sharp</code>
|
||||
|
||||
Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
|
||||
|
||||
The default behaviour, when `keepMetadata` is not used, is to convert to the device-independent
|
||||
sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
||||
|
||||
|
||||
**Since**: 0.33.0
|
||||
**Example**
|
||||
```js
|
||||
const outputWithMetadata = await sharp(inputWithMetadata)
|
||||
.keepMetadata()
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## withMetadata
|
||||
> withMetadata([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Keep most metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
||||
|
||||
This will also convert to and add a web-friendly sRGB ICC profile if appropriate.
|
||||
|
||||
Allows orientation and density to be set or updated.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | |
|
||||
| [options.orientation] | <code>number</code> | Used to update the EXIF `Orientation` tag, integer between 1 and 8. |
|
||||
| [options.density] | <code>number</code> | Number of pixels per inch (DPI). |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const outputSrgbWithMetadata = await sharp(inputRgbWithMetadata)
|
||||
.withMetadata()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Set output metadata to 96 DPI
|
||||
const data = await sharp(input)
|
||||
.withMetadata({ density: 96 })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## toFormat
|
||||
> toFormat(format, options) ⇒ <code>Sharp</code>
|
||||
|
||||
Force output to a given format.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> unsupported format or options
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| format | <code>string</code> \| <code>Object</code> | as a string or an Object with an 'id' attribute |
|
||||
| options | <code>Object</code> | output options |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to PNG output
|
||||
const data = await sharp(input)
|
||||
.toFormat('png')
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## jpeg
|
||||
> jpeg([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these JPEG options for output image.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||
| [options.progressive] | <code>boolean</code> | <code>false</code> | use progressive (interlace) scan |
|
||||
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:2:0'"</code> | set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling |
|
||||
| [options.optimiseCoding] | <code>boolean</code> | <code>true</code> | optimise Huffman coding tables |
|
||||
| [options.optimizeCoding] | <code>boolean</code> | <code>true</code> | alternative spelling of optimiseCoding |
|
||||
| [options.mozjpeg] | <code>boolean</code> | <code>false</code> | use mozjpeg defaults, equivalent to `{ trellisQuantisation: true, overshootDeringing: true, optimiseScans: true, quantisationTable: 3 }` |
|
||||
| [options.trellisQuantisation] | <code>boolean</code> | <code>false</code> | apply trellis quantisation |
|
||||
| [options.overshootDeringing] | <code>boolean</code> | <code>false</code> | apply overshoot deringing |
|
||||
| [options.optimiseScans] | <code>boolean</code> | <code>false</code> | optimise progressive scans, forces progressive |
|
||||
| [options.optimizeScans] | <code>boolean</code> | <code>false</code> | alternative spelling of optimiseScans |
|
||||
| [options.quantisationTable] | <code>number</code> | <code>0</code> | quantization table to use, integer 0-8 |
|
||||
| [options.quantizationTable] | <code>number</code> | <code>0</code> | alternative spelling of quantisationTable |
|
||||
| [options.force] | <code>boolean</code> | <code>true</code> | force JPEG output, otherwise attempt to use input format |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to very high quality JPEG output
|
||||
const data = await sharp(input)
|
||||
.jpeg({
|
||||
quality: 100,
|
||||
chromaSubsampling: '4:4:4'
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Use mozjpeg to reduce output JPEG file size (slower)
|
||||
const data = await sharp(input)
|
||||
.jpeg({ mozjpeg: true })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## png
|
||||
> png([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these PNG options for output image.
|
||||
|
||||
By default, PNG output is full colour at 8 or 16 bits per pixel.
|
||||
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||
Set `palette` to `true` for slower, indexed PNG output.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.progressive] | <code>boolean</code> | <code>false</code> | use progressive (interlace) scan |
|
||||
| [options.compressionLevel] | <code>number</code> | <code>6</code> | zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest) |
|
||||
| [options.adaptiveFiltering] | <code>boolean</code> | <code>false</code> | use adaptive row filtering |
|
||||
| [options.palette] | <code>boolean</code> | <code>false</code> | quantise to a palette-based image with alpha transparency support |
|
||||
| [options.quality] | <code>number</code> | <code>100</code> | use the lowest number of colours needed to achieve given quality, sets `palette` to `true` |
|
||||
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 10 (slowest), sets `palette` to `true` |
|
||||
| [options.colours] | <code>number</code> | <code>256</code> | maximum number of palette entries, sets `palette` to `true` |
|
||||
| [options.colors] | <code>number</code> | <code>256</code> | alternative spelling of `options.colours`, sets `palette` to `true` |
|
||||
| [options.dither] | <code>number</code> | <code>1.0</code> | level of Floyd-Steinberg error diffusion, sets `palette` to `true` |
|
||||
| [options.force] | <code>boolean</code> | <code>true</code> | force PNG output, otherwise attempt to use input format |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to full colour PNG output
|
||||
const data = await sharp(input)
|
||||
.png()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to indexed PNG output (slower)
|
||||
const data = await sharp(input)
|
||||
.png({ palette: true })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## webp
|
||||
> webp([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these WebP options for output image.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||
| [options.alphaQuality] | <code>number</code> | <code>100</code> | quality of alpha layer, integer 0-100 |
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression mode |
|
||||
| [options.nearLossless] | <code>boolean</code> | <code>false</code> | use near_lossless compression mode |
|
||||
| [options.smartSubsample] | <code>boolean</code> | <code>false</code> | use high quality chroma subsampling |
|
||||
| [options.preset] | <code>string</code> | <code>"'default'"</code> | named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text |
|
||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 6 (slowest) |
|
||||
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||
| [options.delay] | <code>number</code> \| <code>Array.<number></code> | | delay(s) between animation frames (in milliseconds) |
|
||||
| [options.minSize] | <code>boolean</code> | <code>false</code> | prevent use of animation key frames to minimise file size (slow) |
|
||||
| [options.mixed] | <code>boolean</code> | <code>false</code> | allow mixture of lossy and lossless animation frames (slow) |
|
||||
| [options.force] | <code>boolean</code> | <code>true</code> | force WebP output, otherwise attempt to use input format |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to lossless WebP output
|
||||
const data = await sharp(input)
|
||||
.webp({ lossless: true })
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Optimise the file size of an animated WebP
|
||||
const outputWebp = await sharp(inputWebp, { animated: true })
|
||||
.webp({ effort: 6 })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## gif
|
||||
> gif([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these GIF options for the output image.
|
||||
|
||||
The first entry in the palette is reserved for transparency.
|
||||
|
||||
The palette of the input image will be re-used if possible.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
**Since**: 0.30.0
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.reuse] | <code>boolean</code> | <code>true</code> | re-use existing palette, otherwise generate new (slow) |
|
||||
| [options.progressive] | <code>boolean</code> | <code>false</code> | use progressive (interlace) scan |
|
||||
| [options.colours] | <code>number</code> | <code>256</code> | maximum number of palette entries, including transparency, between 2 and 256 |
|
||||
| [options.colors] | <code>number</code> | <code>256</code> | alternative spelling of `options.colours` |
|
||||
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 10 (slowest) |
|
||||
| [options.dither] | <code>number</code> | <code>1.0</code> | level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most) |
|
||||
| [options.interFrameMaxError] | <code>number</code> | <code>0</code> | maximum inter-frame error for transparency, between 0 (lossless) and 32 |
|
||||
| [options.interPaletteMaxError] | <code>number</code> | <code>3</code> | maximum inter-palette error for palette reuse, between 0 and 256 |
|
||||
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||
| [options.delay] | <code>number</code> \| <code>Array.<number></code> | | delay(s) between animation frames (in milliseconds) |
|
||||
| [options.force] | <code>boolean</code> | <code>true</code> | force GIF output, otherwise attempt to use input format |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert PNG to GIF
|
||||
await sharp(pngBuffer)
|
||||
.gif()
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Convert animated WebP to animated GIF
|
||||
await sharp('animated.webp', { animated: true })
|
||||
.toFile('animated.gif');
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Create a 128x128, cropped, non-dithered, animated thumbnail of an animated GIF
|
||||
const out = await sharp('in.gif', { animated: true })
|
||||
.resize({ width: 128, height: 128 })
|
||||
.gif({ dither: 0 })
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Lossy file size reduction of animated GIF
|
||||
await sharp('in.gif', { animated: true })
|
||||
.gif({ interFrameMaxError: 8 })
|
||||
.toFile('optim.gif');
|
||||
```
|
||||
|
||||
|
||||
## jp2
|
||||
> jp2([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these JP2 options for output image.
|
||||
|
||||
Requires libvips compiled with support for OpenJPEG.
|
||||
The prebuilt binaries do not include this - see
|
||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
**Since**: 0.29.1
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression mode |
|
||||
| [options.tileWidth] | <code>number</code> | <code>512</code> | horizontal tile size |
|
||||
| [options.tileHeight] | <code>number</code> | <code>512</code> | vertical tile size |
|
||||
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to lossless JP2 output
|
||||
const data = await sharp(input)
|
||||
.jp2({ lossless: true })
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Convert any input to very high quality JP2 output
|
||||
const data = await sharp(input)
|
||||
.jp2({
|
||||
quality: 100,
|
||||
chromaSubsampling: '4:4:4'
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## tiff
|
||||
> tiff([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these TIFF options for output image.
|
||||
|
||||
The `density` can be set in pixels/inch via [withMetadata](#withmetadata)
|
||||
instead of providing `xres` and `yres` in pixels/mm.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||
| [options.force] | <code>boolean</code> | <code>true</code> | force TIFF output, otherwise attempt to use input format |
|
||||
| [options.compression] | <code>string</code> | <code>"'jpeg'"</code> | compression options: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k |
|
||||
| [options.predictor] | <code>string</code> | <code>"'horizontal'"</code> | compression predictor options: none, horizontal, float |
|
||||
| [options.pyramid] | <code>boolean</code> | <code>false</code> | write an image pyramid |
|
||||
| [options.tile] | <code>boolean</code> | <code>false</code> | write a tiled tiff |
|
||||
| [options.tileWidth] | <code>number</code> | <code>256</code> | horizontal tile size |
|
||||
| [options.tileHeight] | <code>number</code> | <code>256</code> | vertical tile size |
|
||||
| [options.xres] | <code>number</code> | <code>1.0</code> | horizontal resolution in pixels/mm |
|
||||
| [options.yres] | <code>number</code> | <code>1.0</code> | vertical resolution in pixels/mm |
|
||||
| [options.resolutionUnit] | <code>string</code> | <code>"'inch'"</code> | resolution unit options: inch, cm |
|
||||
| [options.bitdepth] | <code>number</code> | <code>8</code> | reduce bitdepth to 1, 2 or 4 bit |
|
||||
| [options.miniswhite] | <code>boolean</code> | <code>false</code> | write 1-bit images as miniswhite |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||
sharp('input.svg')
|
||||
.tiff({
|
||||
compression: 'lzw',
|
||||
bitdepth: 1
|
||||
})
|
||||
.toFile('1-bpp-output.tiff')
|
||||
.then(info => { ... });
|
||||
```
|
||||
|
||||
|
||||
## avif
|
||||
> avif([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these AVIF options for output image.
|
||||
|
||||
AVIF image sequences are not supported.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
**Since**: 0.27.0
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.quality] | <code>number</code> | <code>50</code> | quality, integer 1-100 |
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
||||
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const data = await sharp(input)
|
||||
.avif({ effort: 2 })
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const data = await sharp(input)
|
||||
.avif({ lossless: true })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## heif
|
||||
> heif(options) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these HEIF options for output image.
|
||||
|
||||
Support for patent-encumbered HEIC images using `hevc` compression requires the use of a
|
||||
globally-installed libvips compiled with support for libheif, libde265 and x265.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
**Since**: 0.23.0
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| options | <code>Object</code> | | output options |
|
||||
| options.compression | <code>string</code> | | compression format: av1, hevc |
|
||||
| [options.quality] | <code>number</code> | <code>50</code> | quality, integer 1-100 |
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
||||
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const data = await sharp(input)
|
||||
.heif({ compression: 'hevc' })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## jxl
|
||||
> jxl([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use these JPEG-XL (JXL) options for output image.
|
||||
|
||||
This feature is experimental, please do not use in production systems.
|
||||
|
||||
Requires libvips compiled with support for libjxl.
|
||||
The prebuilt binaries do not include this - see
|
||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||
|
||||
Image metadata (EXIF, XMP) is unsupported.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
**Since**: 0.31.3
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.distance] | <code>number</code> | <code>1.0</code> | maximum encoding error, between 0 (highest quality) and 15 (lowest quality) |
|
||||
| [options.quality] | <code>number</code> | | calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified |
|
||||
| [options.decodingTier] | <code>number</code> | <code>0</code> | target decode speed tier, between 0 (highest quality) and 4 (lowest quality) |
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 3 (fastest) and 9 (slowest) |
|
||||
|
||||
|
||||
|
||||
## raw
|
||||
> raw([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Force output to be raw, uncompressed pixel data.
|
||||
Pixel ordering is left-to-right, top-to-bottom, without padding.
|
||||
Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid options
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | output options |
|
||||
| [options.depth] | <code>string</code> | <code>"'uchar'"</code> | bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
||||
const { data, info } = await sharp('input.jpg')
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
||||
const data = await sharp('input.png')
|
||||
.ensureAlpha()
|
||||
.extractChannel(3)
|
||||
.toColourspace('b-w')
|
||||
.raw({ depth: 'ushort' })
|
||||
.toBuffer();
|
||||
```
|
||||
|
||||
|
||||
## tile
|
||||
> tile([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Use tile-based deep zoom (image pyramid) output.
|
||||
|
||||
Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
||||
Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
||||
|
||||
The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
||||
|
||||
Requires libvips compiled with support for libgsf.
|
||||
The prebuilt binaries do not include this - see
|
||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.size] | <code>number</code> | <code>256</code> | tile size in pixels, a value between 1 and 8192. |
|
||||
| [options.overlap] | <code>number</code> | <code>0</code> | tile overlap in pixels, a value between 0 and 8192. |
|
||||
| [options.angle] | <code>number</code> | <code>0</code> | tile angle of rotation, must be a multiple of 90. |
|
||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"{r: 255, g: 255, b: 255, alpha: 1}"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency. |
|
||||
| [options.depth] | <code>string</code> | | how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout. |
|
||||
| [options.skipBlanks] | <code>number</code> | <code>-1</code> | threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images |
|
||||
| [options.container] | <code>string</code> | <code>"'fs'"</code> | tile container, with value `fs` (filesystem) or `zip` (compressed file). |
|
||||
| [options.layout] | <code>string</code> | <code>"'dz'"</code> | filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`. |
|
||||
| [options.centre] | <code>boolean</code> | <code>false</code> | centre image in tile. |
|
||||
| [options.center] | <code>boolean</code> | <code>false</code> | alternative spelling of centre. |
|
||||
| [options.id] | <code>string</code> | <code>"'https://example.com/iiif'"</code> | when `layout` is `iiif`/`iiif3`, sets the `@id`/`id` attribute of `info.json` |
|
||||
| [options.basename] | <code>string</code> | | the name of the directory within the zip file when container is `zip`. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp('input.tiff')
|
||||
.png()
|
||||
.tile({
|
||||
size: 512
|
||||
})
|
||||
.toFile('output.dz', function(err, info) {
|
||||
// output.dzi is the Deep Zoom XML definition
|
||||
// output_files contains 512x512 tiles grouped by zoom level
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const zipFileWithTiles = await sharp(input)
|
||||
.tile({ basename: "tiles" })
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const iiififier = sharp().tile({ layout: "iiif" });
|
||||
readableStream
|
||||
.pipe(iiififier)
|
||||
.pipe(writeableStream);
|
||||
```
|
||||
|
||||
|
||||
## timeout
|
||||
> timeout(options) ⇒ <code>Sharp</code>
|
||||
|
||||
Set a timeout for processing, in seconds.
|
||||
Use a value of zero to continue processing indefinitely, the default behaviour.
|
||||
|
||||
The clock starts when libvips opens an input image for processing.
|
||||
Time spent waiting for a libuv thread to become available is not included.
|
||||
|
||||
|
||||
**Since**: 0.29.2
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | <code>Object</code> | |
|
||||
| options.seconds | <code>number</code> | Number of seconds after which processing will be stopped |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Ensure processing takes no longer than 3 seconds
|
||||
try {
|
||||
const data = await sharp(input)
|
||||
.blur(1000)
|
||||
.timeout({ seconds: 3 })
|
||||
.toBuffer();
|
||||
} catch (err) {
|
||||
if (err.message.includes('timeout')) { ... }
|
||||
}
|
||||
```
|
||||
312
docs/api-resize.md
Normal file
312
docs/api-resize.md
Normal file
@@ -0,0 +1,312 @@
|
||||
## resize
|
||||
> resize([width], [height], [options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Resize image to `width`, `height` or `width x height`.
|
||||
|
||||
When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
||||
- `cover`: (default) Preserving aspect ratio, attempt to ensure the image covers both provided dimensions by cropping/clipping to fit.
|
||||
- `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
||||
- `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
||||
- `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
||||
- `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
||||
|
||||
Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
|
||||
|
||||
<img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.svg">
|
||||
|
||||
When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
||||
- `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
||||
- `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
|
||||
- `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
|
||||
|
||||
Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
||||
|
||||
The experimental strategy-based approach resizes so one dimension is at its target length
|
||||
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
||||
- `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
||||
- `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
||||
|
||||
Possible interpolation kernels are:
|
||||
- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||
- `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||
- `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
||||
- `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||
|
||||
Only one resize can occur per pipeline.
|
||||
Previous calls to `resize` in the same pipeline will be ignored.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [width] | <code>number</code> | | How many pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height. |
|
||||
| [height] | <code>number</code> | | How many pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width. |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.width] | <code>number</code> | | An alternative means of specifying `width`. If both are present this takes priority. |
|
||||
| [options.height] | <code>number</code> | | An alternative means of specifying `height`. If both are present this takes priority. |
|
||||
| [options.fit] | <code>String</code> | <code>'cover'</code> | How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`. |
|
||||
| [options.position] | <code>String</code> | <code>'centre'</code> | A position, gravity or strategy to use when `fit` is `cover` or `contain`. |
|
||||
| [options.background] | <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
|
||||
| [options.kernel] | <code>String</code> | <code>'lanczos3'</code> | The kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load. |
|
||||
| [options.withoutEnlargement] | <code>Boolean</code> | <code>false</code> | Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions. |
|
||||
| [options.withoutReduction] | <code>Boolean</code> | <code>false</code> | Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions. |
|
||||
| [options.fastShrinkOnLoad] | <code>Boolean</code> | <code>true</code> | Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.resize({ width: 100 })
|
||||
.toBuffer()
|
||||
.then(data => {
|
||||
// 100 pixels wide, auto-scaled height
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.resize({ height: 100 })
|
||||
.toBuffer()
|
||||
.then(data => {
|
||||
// 100 pixels high, auto-scaled width
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.resize(200, 300, {
|
||||
kernel: sharp.kernel.nearest,
|
||||
fit: 'contain',
|
||||
position: 'right top',
|
||||
background: { r: 255, g: 255, b: 255, alpha: 0.5 }
|
||||
})
|
||||
.toFile('output.png')
|
||||
.then(() => {
|
||||
// output.png is a 200 pixels wide and 300 pixels high image
|
||||
// containing a nearest-neighbour scaled version
|
||||
// contained within the north-east corner of a semi-transparent white canvas
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const transformer = sharp()
|
||||
.resize({
|
||||
width: 200,
|
||||
height: 200,
|
||||
fit: sharp.fit.cover,
|
||||
position: sharp.strategy.entropy
|
||||
});
|
||||
// Read image data from readableStream
|
||||
// Write 200px square auto-cropped image data to writableStream
|
||||
readableStream
|
||||
.pipe(transformer)
|
||||
.pipe(writableStream);
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.inside,
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.toFormat('jpeg')
|
||||
.toBuffer()
|
||||
.then(function(outputBuffer) {
|
||||
// outputBuffer contains JPEG image data
|
||||
// no wider and no higher than 200 pixels
|
||||
// and no larger than the input image
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.resize(200, 200, {
|
||||
fit: sharp.fit.outside,
|
||||
withoutReduction: true
|
||||
})
|
||||
.toFormat('jpeg')
|
||||
.toBuffer()
|
||||
.then(function(outputBuffer) {
|
||||
// outputBuffer contains JPEG image data
|
||||
// of at least 200 pixels wide and 200 pixels high while maintaining aspect ratio
|
||||
// and no smaller than the input image
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const scaleByHalf = await sharp(input)
|
||||
.metadata()
|
||||
.then(({ width }) => sharp(input)
|
||||
.resize(Math.round(width * 0.5))
|
||||
.toBuffer()
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
## extend
|
||||
> extend(extend) ⇒ <code>Sharp</code>
|
||||
|
||||
Extend / pad / extrude one or more edges of the image with either
|
||||
the provided background colour or pixels derived from the image.
|
||||
This operation will always occur after resizing and extraction, if any.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| extend | <code>number</code> \| <code>Object</code> | | single pixel count to add to all edges or an Object with per-edge counts |
|
||||
| [extend.top] | <code>number</code> | <code>0</code> | |
|
||||
| [extend.left] | <code>number</code> | <code>0</code> | |
|
||||
| [extend.bottom] | <code>number</code> | <code>0</code> | |
|
||||
| [extend.right] | <code>number</code> | <code>0</code> | |
|
||||
| [extend.extendWith] | <code>String</code> | <code>'background'</code> | populate new pixels using this method, one of: background, copy, repeat, mirror. |
|
||||
| [extend.background] | <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Resize to 140 pixels wide, then add 10 transparent pixels
|
||||
// to the top, left and right edges and 20 to the bottom edge
|
||||
sharp(input)
|
||||
.resize(140)
|
||||
.extend({
|
||||
top: 10,
|
||||
bottom: 20,
|
||||
left: 10,
|
||||
right: 10,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
...
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Add a row of 10 red pixels to the bottom
|
||||
sharp(input)
|
||||
.extend({
|
||||
bottom: 10,
|
||||
background: 'red'
|
||||
})
|
||||
...
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Extrude image by 8 pixels to the right, mirroring existing right hand edge
|
||||
sharp(input)
|
||||
.extend({
|
||||
right: 8,
|
||||
background: 'mirror'
|
||||
})
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
## extract
|
||||
> extract(options) ⇒ <code>Sharp</code>
|
||||
|
||||
Extract/crop a region of the image.
|
||||
|
||||
- Use `extract` before `resize` for pre-resize extraction.
|
||||
- Use `extract` after `resize` for post-resize extraction.
|
||||
- Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | <code>Object</code> | describes the region to extract using integral pixel values |
|
||||
| options.left | <code>number</code> | zero-indexed offset from left edge |
|
||||
| options.top | <code>number</code> | zero-indexed offset from top edge |
|
||||
| options.width | <code>number</code> | width of region to extract |
|
||||
| options.height | <code>number</code> | height of region to extract |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.extract({ left: left, top: top, width: width, height: height })
|
||||
.toFile(output, function(err) {
|
||||
// Extract a region of the input image, saving in the same format.
|
||||
});
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp(input)
|
||||
.extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
|
||||
.resize(width, height)
|
||||
.extract({ left: leftOffsetPost, top: topOffsetPost, width: widthPost, height: heightPost })
|
||||
.toFile(output, function(err) {
|
||||
// Extract a region, resize, then extract from the resized image
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## trim
|
||||
> trim([options]) ⇒ <code>Sharp</code>
|
||||
|
||||
Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
||||
|
||||
Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
|
||||
|
||||
If the result of this operation would trim an image to nothing then no change is made.
|
||||
|
||||
The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
- <code>Error</code> Invalid parameters
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> | | |
|
||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"'top-left pixel'"</code> | Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel. |
|
||||
| [options.threshold] | <code>number</code> | <code>10</code> | Allowed difference from the above colour, a positive number. |
|
||||
| [options.lineArt] | <code>boolean</code> | <code>false</code> | Does the input more closely resemble line art (e.g. vector) rather than being photographic? |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Trim pixels with a colour similar to that of the top-left pixel.
|
||||
await sharp(input)
|
||||
.trim()
|
||||
.toFile(output);
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Trim pixels with the exact same colour as that of the top-left pixel.
|
||||
await sharp(input)
|
||||
.trim({
|
||||
threshold: 0
|
||||
})
|
||||
.toFile(output);
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Assume input is line art and trim only pixels with a similar colour to red.
|
||||
const output = await sharp(input)
|
||||
.trim({
|
||||
background: "#FF0000",
|
||||
lineArt: true
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
||||
const output = await sharp(input)
|
||||
.trim({
|
||||
background: "yellow",
|
||||
threshold: 42,
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
233
docs/api-utility.md
Normal file
233
docs/api-utility.md
Normal file
@@ -0,0 +1,233 @@
|
||||
## versions
|
||||
> versions
|
||||
|
||||
An Object containing the version numbers of sharp, libvips
|
||||
and (when using prebuilt binaries) its dependencies.
|
||||
|
||||
|
||||
**Example**
|
||||
```js
|
||||
console.log(sharp.versions);
|
||||
```
|
||||
|
||||
|
||||
## interpolators
|
||||
> interpolators : <code>enum</code>
|
||||
|
||||
An Object containing the available interpolators and their proper values
|
||||
|
||||
|
||||
**Read only**: true
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| nearest | <code>string</code> | <code>"nearest"</code> | [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. |
|
||||
| bilinear | <code>string</code> | <code>"bilinear"</code> | [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. |
|
||||
| bicubic | <code>string</code> | <code>"bicubic"</code> | [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). |
|
||||
| locallyBoundedBicubic | <code>string</code> | <code>"lbb"</code> | [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. |
|
||||
| nohalo | <code>string</code> | <code>"nohalo"</code> | [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. |
|
||||
| vertexSplitQuadraticBasisSpline | <code>string</code> | <code>"vsqbs"</code> | [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. |
|
||||
|
||||
|
||||
|
||||
## format
|
||||
> format ⇒ <code>Object</code>
|
||||
|
||||
An Object containing nested boolean values representing the available input and output formats/methods.
|
||||
|
||||
|
||||
**Example**
|
||||
```js
|
||||
console.log(sharp.format);
|
||||
```
|
||||
|
||||
|
||||
## queue
|
||||
> queue
|
||||
|
||||
An EventEmitter that emits a `change` event when a task is either:
|
||||
- queued, waiting for _libuv_ to provide a worker thread
|
||||
- complete
|
||||
|
||||
|
||||
**Example**
|
||||
```js
|
||||
sharp.queue.on('change', function(queueLength) {
|
||||
console.log('Queue contains ' + queueLength + ' task(s)');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## cache
|
||||
> cache([options]) ⇒ <code>Object</code>
|
||||
|
||||
Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
||||
Existing entries in the cache will be trimmed after any change in limits.
|
||||
This method always returns cache statistics,
|
||||
useful for determining how much working memory is required for a particular task.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [options] | <code>Object</code> \| <code>boolean</code> | <code>true</code> | Object with the following attributes, or boolean where true uses default cache settings and false removes all caching |
|
||||
| [options.memory] | <code>number</code> | <code>50</code> | is the maximum memory in MB to use for this cache |
|
||||
| [options.files] | <code>number</code> | <code>20</code> | is the maximum number of files to hold open |
|
||||
| [options.items] | <code>number</code> | <code>100</code> | is the maximum number of operations to cache |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const stats = sharp.cache();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
sharp.cache( { items: 200 } );
|
||||
sharp.cache( { files: 0 } );
|
||||
sharp.cache(false);
|
||||
```
|
||||
|
||||
|
||||
## concurrency
|
||||
> concurrency([concurrency]) ⇒ <code>number</code>
|
||||
|
||||
Gets or, when a concurrency is provided, sets
|
||||
the maximum number of threads _libvips_ should use to process _each image_.
|
||||
These are from a thread pool managed by glib,
|
||||
which helps avoid the overhead of creating new threads.
|
||||
|
||||
This method always returns the current concurrency.
|
||||
|
||||
The default value is the number of CPU cores,
|
||||
except when using glibc-based Linux without jemalloc,
|
||||
where the default is `1` to help reduce memory fragmentation.
|
||||
|
||||
A value of `0` will reset this to the number of CPU cores.
|
||||
|
||||
Some image format libraries spawn additional threads,
|
||||
e.g. libaom manages its own 4 threads when encoding AVIF images,
|
||||
and these are independent of the value set here.
|
||||
|
||||
The maximum number of images that sharp can process in parallel
|
||||
is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
|
||||
which defaults to 4.
|
||||
|
||||
https://nodejs.org/api/cli.html#uv_threadpool_sizesize
|
||||
|
||||
For example, by default, a machine with 8 CPU cores will process
|
||||
4 images in parallel and use up to 8 threads per image,
|
||||
so there will be up to 32 concurrent threads.
|
||||
|
||||
|
||||
**Returns**: <code>number</code> - concurrency
|
||||
|
||||
| Param | Type |
|
||||
| --- | --- |
|
||||
| [concurrency] | <code>number</code> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const threads = sharp.concurrency(); // 4
|
||||
sharp.concurrency(2); // 2
|
||||
sharp.concurrency(0); // 4
|
||||
```
|
||||
|
||||
|
||||
## counters
|
||||
> counters() ⇒ <code>Object</code>
|
||||
|
||||
Provides access to internal task counters.
|
||||
- queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
|
||||
- process is the number of resize tasks currently being processed.
|
||||
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const counters = sharp.counters(); // { queue: 2, process: 4 }
|
||||
```
|
||||
|
||||
|
||||
## simd
|
||||
> simd([simd]) ⇒ <code>boolean</code>
|
||||
|
||||
Get and set use of SIMD vector unit instructions.
|
||||
Requires libvips to have been compiled with highway support.
|
||||
|
||||
Improves the performance of `resize`, `blur` and `sharpen` operations
|
||||
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||
|
||||
|
||||
|
||||
| Param | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| [simd] | <code>boolean</code> | <code>true</code> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
const simd = sharp.simd();
|
||||
// simd is `true` if the runtime use of highway is currently enabled
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
const simd = sharp.simd(false);
|
||||
// prevent libvips from using highway at runtime
|
||||
```
|
||||
|
||||
|
||||
## block
|
||||
> block(options)
|
||||
|
||||
Block libvips operations at runtime.
|
||||
|
||||
This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
|
||||
which when set will block all "untrusted" operations.
|
||||
|
||||
|
||||
**Since**: 0.32.4
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | <code>Object</code> | |
|
||||
| options.operation | <code>Array.<string></code> | List of libvips low-level operation names to block. |
|
||||
|
||||
**Example** *(Block all TIFF input.)*
|
||||
```js
|
||||
sharp.block({
|
||||
operation: ['VipsForeignLoadTiff']
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## unblock
|
||||
> unblock(options)
|
||||
|
||||
Unblock libvips operations at runtime.
|
||||
|
||||
This is useful for defining a list of allowed operations.
|
||||
|
||||
|
||||
**Since**: 0.32.4
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | <code>Object</code> | |
|
||||
| options.operation | <code>Array.<string></code> | List of libvips low-level operation names to unblock. |
|
||||
|
||||
**Example** *(Block all input except WebP from the filesystem.)*
|
||||
```js
|
||||
sharp.block({
|
||||
operation: ['VipsForeignLoad']
|
||||
});
|
||||
sharp.unblock({
|
||||
operation: ['VipsForeignLoadWebpFile']
|
||||
});
|
||||
```
|
||||
**Example** *(Block all input except JPEG and PNG from a Buffer or Stream.)*
|
||||
```js
|
||||
sharp.block({
|
||||
operation: ['VipsForeignLoad']
|
||||
});
|
||||
sharp.unblock({
|
||||
operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
|
||||
});
|
||||
```
|
||||
724
docs/api.md
724
docs/api.md
@@ -1,724 +0,0 @@
|
||||
# API
|
||||
|
||||
```javascript
|
||||
var sharp = require('sharp');
|
||||
```
|
||||
|
||||
### Input
|
||||
|
||||
#### sharp([input], [options])
|
||||
|
||||
Constructor to which further methods are chained.
|
||||
|
||||
`input`, if present, can be one of:
|
||||
|
||||
* Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
||||
* String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
||||
|
||||
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data
|
||||
can be streamed into the object when `input` is `null` or `undefined`.
|
||||
|
||||
`options`, if present, is an Object with the following optional attributes:
|
||||
|
||||
* `density` an integral number representing the DPI for vector images, defaulting to 72.
|
||||
* `raw` an Object containing `width`, `height` and `channels` when providing uncompressed data. See `raw()` for pixel ordering.
|
||||
|
||||
The object returned by the constructor implements the
|
||||
[stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||
|
||||
JPEG, PNG or WebP format image data can be streamed out from this object.
|
||||
When using Stream based output, derived attributes are available from the `info` event.
|
||||
|
||||
```javascript
|
||||
sharp('input.jpg')
|
||||
.resize(300, 200)
|
||||
.toFile('output.jpg', function(err) {
|
||||
// output.jpg is a 300 pixels wide and 200 pixels high image
|
||||
// containing a scaled and cropped version of input.jpg
|
||||
});
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Read image data from readableStream,
|
||||
// resize to 300 pixels wide,
|
||||
// emit an 'info' event with calculated dimensions
|
||||
// and finally write image data to writableStream
|
||||
var transformer = sharp()
|
||||
.resize(300)
|
||||
.on('info', function(info) {
|
||||
console.log('Image height is ' + info.height);
|
||||
});
|
||||
readableStream.pipe(transformer).pipe(writableStream);
|
||||
```
|
||||
|
||||
#### metadata([callback])
|
||||
|
||||
Fast access to image metadata without decoding any compressed image data.
|
||||
|
||||
`callback`, if present, gets the arguments `(err, metadata)` where `metadata` has the attributes:
|
||||
|
||||
* `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||
* `width`: Number of pixels wide
|
||||
* `height`: Number of pixels high
|
||||
* `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `scrgb`, `cmyk`, `lab`, `xyz`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L522)
|
||||
* `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||
* `density`: Number of pixels per inch (DPI), if present
|
||||
* `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||
* `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
||||
* `orientation`: Number value of the EXIF Orientation header, if present
|
||||
* `exif`: Buffer containing raw EXIF data, if present
|
||||
* `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
||||
|
||||
A Promises/A+ promise is returned when `callback` is not provided.
|
||||
|
||||
```javascript
|
||||
var image = sharp(inputJpg);
|
||||
image
|
||||
.metadata()
|
||||
.then(function(metadata) {
|
||||
return image
|
||||
.resize(Math.round(metadata.width / 2))
|
||||
.webp()
|
||||
.toBuffer();
|
||||
})
|
||||
.then(function(data) {
|
||||
// data contains a WebP image half the width and height of the original JPEG
|
||||
});
|
||||
```
|
||||
|
||||
#### clone()
|
||||
|
||||
Takes a "snapshot" of the instance, returning a new instance.
|
||||
Cloned instances inherit the input of their parent instance.
|
||||
|
||||
This allows multiple output Streams
|
||||
and therefore multiple processing pipelines
|
||||
to share a single input Stream.
|
||||
|
||||
```javascript
|
||||
var pipeline = sharp().rotate();
|
||||
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
|
||||
pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
|
||||
readableStream.pipe(pipeline);
|
||||
// firstWritableStream receives auto-rotated, resized readableStream
|
||||
// secondWritableStream receives auto-rotated, extracted region of readableStream
|
||||
```
|
||||
|
||||
#### sequentialRead()
|
||||
|
||||
An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`.
|
||||
This will reduce memory usage and can improve performance on some systems.
|
||||
|
||||
#### limitInputPixels(pixels)
|
||||
|
||||
Do not process input images where the number of pixels (width * height) exceeds this limit.
|
||||
|
||||
`pixels` is either an integral Number of pixels, with a value between 1 and the default 268402689 (0x3FFF * 0x3FFF) or
|
||||
a boolean. `false` will disable checking while `true` will revert to the default limit.
|
||||
|
||||
### Resizing
|
||||
|
||||
#### resize([width], [height], [options])
|
||||
|
||||
Scale output to `width` x `height`. By default, the resized image is cropped to the exact size specified.
|
||||
|
||||
`width` is the integral Number of pixels wide the resultant image should be, between 1 and 16383 (0x3FFF). Use `null` or `undefined` to auto-scale the width to match the height.
|
||||
|
||||
`height` is the integral Number of pixels high the resultant image should be, between 1 and 16383. Use `null` or `undefined` to auto-scale the height to match the width.
|
||||
|
||||
`options` is an optional Object. If present, it can contain one or more of:
|
||||
|
||||
* `options.kernel`, the kernel to use for image reduction, defaulting to `lanczos3`.
|
||||
* `options.interpolator`, the interpolator to use for image enlargement, defaulting to `bicubic`.
|
||||
|
||||
Possible kernels are:
|
||||
|
||||
* `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||
* `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||
* `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||
|
||||
Possible interpolators are:
|
||||
|
||||
* `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||
* `bilinear`: Use [bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation), faster than bicubic but with less smooth results.
|
||||
* `vertexSplitQuadraticBasisSpline`: Use the smoother [VSQBS interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48) to prevent "staircasing" when enlarging.
|
||||
* `bicubic`: Use [bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default).
|
||||
* `locallyBoundedBicubic`: Use [LBB interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/lbb.cpp#L100), which prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2.
|
||||
* `nohalo`: Use [Nohalo interpolation](http://eprints.soton.ac.uk/268086/), which prevents acutance but typically reduces performance by a factor of 3.
|
||||
|
||||
```javascript
|
||||
sharp(inputBuffer)
|
||||
.resize(200, 300, {
|
||||
kernel: sharp.kernel.lanczos2,
|
||||
interpolator: sharp.interpolator.nohalo
|
||||
})
|
||||
.background('white')
|
||||
.embed()
|
||||
.toFile('output.tiff')
|
||||
.then(function() {
|
||||
// output.tiff is a 200 pixels wide and 300 pixels high image
|
||||
// containing a lanczos2/nohalo scaled version, embedded on a white canvas,
|
||||
// of the image data in inputBuffer
|
||||
});
|
||||
```
|
||||
|
||||
#### crop([option])
|
||||
|
||||
Crop the resized image to the exact size specified, the default behaviour.
|
||||
|
||||
`option`, if present, is an attribute of:
|
||||
|
||||
* `sharp.gravity` e.g. `sharp.gravity.north`, to crop to an edge or corner, or
|
||||
* `sharp.strategy` e.g. `sharp.strategy.entropy`, to crop dynamically.
|
||||
|
||||
Possible attributes of `sharp.gravity` are
|
||||
`north`, `northeast`, `east`, `southeast`, `south`,
|
||||
`southwest`, `west`, `northwest`, `center` and `centre`.
|
||||
|
||||
Possible attributes of the experimental `sharp.strategy` are:
|
||||
|
||||
* `entropy`: resize so one dimension is at its target size
|
||||
then repeatedly remove pixels from the edge with the lowest
|
||||
[Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29)
|
||||
until it too reaches the target size.
|
||||
|
||||
The default crop option is a `center`/`centre` gravity.
|
||||
|
||||
```javascript
|
||||
var transformer = sharp()
|
||||
.resize(200, 200)
|
||||
.crop(sharp.strategy.entropy)
|
||||
.on('error', function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
// Read image data from readableStream
|
||||
// Write 200px square auto-cropped image data to writableStream
|
||||
readableStream.pipe(transformer).pipe(writableStream);
|
||||
```
|
||||
|
||||
#### embed()
|
||||
|
||||
Preserving aspect ratio, resize the image to the
|
||||
maximum `width` or `height` specified
|
||||
then embed on a background of the exact
|
||||
`width` and `height` specified.
|
||||
|
||||
If the background contains an alpha value
|
||||
then WebP and PNG format output images will
|
||||
contain an alpha channel,
|
||||
even when the input image does not.
|
||||
|
||||
```javascript
|
||||
sharp('input.gif')
|
||||
.resize(200, 300)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.embed()
|
||||
.toFormat(sharp.format.webp)
|
||||
.toBuffer(function(err, outputBuffer) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
// outputBuffer contains WebP image data of a 200 pixels wide and 300 pixels high
|
||||
// containing a scaled version, embedded on a transparent canvas, of input.gif
|
||||
});
|
||||
```
|
||||
|
||||
#### max()
|
||||
|
||||
Preserving aspect ratio,
|
||||
resize the image to be as large as possible
|
||||
while ensuring its dimensions are less than or equal to
|
||||
the `width` and `height` specified.
|
||||
|
||||
Both `width` and `height` must be provided via
|
||||
`resize` otherwise the behaviour will default to `crop`.
|
||||
|
||||
```javascript
|
||||
sharp(inputBuffer)
|
||||
.resize(200, 200)
|
||||
.max()
|
||||
.toFormat('jpeg')
|
||||
.toBuffer()
|
||||
.then(function(outputBuffer) {
|
||||
// outputBuffer contains JPEG image data no wider than 200 pixels and no higher
|
||||
// than 200 pixels regardless of the inputBuffer image dimensions
|
||||
});
|
||||
```
|
||||
|
||||
#### min()
|
||||
|
||||
Preserving aspect ratio,
|
||||
resize the image to be as small as possible
|
||||
while ensuring its dimensions are greater than or equal to
|
||||
the `width` and `height` specified.
|
||||
|
||||
Both `width` and `height` must be provided via `resize` otherwise the behaviour will default to `crop`.
|
||||
|
||||
#### withoutEnlargement()
|
||||
|
||||
Do not enlarge the output image
|
||||
if the input image width *or* height
|
||||
are already less than the required dimensions.
|
||||
|
||||
This is equivalent to GraphicsMagick's `>` geometry option:
|
||||
"*change the dimensions of the image only
|
||||
if its width or height exceeds the geometry specification*".
|
||||
|
||||
#### ignoreAspectRatio()
|
||||
|
||||
Ignoring the aspect ratio of the input, stretch the image to the exact `width` and/or `height` provided via `resize`.
|
||||
|
||||
### Operations
|
||||
|
||||
#### extract({ left: left, top: top, width: width, height: height })
|
||||
|
||||
Extract a region of the image. Can be used with or without a `resize` operation.
|
||||
|
||||
`left` and `top` are the offset, in pixels, from the top-left corner.
|
||||
|
||||
`width` and `height` are the dimensions of the extracted image.
|
||||
|
||||
Use `extract` before `resize` for pre-resize extraction. Use `extract` after `resize` for post-resize extraction. Use `extract` before and after for both.
|
||||
|
||||
```javascript
|
||||
sharp(input)
|
||||
.extract({ left: left, top: top, width: width, height: height })
|
||||
.toFile(output, function(err) {
|
||||
// Extract a region of the input image, saving in the same format.
|
||||
});
|
||||
```
|
||||
|
||||
```javascript
|
||||
sharp(input)
|
||||
.extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
|
||||
.resize(width, height)
|
||||
.extract({ left: leftOffsetPost, top: topOffsetPost, width: widthPost, height: heightPost })
|
||||
.toFile(output, function(err) {
|
||||
// Extract a region, resize, then extract from the resized image
|
||||
});
|
||||
```
|
||||
|
||||
#### background(rgba)
|
||||
|
||||
Set the background for the `embed`, `flatten` and `extend` operations.
|
||||
|
||||
`rgba` is parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||
|
||||
The alpha value is a float between `0` (transparent) and `1` (opaque).
|
||||
|
||||
The default background is `{r: 0, g: 0, b: 0, a: 1}`, black without transparency.
|
||||
|
||||
#### flatten()
|
||||
|
||||
Merge alpha transparency channel, if any, with `background`.
|
||||
|
||||
#### extend(extension)
|
||||
|
||||
Extends/pads the edges of the image with `background`, where `extension` is one of:
|
||||
|
||||
* a Number representing the pixel count to add to each edge, or
|
||||
* an Object containing `top`, `left`, `bottom` and `right` attributes, each a Number of pixels to add to that edge.
|
||||
|
||||
This operation will always occur after resizing and extraction, if any.
|
||||
|
||||
```javascript
|
||||
// Resize to 140 pixels wide, then add 10 transparent pixels
|
||||
// to the top, left and right edges and 20 to the bottom edge
|
||||
sharp(input)
|
||||
.resize(140)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.extend({top: 10, bottom: 20, left: 10, right: 10})
|
||||
...
|
||||
```
|
||||
|
||||
#### negate()
|
||||
|
||||
Produces the "negative" of the image. White => Black, Black => White, Blue => Yellow, etc.
|
||||
|
||||
#### rotate([angle])
|
||||
|
||||
Rotate the output image by either an explicit angle or auto-orient based on the EXIF `Orientation` tag.
|
||||
|
||||
`angle`, if present, is a Number with a value of `0`, `90`, `180` or `270`.
|
||||
|
||||
Use this method without `angle` to determine the angle from EXIF data. Mirroring is supported and may infer the use of a `flip` operation.
|
||||
|
||||
Method order is important when both rotating and extracting regions, for example `rotate(x).extract(y)` will produce a different result to `extract(y).rotate(x)`.
|
||||
|
||||
The use of `rotate` implies the removal of the EXIF `Orientation` tag, if any.
|
||||
|
||||
```javascript
|
||||
var pipeline = sharp()
|
||||
.rotate()
|
||||
.resize(null, 200)
|
||||
.progressive()
|
||||
.toBuffer(function(err, outputBuffer, info) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
// outputBuffer contains 200px high progressive JPEG image data,
|
||||
// auto-rotated using EXIF Orientation tag
|
||||
// info.width and info.height contain the dimensions of the resized image
|
||||
});
|
||||
readableStream.pipe(pipeline);
|
||||
```
|
||||
|
||||
#### flip()
|
||||
|
||||
Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
||||
The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
||||
|
||||
#### flop()
|
||||
|
||||
Flop the image about the horizontal X axis. This always occurs after rotation, if any.
|
||||
The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
||||
|
||||
#### blur([sigma])
|
||||
|
||||
When used without parameters, performs a fast, mild blur of the output image. This typically reduces performance by 10%.
|
||||
|
||||
When a `sigma` is provided, performs a slower, more accurate Gaussian blur. This typically reduces performance by 25%.
|
||||
|
||||
* `sigma`, if present, is a Number between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||
|
||||
#### sharpen([sigma], [flat], [jagged])
|
||||
|
||||
When used without parameters, performs a fast, mild sharpen of the output image. This typically reduces performance by 10%.
|
||||
|
||||
When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space. Separate control over the level of sharpening in "flat" and "jagged" areas is available. This typically reduces performance by 50%.
|
||||
|
||||
* `sigma`, if present, is a Number representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||
* `flat`, if present, is a Number representing the level of sharpening to apply to "flat" areas, defaulting to a value of 1.0.
|
||||
* `jagged`, if present, is a Number representing the level of sharpening to apply to "jagged" areas, defaulting to a value of 2.0.
|
||||
|
||||
#### threshold([threshold])
|
||||
|
||||
Converts all pixels in the image to greyscale white or black. Any pixel greather-than-or-equal-to the threshold (0..255) will be white. All others will be black.
|
||||
|
||||
* `threshold`, if present, is a Number, representing the level above which pixels will be forced to white.
|
||||
|
||||
#### gamma([gamma])
|
||||
|
||||
Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma` then increasing the encoding (brighten) post-resize at a factor of `gamma`.
|
||||
|
||||
`gamma`, if present, is a Number between 1 and 3. The default value is `2.2`, a suitable approximation for sRGB images.
|
||||
|
||||
This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||
|
||||
JPEG input images will not take advantage of the shrink-on-load performance optimisation when applying a gamma correction.
|
||||
|
||||
#### grayscale() / greyscale()
|
||||
|
||||
Convert to 8-bit greyscale; 256 shades of grey.
|
||||
|
||||
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||
|
||||
The output image will still be web-friendly sRGB and contain three (identical) channels.
|
||||
|
||||
#### normalize() / normalise()
|
||||
|
||||
Enhance output image contrast by stretching its luminance to cover the full dynamic range. This typically reduces performance by 30%.
|
||||
|
||||
#### overlayWith(image, [options])
|
||||
|
||||
Overlay (composite) a image containing an alpha channel over the processed (resized, extracted etc.) image.
|
||||
|
||||
`image` is one of the following, and must be the same size or smaller than the processed image:
|
||||
|
||||
* Buffer containing PNG, WebP, GIF or SVG image data, or
|
||||
* String containing the path to an image file, with most major transparency formats supported.
|
||||
|
||||
`options`, if present, is an Object with the following optional attributes:
|
||||
|
||||
* `gravity` is a String or an attribute of the `sharp.gravity` Object e.g. `sharp.gravity.north` at which to place the overlay, defaulting to `center`/`centre`.
|
||||
|
||||
```javascript
|
||||
sharp('input.png')
|
||||
.rotate(180)
|
||||
.resize(300)
|
||||
.flatten()
|
||||
.background('#ff6600')
|
||||
.overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
||||
.sharpen()
|
||||
.withMetadata()
|
||||
.quality(90)
|
||||
.webp()
|
||||
.toBuffer()
|
||||
.then(function(outputBuffer) {
|
||||
// outputBuffer contains upside down, 300px wide, alpha channel flattened
|
||||
// onto orange background, composited with overlay.png with SE gravity,
|
||||
// sharpened, with metadata, 90% quality WebP image data. Phew!
|
||||
});
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
#### toFile(path, [callback])
|
||||
|
||||
`path` is a String containing the path to write the image data to.
|
||||
|
||||
If an explicit output format is not selected, it will be inferred from the extension, with JPEG, PNG, WebP, TIFF and DZI supported.
|
||||
|
||||
`callback`, if present, is called with two arguments `(err, info)` where:
|
||||
|
||||
* `err` contains an error message, if any.
|
||||
* `info` contains the output image `format`, `size` (bytes), `width`, `height` and `channels`.
|
||||
|
||||
A Promises/A+ promise is returned when `callback` is not provided.
|
||||
|
||||
#### toBuffer([callback])
|
||||
|
||||
Write image data to a Buffer, the format of which will match the input image by default. JPEG, PNG and WebP are supported.
|
||||
|
||||
`callback`, if present, gets three arguments `(err, buffer, info)` where:
|
||||
|
||||
* `err` is an error message, if any.
|
||||
* `buffer` is the output image data.
|
||||
* `info` contains the output image `format`, `size` (bytes), `width`, `height` and `channels`.
|
||||
|
||||
A Promises/A+ promise is returned when `callback` is not provided.
|
||||
|
||||
#### jpeg()
|
||||
|
||||
Use JPEG format for the output image.
|
||||
|
||||
#### png()
|
||||
|
||||
Use PNG format for the output image.
|
||||
|
||||
#### webp()
|
||||
|
||||
Use WebP format for the output image.
|
||||
|
||||
#### raw()
|
||||
|
||||
Provide raw, uncompressed uint8 (unsigned char) image data for Buffer and Stream based output.
|
||||
|
||||
The number of channels depends on the input image and selected options.
|
||||
|
||||
* 1 channel for images converted to `greyscale()`, with each byte representing one pixel.
|
||||
* 3 channels for colour images without alpha transparency, with bytes ordered \[red, green, blue, red, green, blue, etc.\]).
|
||||
* 4 channels for colour images with alpha transparency, with bytes ordered \[red, green, blue, alpha, red, green, blue, alpha, etc.\].
|
||||
|
||||
#### toFormat(format)
|
||||
|
||||
Convenience method for the above output format methods, where `format` is either:
|
||||
|
||||
* an attribute of the `sharp.format` Object e.g. `sharp.format.jpeg`, or
|
||||
* a String containing `jpeg`, `png`, `webp` or `raw`.
|
||||
|
||||
#### quality(quality)
|
||||
|
||||
The output quality to use for lossy JPEG, WebP and TIFF output formats. The default quality is `80`.
|
||||
|
||||
`quality` is a Number between 1 and 100.
|
||||
|
||||
#### progressive()
|
||||
|
||||
Use progressive (interlace) scan for JPEG and PNG output. This typically reduces compression performance by 30% but results in an image that can be rendered sooner when decompressed.
|
||||
|
||||
#### withMetadata([metadata])
|
||||
|
||||
Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
||||
This will also convert to and add the latest web-friendly v2 sRGB ICC profile.
|
||||
|
||||
The optional `metadata` parameter, if present, is an Object with the attributes to update.
|
||||
New attributes cannot be inserted, only existing attributes updated.
|
||||
|
||||
* `orientation` is an integral Number between 1 and 8, used to update the value of the EXIF `Orientation` tag.
|
||||
This has no effect if the input image does not have an EXIF `Orientation` tag.
|
||||
|
||||
The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
||||
|
||||
#### tile(options)
|
||||
|
||||
The size, overlap, container and directory layout to use when generating square Deep Zoom image pyramid tiles.
|
||||
|
||||
`options` is an Object with one or more of the following attributes:
|
||||
|
||||
* `size` is an integral Number between 1 and 8192. The default value is 256 pixels.
|
||||
* `overlap` is an integral Number between 0 and 8192. The default value is 0 pixels.
|
||||
* `container` is a String, with value `fs` or `zip`. The default value is `fs`.
|
||||
* `layout` is a String, with value `dz`, `zoomify` or `google`. The default value is `dz`.
|
||||
|
||||
You can also use the file extension .zip or .szi to write to a ZIP container instead of the filesystem.
|
||||
|
||||
```javascript
|
||||
sharp('input.tiff')
|
||||
.tile({
|
||||
size: 512
|
||||
})
|
||||
.toFile('output.dzi', function(err, info) {
|
||||
// output.dzi is the Deep Zoom XML definition
|
||||
// output_files contains 512x512 tiles grouped by zoom level
|
||||
});
|
||||
```
|
||||
|
||||
#### withoutChromaSubsampling()
|
||||
|
||||
Disable the use of [chroma subsampling](http://en.wikipedia.org/wiki/Chroma_subsampling) with JPEG output (4:4:4).
|
||||
|
||||
This can improve colour representation at higher quality settings (90+),
|
||||
but usually increases output file size and typically reduces performance by 25%.
|
||||
|
||||
The default behaviour is to use chroma subsampling (4:2:0).
|
||||
|
||||
#### compressionLevel(compressionLevel)
|
||||
|
||||
An advanced setting for the _zlib_ compression level of the lossless PNG output format. The default level is `6`.
|
||||
|
||||
`compressionLevel` is a Number between 0 and 9.
|
||||
|
||||
#### withoutAdaptiveFiltering()
|
||||
|
||||
An advanced setting to disable adaptive row filtering for the lossless PNG output format.
|
||||
|
||||
#### trellisQuantisation() / trellisQuantization()
|
||||
|
||||
_Requires libvips to have been compiled with mozjpeg support_
|
||||
|
||||
An advanced setting to apply the use of
|
||||
[trellis quantisation](http://en.wikipedia.org/wiki/Trellis_quantization) with JPEG output.
|
||||
Reduces file size and slightly increases relative quality at the cost of increased compression time.
|
||||
|
||||
#### overshootDeringing()
|
||||
|
||||
_Requires libvips to have been compiled with mozjpeg support_
|
||||
|
||||
An advanced setting to reduce the effects of
|
||||
[ringing](http://en.wikipedia.org/wiki/Ringing_%28signal%29) in JPEG output,
|
||||
in particular where black text appears on a white background (or vice versa).
|
||||
|
||||
#### optimiseScans() / optimizeScans()
|
||||
|
||||
_Requires libvips to have been compiled with mozjpeg support_
|
||||
|
||||
An advanced setting for progressive (interlace) JPEG output.
|
||||
Calculates which spectrum of DCT coefficients uses the fewest bits.
|
||||
Usually reduces file size at the cost of increased compression time.
|
||||
|
||||
### Attributes
|
||||
|
||||
#### format
|
||||
|
||||
An Object containing nested boolean values
|
||||
representing the available input and output formats/methods,
|
||||
for example:
|
||||
|
||||
```javascript
|
||||
> console.dir(sharp.format);
|
||||
|
||||
{ jpeg: { id: 'jpeg',
|
||||
input: { file: true, buffer: true, stream: true },
|
||||
output: { file: true, buffer: true, stream: true } },
|
||||
png: { id: 'png',
|
||||
input: { file: true, buffer: true, stream: true },
|
||||
output: { file: true, buffer: true, stream: true } },
|
||||
webp: { id: 'webp',
|
||||
input: { file: true, buffer: true, stream: true },
|
||||
output: { file: true, buffer: true, stream: true } },
|
||||
tiff: { id: 'tiff',
|
||||
input: { file: true, buffer: true, stream: true },
|
||||
output: { file: true, buffer: false, stream: false } },
|
||||
raw: { id: 'raw',
|
||||
input: { file: false, buffer: false, stream: false },
|
||||
output: { file: false, buffer: true, stream: true } } }
|
||||
```
|
||||
|
||||
#### queue
|
||||
|
||||
An EventEmitter that emits a `change` event when a task is either:
|
||||
|
||||
* queued, waiting for _libuv_ to provide a worker thread
|
||||
* complete
|
||||
|
||||
```javascript
|
||||
sharp.queue.on('change', function(queueLength) {
|
||||
console.log('Queue contains ' + queueLength + ' task(s)');
|
||||
});
|
||||
```
|
||||
|
||||
#### versions
|
||||
|
||||
An Object containing the version numbers of libvips and, on Linux, its dependencies.
|
||||
|
||||
```javascript
|
||||
console.log(sharp.versions);
|
||||
```
|
||||
|
||||
### Utilities
|
||||
|
||||
#### sharp.cache([options])
|
||||
|
||||
If `options` is provided, sets the limits of _libvips'_ operation cache.
|
||||
|
||||
* `options.memory` is the maximum memory in MB to use for this cache, with a default value of 50
|
||||
* `options.files` is the maximum number of files to hold open, with a default value of 20
|
||||
* `options.items` is the maximum number of operations to cache, with a default value of 100
|
||||
|
||||
`options` can also be a boolean, where `true` enables the default cache settings and `false` disables all caching.
|
||||
|
||||
This method always returns cache statistics, useful for determining how much working memory is required for a particular task.
|
||||
|
||||
```javascript
|
||||
var stats = sharp.cache();
|
||||
```
|
||||
|
||||
```javascript
|
||||
sharp.cache( { items: 200 } );
|
||||
sharp.cache( { files: 0 } );
|
||||
sharp.cache(false);
|
||||
```
|
||||
|
||||
#### sharp.concurrency([threads])
|
||||
|
||||
`threads`, if provided, is the Number of threads _libvips'_ should create for processing each image. The default value is the number of CPU cores. A value of `0` will reset to this default.
|
||||
|
||||
This method always returns the current concurrency.
|
||||
|
||||
```javascript
|
||||
var threads = sharp.concurrency(); // 4
|
||||
sharp.concurrency(2); // 2
|
||||
sharp.concurrency(0); // 4
|
||||
```
|
||||
|
||||
The maximum number of images that can be processed in parallel is limited by libuv's `UV_THREADPOOL_SIZE` environment variable.
|
||||
|
||||
#### sharp.counters()
|
||||
|
||||
Provides access to internal task counters.
|
||||
|
||||
* `queue` is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
|
||||
* `process` is the number of resize tasks currently being processed.
|
||||
|
||||
```javascript
|
||||
var counters = sharp.counters(); // { queue: 2, process: 4 }
|
||||
```
|
||||
|
||||
#### sharp.simd([enable])
|
||||
|
||||
_Requires libvips to have been compiled with liborc support_
|
||||
|
||||
Improves the performance of `resize`, `blur` and `sharpen` operations
|
||||
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||
|
||||
* `enable`, if present, is a boolean where `true` enables and `false` disables the use of SIMD.
|
||||
|
||||
This method always returns the current state.
|
||||
|
||||
This feature is currently disabled by default
|
||||
but future versions may enable it by default.
|
||||
|
||||
When enabled, versions of liborc prior to 0.4.24
|
||||
and versions of libvips prior to 8.2.0
|
||||
have been known to crash under heavy load.
|
||||
|
||||
```javascript
|
||||
var simd = sharp.simd();
|
||||
// simd is `true` if SIMD is currently enabled
|
||||
```
|
||||
|
||||
```javascript
|
||||
var simd = sharp.simd(true);
|
||||
// attempts to enable the use of SIMD, returning true if available
|
||||
```
|
||||
38
docs/build.js
Normal file
38
docs/build.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
const jsdoc2md = require('jsdoc-to-markdown');
|
||||
|
||||
[
|
||||
'constructor',
|
||||
'input',
|
||||
'resize',
|
||||
'composite',
|
||||
'operation',
|
||||
'colour',
|
||||
'channel',
|
||||
'output',
|
||||
'utility'
|
||||
].forEach(async (m) => {
|
||||
const input = path.join('lib', `${m}.js`);
|
||||
const output = path.join('docs', `api-${m}.md`);
|
||||
|
||||
const ast = await jsdoc2md.getTemplateData({ files: input });
|
||||
const markdown = await jsdoc2md.render({
|
||||
data: ast,
|
||||
'global-index-format': 'none',
|
||||
'module-index-format': 'none'
|
||||
});
|
||||
|
||||
const cleanMarkdown = markdown
|
||||
.replace(/(## )([A-Za-z0-9]+)([^\n]*)/g, '$1$2\n> $2$3\n') // simplify headings to match those of documentationjs, ensures existing URLs work
|
||||
.replace(/<a name="[A-Za-z0-9+]+"><\/a>/g, '') // remove anchors, let docute add these (at markdown to HTML render time)
|
||||
.replace(/\*\*Kind\*\*: global[^\n]+/g, '') // remove all "global" Kind labels (requires JSDoc refactoring)
|
||||
.trim();
|
||||
|
||||
await fs.writeFile(output, cleanMarkdown);
|
||||
});
|
||||
1702
docs/changelog.md
1702
docs/changelog.md
File diff suppressed because it is too large
Load Diff
1
docs/docute.min.js
vendored
Normal file
1
docs/docute.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
116
docs/firebase.json
Normal file
116
docs/firebase.json
Normal file
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"hosting": {
|
||||
"site": "pixelplumbing-sharp",
|
||||
"public": ".",
|
||||
"ignore": [
|
||||
".*",
|
||||
"build.js",
|
||||
"firebase.json",
|
||||
"image/**",
|
||||
"search-index/**"
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"source": "**",
|
||||
"headers": [
|
||||
{ "key": "Cache-Control", "value": "max-age=86400" },
|
||||
{ "key": "X-Content-Type-Options", "value": "nosniff" },
|
||||
{ "key": "X-Frame-Options", "value": "SAMEORIGIN" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"redirects": [
|
||||
{
|
||||
"source": "**/install/**",
|
||||
"destination": "/install",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "/page/install",
|
||||
"destination": "/install",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-constructor/**",
|
||||
"destination": "/api-constructor",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-input/**",
|
||||
"destination": "/api-input",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-output/**",
|
||||
"destination": "/api-output",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-resize/**",
|
||||
"destination": "/api-resize",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-compsite/**",
|
||||
"destination": "/api-compsite",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-operation/**",
|
||||
"destination": "/api-operation",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-colour/**",
|
||||
"destination": "/api-colour",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-channel/**",
|
||||
"destination": "/api-channel",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/api-utility/**",
|
||||
"destination": "/api-utility",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "/page/api",
|
||||
"destination": "/api-constructor",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/performance/**",
|
||||
"destination": "/performance",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "/page/performance",
|
||||
"destination": "/performance",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "**/changelog/**",
|
||||
"destination": "/changelog",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "/page/changelog",
|
||||
"destination": "/changelog",
|
||||
"type": 301
|
||||
},
|
||||
{
|
||||
"source": "/en/**",
|
||||
"destination": "/",
|
||||
"type": 301
|
||||
}
|
||||
],
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "**",
|
||||
"destination": "/index.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
286
docs/humans.txt
Normal file
286
docs/humans.txt
Normal file
@@ -0,0 +1,286 @@
|
||||
/* THANKS */
|
||||
|
||||
Name: John Cupitt
|
||||
GitHub: https://github.com/jcupitt
|
||||
|
||||
Name: Pierre Inglebert
|
||||
GitHub: https://github.com/pierreinglebert
|
||||
|
||||
Name: Jonathan Ong
|
||||
GitHub: https://github.com/jonathanong
|
||||
|
||||
Name: Chanon Sajjamanochai
|
||||
GitHub: https://github.com/chanon
|
||||
|
||||
Name: Juliano Julio
|
||||
GitHub: https://github.com/julianojulio
|
||||
|
||||
Name: Daniel Gasienica
|
||||
GitHub: https://github.com/gasi
|
||||
|
||||
Name: Julian Walker
|
||||
GitHub: https://github.com/julianwa
|
||||
|
||||
Name: Amit Pitaru
|
||||
GitHub: https://github.com/apitaru
|
||||
|
||||
Name: Brandon Aaron
|
||||
GitHub: https://github.com/brandonaaron
|
||||
|
||||
Name: Andreas Lind
|
||||
GitHub: https://github.com/papandreouGitHub:
|
||||
|
||||
Name: Maurus Cuelenaere
|
||||
GitHub: https://github.com/mcuelenaere
|
||||
|
||||
Name: Linus Unnebäck
|
||||
GitHub: https://github.com/LinusU
|
||||
|
||||
Name: Victor Mateevitsi
|
||||
GitHub: https://github.com/mvictoras
|
||||
|
||||
Name: Alaric Holloway
|
||||
GitHub: https://github.com/skedastik
|
||||
|
||||
Name: Bernhard K. Weisshuhn
|
||||
GitHub: https://github.com/bkw
|
||||
|
||||
Name: David A. Carley
|
||||
GitHub: https://github.com/dacarley
|
||||
|
||||
Name: John Tobin
|
||||
GitHub: https://github.com/jtobinisaniceguy
|
||||
|
||||
Name: Kenton Gray
|
||||
GitHub: https://github.com/kentongray
|
||||
|
||||
Name: Felix Bünemann
|
||||
GitHub: https://github.com/felixbuenemann
|
||||
|
||||
Name: Samy Al Zahrani
|
||||
GitHub: https://github.com/salzhrani
|
||||
|
||||
Name: Chintan Thakkar
|
||||
GitHub: https://github.com/lemnisk8
|
||||
|
||||
Name: F. Orlando Galashan
|
||||
GitHub: https://github.com/frulo
|
||||
|
||||
Name: Kleis Auke Wolthuizen
|
||||
GitHub: https://github.com/kleisauke
|
||||
|
||||
Name: Matt Hirsch
|
||||
GitHub: https://github.com/mhirsch
|
||||
|
||||
Name: Rahul Nanwani
|
||||
GitHub: https://github.com/rnanwani
|
||||
|
||||
Name: Matthias Thoemmes
|
||||
GitHub: https://github.com/cmtt
|
||||
|
||||
Name: Patrick Paskaris
|
||||
GitHub: https://github.com/ppaskaris
|
||||
|
||||
Name: Jérémy Lal
|
||||
GitHub: https://github.com/kapouer
|
||||
|
||||
Name: Alice Monday
|
||||
GitHub: https://github.com/alice0meta
|
||||
|
||||
Name: Kristo Jorgenson
|
||||
GitHub: https://github.com/kristojorg
|
||||
|
||||
Name: Yves Bos
|
||||
GitHub: https://github.com/YvesBos
|
||||
|
||||
Name: Nicolas Coden
|
||||
GitHub: https://github.com/ncoden
|
||||
|
||||
Name: Matt Parrish
|
||||
GitHub: https://github.com/pbomb
|
||||
|
||||
Name: Matthew McEachen
|
||||
GitHub: https://github.com/mceachen
|
||||
|
||||
Name: Jarda Kotěšovec
|
||||
GitHub: https://github.com/jardakotesovec
|
||||
|
||||
Name: Kenric D'Souza
|
||||
GitHub: https://github.com/AzureByte
|
||||
|
||||
Name: Oleh Aleinyk
|
||||
GitHub: https://github.com/oaleynik
|
||||
|
||||
Name: Marcel Bretschneider
|
||||
GitHub: https://github.com/3epnm
|
||||
|
||||
Name: Andrea Bianco
|
||||
GitHub: https://github.com/BiancoA
|
||||
|
||||
Name: Rik Heywood
|
||||
GitHub: https://github.com/rikh42
|
||||
|
||||
Name: Thomas Parisot
|
||||
GitHub: https://github.com/oncletom
|
||||
|
||||
Name: Nathan Graves
|
||||
GitHub: https://github.com/woolite64
|
||||
|
||||
Name: Tom Lokhorst
|
||||
GitHub: https://github.com/tomlokhorst
|
||||
|
||||
Name: Espen Hovlandsdal
|
||||
GitHub: https://github.com/rexxars
|
||||
|
||||
Name: Sylvain Dumont
|
||||
GitHub: https://github.com/sylvaindumont
|
||||
|
||||
Name: Alun Davies
|
||||
GitHub: https://github.com/alundavies
|
||||
|
||||
Name: Aidan Hoolachan
|
||||
GitHub: https://github.com/ajhool
|
||||
|
||||
Name: Axel Eirola
|
||||
GitHub: https://github.com/aeirola
|
||||
|
||||
Name: Freezy
|
||||
GitHub: https://github.com/freezy
|
||||
|
||||
Name: Julian Aubourg
|
||||
GitHub: https://github.com/jaubourg
|
||||
|
||||
Name: Keith Belovay
|
||||
GitHub: https://github.com/fromkeith
|
||||
|
||||
Name: Michael B. Klein
|
||||
GitHub: https://github.com/mbklein
|
||||
|
||||
Name: Jakub Michálek
|
||||
GitHub: https://github.com/Goues
|
||||
|
||||
Name: Ilya Ovdin
|
||||
GitHub: https://github.com/iovdin
|
||||
|
||||
Name: Andargor
|
||||
GitHub: https://github.com/Andargor
|
||||
|
||||
Name: Nicolas Stepien
|
||||
GitHub: https://github.com/MayhemYDG
|
||||
|
||||
Name: Paul Neave
|
||||
GitHub: https://github.com/neave
|
||||
|
||||
Name: Brendan Kennedy
|
||||
GitHub: https://github.com/rustyguts
|
||||
|
||||
Name: Brychan Bennett-Odlum
|
||||
GitHub: https://github.com/BrychanOdlum
|
||||
|
||||
Name: Edward Silverton
|
||||
GitHub: https://github.com/edsilv
|
||||
|
||||
Name: Dumitru Deveatii
|
||||
GitHub: https://github.com/dimadeveatii
|
||||
|
||||
Name: Roland Asmann
|
||||
GitHub: https://github.com/malice00
|
||||
|
||||
Name: Roman Malieiev
|
||||
GitHub: https://github.com/romaleev
|
||||
|
||||
Name: Jerome Vouillon
|
||||
GitHub: https://github.com/vouillon
|
||||
|
||||
Name: Tomáš Szabo
|
||||
GitHub: https://github.com/deftomat
|
||||
|
||||
Name: Robert O'Rourke
|
||||
GitHub: https://github.com/roborourke
|
||||
|
||||
Name: Denis Soldatov
|
||||
GitHub: https://github.com/derom
|
||||
|
||||
Name: Stefan Probst
|
||||
GitHub: https://github.com/stefanprobst
|
||||
|
||||
Name: Thomas Beiganz
|
||||
GitHub: https://github.com/beig
|
||||
|
||||
Name: Florian Busch
|
||||
GitHub: https://github.com/florian-busch
|
||||
|
||||
Name: Matthieu Salettes
|
||||
GitHub: https://github.com/msalettes
|
||||
|
||||
Name: Taneli Vatanen
|
||||
GitHub: https://github.com/Daiz
|
||||
|
||||
Name: Mart Jansink
|
||||
GitHub: https://github.com/mart-jansink
|
||||
|
||||
Name: Tenpi
|
||||
GitHub: https://github.com/Tenpi
|
||||
|
||||
Name: Zaruike
|
||||
GitHub: https://github.com/Zaruike
|
||||
|
||||
Name: Erlend F
|
||||
GitHub: https://github.com/erf
|
||||
|
||||
Name: Drian Naude
|
||||
GitHub: https://github.com/driannaude
|
||||
|
||||
Name: Max Gordon
|
||||
GitHub: https://github.com/gforge
|
||||
|
||||
Name: Chris Banks
|
||||
GitHub: https://github.com/christopherbradleybanks
|
||||
|
||||
Name: codepage949
|
||||
GitHub: https://github.com/codepage949
|
||||
|
||||
Name: Chris Hranj
|
||||
GitHub: https://github.com/Brodan
|
||||
|
||||
Name: Ankur Parihar
|
||||
GitHub: https://github.com/ankurparihar
|
||||
|
||||
Name: Joona Heinikoski
|
||||
GitHub: https://github.com/joonamo
|
||||
|
||||
Name: AlexanderTheGrey
|
||||
GitHub: https://github.com/AlexanderTheGrey
|
||||
|
||||
Name: Blayne Chard
|
||||
GitHub: https://github.com/blacha
|
||||
|
||||
Name: Brahim
|
||||
GitHub: https://github.com/brahima
|
||||
|
||||
Name: Anton Marsden
|
||||
GitHub: https://github.com/antonmarsden
|
||||
|
||||
Name: Marcos Casagrande
|
||||
GitHub: https://github.com/marcosc90
|
||||
|
||||
Name: Emanuel Jöbstl
|
||||
GitHub: https://github.com/ejoebstl
|
||||
|
||||
Name: Tomasz Janowski
|
||||
GitHub: https://github.com/janaz
|
||||
|
||||
Name: Lachlan Newman
|
||||
GitHub: https://github.com/LachlanNewman
|
||||
|
||||
Name: BJJ
|
||||
GitHub: https://github.com/bianjunjie1981
|
||||
|
||||
Name: Dennis Beatty
|
||||
GitHub: https://github.com/dnsbty
|
||||
|
||||
Name: Ingvar Stepanyan
|
||||
GitHub: https://github.com/RReverser
|
||||
|
||||
Name: Tamás András Horváth
|
||||
GitHub: https://github.com/icetee
|
||||
61
docs/image/api-resize-fit.svg
Normal file
61
docs/image/api-resize-fit.svg
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="998" height="243" viewBox="0 0 998 243">
|
||||
<defs>
|
||||
<g id="placeholder">
|
||||
<rect width="180" height="128" fill="#64bed8"/>
|
||||
<circle cx="61.1" cy="36.8" r="19.3" fill="#ffefa9"/>
|
||||
<circle cx="61.1" cy="36.8" r="18.1" fill="#fdda42"/>
|
||||
<path d="m67.2 34.7 15.2 46L90 57.9l30.4 38 7.8-15.2 7.5 15.4H44z" fill="#6a696f"/>
|
||||
<path d="m82.4 80.7-15.2-46-.3 69h22.9z" fill="#474749"/>
|
||||
<path d="m90.1 58 12.2 15 18.2 23-13.9.1z" fill="#474749"/>
|
||||
<path d="M135.8 96H131l-2.8-15.3z" fill="#474749"/>
|
||||
<path d="M35.2 96h107.1c0 1.7-1.4 3.2-3.2 3.2H38.4a3.2 3.2 0 0 1-3.2-3.2z" fill="#b9c861"/>
|
||||
<path d="m67.2 34.7-.1 31-6.2-3-5.3 2.7z" fill="#fff"/>
|
||||
<path d="m67.2 34.7 7.6 23-7.7 8z" fill="#b3b1b4"/>
|
||||
<rect width="30.8" height="7.7" x="71.1" y="27.2" rx="2.8" ry="4.1" fill="#fff"/>
|
||||
<rect width="30.8" height="7.7" x="82.2" y="34.8" rx="2.8" ry="4.1" fill="#fff"/>
|
||||
<rect width="30.8" height="7.7" x="36.2" y="19.6" rx="2.8" ry="4.1" fill="#fff"/>
|
||||
<path d="m89.6 72.8-7.2 7.9L90 57.9l10 23z" fill="#fff"/>
|
||||
<path d="m90.1 58 10 23 2.2-8z" fill="#b3b1b4"/>
|
||||
<path d="M131.2 85.2 137 68l9 17.2-8 6z" fill="#8da128"/>
|
||||
<rect width="109.4" height="6.8" x="33.9" y="99.1" rx="13.2" ry="11.4" fill="#22b0d6"/>
|
||||
<path d="m137 68-5.8 17.2 6.8 6.1.3-13.7z" fill="#727d2e"/>
|
||||
<rect width="83.3" height="6.8" x="50.8" y="103.6" rx="10" ry="11.4" fill="#22b0d6"/>
|
||||
<rect width=".7" height="18.4" x="138" y="77.6" fill="#585657"/>
|
||||
<rect width=".5" height="5.2" x="2" y="-161.3" fill="#585657" transform="rotate(120)"/>
|
||||
<rect width=".5" height="5.3" x="5.5" y="-163.3" fill="#585657" transform="rotate(120)"/>
|
||||
<rect width=".5" height="4.8" x="-142.4" y="77.7" fill="#585657" transform="rotate(240)"/>
|
||||
<rect width=".5" height="5.1" x="-146" y="75.6" fill="#585657" transform="rotate(240)"/>
|
||||
</g>
|
||||
<pattern id="img" height="100%" width="100%" viewBox="0 0 180 128">
|
||||
<use xlink:href="#placeholder"/>
|
||||
</pattern>
|
||||
<pattern id="img-fill" width="100%" height="100%" viewBox="0 0 180 128" preserveAspectRatio="none">
|
||||
<use xlink:href="#placeholder"/>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="998" height="243" fill="#ddd"/>
|
||||
<g id="cover">
|
||||
<rect x="22" y="28" width="180" height="132" fill="url(#img)"/>
|
||||
<rect x="48" y="30" width="128" height="128" fill="none" stroke="#000" stroke-width="4"/>
|
||||
<text x="112" y="85%" dominant-baseline="middle" text-anchor="middle" font-family="sans" font-size="32" font-weight="bold">cover</text>
|
||||
</g>
|
||||
<g id="contain">
|
||||
<rect x="240" y="30" width="128" height="128" fill="url(#img)" stroke="#000" stroke-width="4"/>
|
||||
<text x="304" y="85%" dominant-baseline="middle" text-anchor="middle" font-family="sans" font-size="32" font-weight="bold" fill="#555">contain</text>
|
||||
</g>
|
||||
<g id="fill">
|
||||
<rect x="432" y="30" width="128" height="128" fill="url(#img-fill)" stroke="#000" stroke-width="4"/>
|
||||
<text x="496" y="85%" dominant-baseline="middle" text-anchor="middle" font-family="sans" font-size="32" font-weight="bold">fill</text>
|
||||
</g>
|
||||
<g id="inside">
|
||||
<rect x="624" y="48" width="128" height="92" fill="url(#img)" stroke="#000" stroke-width="4"/>
|
||||
<rect x="624" y="30" width="128" height="128" fill="none" stroke="#000" stroke-width="4" stroke-dasharray="12 4" stroke-dashoffset="6"/>
|
||||
<text x="688" y="85%" dominant-baseline="middle" text-anchor="middle" font-family="sans" font-size="32" font-weight="bold" fill="#555">inside</text>
|
||||
</g>
|
||||
<g id="outside">
|
||||
<rect x="792" y="30" width="176" height="128" fill="url(#img)" stroke="#000" stroke-width="4"/>
|
||||
<rect x="816" y="30" width="128" height="128" fill="none" stroke="#000" stroke-width="4" stroke-dasharray="12 4" stroke-dashoffset="-2"/>
|
||||
<text x="880" y="85%" dominant-baseline="middle" text-anchor="middle" font-family="sans" font-size="32" font-weight="bold">outside</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
BIN
docs/image/sharp-logo-32.png
Normal file
BIN
docs/image/sharp-logo-32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 652 B |
BIN
docs/image/sharp-logo-600.png
Normal file
BIN
docs/image/sharp-logo-600.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
11
docs/image/sharp-logo-mono.svg
Normal file
11
docs/image/sharp-logo-mono.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||
<!-- Creative Commons CC0 1.0 Universal Public Domain Dedication -->
|
||||
<defs>
|
||||
<mask id="c">
|
||||
<path fill="none" stroke="#fff" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66m.001 0V238.484m0-150.121v171.572l178.725-23.917m-359.843 19.584V477.22m2.387 156.95V462.591L93.984 486.515"/>
|
||||
<path fill="none" stroke="#000" stroke-width="112" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||
</mask>
|
||||
</defs>
|
||||
<path mask="url(#c)" fill="none" stroke="#000" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66m.001 0V238.484m0-150.121v171.572l178.725-23.917m-359.843 19.584V477.22m2.387 156.95V462.591L93.984 486.515"/>
|
||||
<path fill="none" stroke="#000" stroke-width="80" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 929 B |
5
docs/image/sharp-logo.svg
Normal file
5
docs/image/sharp-logo.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||
<!-- Creative Commons CC0 1.0 Universal Public Domain Dedication -->
|
||||
<path fill="none" stroke="#9c0" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66M451.441 438.66V238.484M451.441 88.363v171.572l178.725-23.917M270.323 255.602V477.22M272.71 634.17V462.591L93.984 486.515"/>
|
||||
<path fill="none" stroke="#090" stroke-width="80" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 508 B |
206
docs/index.html
Normal file
206
docs/index.html
Normal file
File diff suppressed because one or more lines are too long
111
docs/index.md
111
docs/index.md
@@ -1,111 +0,0 @@
|
||||
# sharp
|
||||
|
||||
The typical use case for this high speed Node.js module
|
||||
is to convert large images in common formats to
|
||||
smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
||||
|
||||
Resizing an image is typically 4x-5x faster than using the
|
||||
quickest ImageMagick and GraphicsMagick settings.
|
||||
|
||||
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
||||
Lanczos resampling ensures quality is not sacrificed for speed.
|
||||
|
||||
As well as image resizing, operations such as
|
||||
rotation, extraction, compositing and gamma correction are available.
|
||||
|
||||
Most Windows (x64), Linux and ARMv6+ systems do not require
|
||||
the installation of any external runtime dependencies.
|
||||
|
||||
Use with OS X is as simple as running `brew install homebrew/science/vips`
|
||||
to install the libvips dependency.
|
||||
|
||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||
|
||||
### Formats
|
||||
|
||||
This module supports reading JPEG, PNG, WebP, TIFF, GIF and SVG images.
|
||||
|
||||
Output images can be in JPEG, PNG and WebP formats as well as uncompressed raw pixel data.
|
||||
|
||||
Streams, Buffer objects and the filesystem can be used for input and output.
|
||||
|
||||
A single input Stream can be split into multiple processing pipelines and output Streams.
|
||||
|
||||
Deep Zoom image pyramids can be generated,
|
||||
suitable for use with "slippy map" tile viewers like
|
||||
[OpenSeadragon](https://github.com/openseadragon/openseadragon)
|
||||
and [Leaflet](https://github.com/turban/Leaflet.Zoomify).
|
||||
|
||||
### Fast
|
||||
|
||||
This module is powered by the blazingly fast
|
||||
[libvips](https://github.com/jcupitt/libvips) image processing library,
|
||||
originally created in 1989 at Birkbeck College
|
||||
and currently maintained by
|
||||
[John Cupitt](https://github.com/jcupitt).
|
||||
|
||||
Only small regions of uncompressed image data
|
||||
are held in memory and processed at a time,
|
||||
taking full advantage of multiple CPU cores and L1/L2/L3 cache.
|
||||
|
||||
Everything remains non-blocking thanks to _libuv_,
|
||||
no child processes are spawned and Promises/A+ are supported.
|
||||
|
||||
### Optimal
|
||||
|
||||
Huffman tables are optimised when generating JPEG output images
|
||||
without having to use separate command line tools like
|
||||
[jpegoptim](https://github.com/tjko/jpegoptim) and
|
||||
[jpegtran](http://jpegclub.org/jpegtran/).
|
||||
|
||||
PNG filtering can be disabled,
|
||||
which for diagrams and line art often produces the same result
|
||||
as [pngcrush](http://pmt.sourceforge.net/pngcrush/).
|
||||
|
||||
### Contributing
|
||||
|
||||
A [guide for contributors](https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md)
|
||||
covers reporting bugs, requesting features and submitting code changes.
|
||||
|
||||
### Credits
|
||||
|
||||
This module would never have been possible without
|
||||
the help and code contributions of the following people:
|
||||
|
||||
* [John Cupitt](https://github.com/jcupitt)
|
||||
* [Pierre Inglebert](https://github.com/pierreinglebert)
|
||||
* [Jonathan Ong](https://github.com/jonathanong)
|
||||
* [Chanon Sajjamanochai](https://github.com/chanon)
|
||||
* [Juliano Julio](https://github.com/julianojulio)
|
||||
* [Daniel Gasienica](https://github.com/gasi)
|
||||
* [Julian Walker](https://github.com/julianwa)
|
||||
* [Amit Pitaru](https://github.com/apitaru)
|
||||
* [Brandon Aaron](https://github.com/brandonaaron)
|
||||
* [Andreas Lind](https://github.com/papandreou)
|
||||
* [Maurus Cuelenaere](https://github.com/mcuelenaere)
|
||||
* [Linus Unnebäck](https://github.com/LinusU)
|
||||
* [Victor Mateevitsi](https://github.com/mvictoras)
|
||||
* [Alaric Holloway](https://github.com/skedastik)
|
||||
* [Bernhard K. Weisshuhn](https://github.com/bkw)
|
||||
* [David A. Carley](https://github.com/dacarley)
|
||||
* [John Tobin](https://github.com/jtobinisaniceguy)
|
||||
* [Kenton Gray](https://github.com/kentongray)
|
||||
* [Felix Bünemann](https://github.com/felixbuenemann)
|
||||
* [Samy Al Zahrani](https://github.com/salzhrani)
|
||||
|
||||
Thank you!
|
||||
|
||||
### Licence
|
||||
|
||||
Copyright 2013, 2014, 2015, 2016 Lovell Fuller and contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
392
docs/install.md
392
docs/install.md
@@ -1,195 +1,295 @@
|
||||
# Installation
|
||||
|
||||
Works with your choice of JavaScript package manager.
|
||||
|
||||
> ⚠️ **Please ensure your package manager is configured to install optional dependencies**
|
||||
|
||||
If a package manager lockfile must support multiple platforms,
|
||||
please see the [cross-platform](#cross-platform) section
|
||||
to help decide which package manager is appropriate.
|
||||
|
||||
```sh
|
||||
npm install sharp
|
||||
```
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* C++11 compatible compiler such as gcc 4.8+, clang 3.0+ or MSVC 2013+
|
||||
* [node-gyp](https://github.com/TooTallNate/node-gyp#installation)
|
||||
|
||||
### Linux
|
||||
|
||||
[](https://travis-ci.org/lovell/sharp)
|
||||
[](https://circleci.com/gh/lovell/sharp)
|
||||
|
||||
libvips and its dependencies are fetched and stored within `node_modules/sharp/lib` during `npm install`.
|
||||
This involves an automated HTTPS download of approximately 6.7MB.
|
||||
|
||||
Most recent Linux-based operating systems with glibc running on x64 and ARMv6+ CPUs should "just work", e.g.:
|
||||
|
||||
* Debian 7, 8
|
||||
* Ubuntu 12.04, 14.04, 15.10, 16.04
|
||||
* Centos 7
|
||||
* Fedora 22, 23
|
||||
* openSUSE 13.2
|
||||
* Archlinux 2015.06.01
|
||||
* Raspbian Jessie
|
||||
* Amazon Linux 2015.03, 2015.09
|
||||
|
||||
To use your own version of libvips instead of the provided binaries, make sure it is
|
||||
at least the version listed under `config.libvips` in the `package.json` file,
|
||||
that it can be located using `pkg-config --modversion vips-cpp`
|
||||
and that it has been compiled with `_GLIBCXX_USE_CXX11_ABI=0`.
|
||||
|
||||
If you are using non-stadard paths (anything other than `/usr` or `/usr/local`),
|
||||
you might need to set `PKG_CONFIG_PATH` during `npm install`
|
||||
and `LD_LIBRARY_PATH` at runtime.
|
||||
|
||||
This allows the use of newer versions of libvips with older versions of sharp.
|
||||
|
||||
For 32-bit Intel CPUs and older Linux-based operating systems such as Centos 6,
|
||||
a system-wide installation of the most suitable version of
|
||||
libvips and its dependencies can be achieved by running
|
||||
the following command as a user with `sudo` access
|
||||
(requires `curl` and `pkg-config`):
|
||||
|
||||
```sh
|
||||
# WARNING: This script is deprecated. You probably don't need to run it. Please read above.
|
||||
curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | sudo bash -
|
||||
pnpm add sharp
|
||||
```
|
||||
|
||||
For Linux-based operating systems such as Alpine that use musl libc,
|
||||
the smaller stack size means libvips' cache should be disabled
|
||||
via `sharp.cache(false)` to avoid a stack overflow.
|
||||
|
||||
Beware of Linux OS upgrades that introduce v5.1+ of the `g++` compiler due to
|
||||
[changes](https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html)
|
||||
in the C++11 ABI.
|
||||
This module assumes the previous behaviour, which can be enforced by setting the
|
||||
`_GLIBCXX_USE_CXX11_ABI=0` environment variable at libvips' compile time.
|
||||
|
||||
### Mac OS
|
||||
|
||||
[](https://travis-ci.org/lovell/sharp)
|
||||
|
||||
libvips must be installed before `npm install` is run.
|
||||
This can be achieved via homebrew:
|
||||
|
||||
```sh
|
||||
brew install homebrew/science/vips
|
||||
yarn add sharp
|
||||
```
|
||||
|
||||
For WebP suppport use:
|
||||
|
||||
```sh
|
||||
brew install homebrew/science/vips --with-webp
|
||||
# yarn v1 (maintenance mode)
|
||||
yarn add sharp --ignore-engines
|
||||
```
|
||||
|
||||
A missing or incorrectly configured _Xcode Command Line Tools_ installation
|
||||
[can lead](https://github.com/lovell/sharp/issues/80) to a
|
||||
`library not found for -ljpeg` error.
|
||||
If so, please try: `xcode-select --install`.
|
||||
```sh
|
||||
bun add sharp
|
||||
```
|
||||
|
||||
The _gettext_ dependency of _libvips_
|
||||
[can lead](https://github.com/lovell/sharp/issues/9)
|
||||
to a `library not found for -lintl` error.
|
||||
If so, please try `brew link gettext --force`.
|
||||
```sh
|
||||
deno run --allow-ffi ...
|
||||
```
|
||||
|
||||
### Windows
|
||||
## Prerequisites
|
||||
|
||||
[](https://ci.appveyor.com/project/lovell/sharp)
|
||||
* Node-API v9 compatible runtime e.g. Node.js ^18.17.0 or >=20.3.0.
|
||||
|
||||
libvips and its dependencies are fetched and stored within `node_modules\sharp` during `npm install`.
|
||||
This involves an automated HTTPS download of approximately 9MB.
|
||||
## Prebuilt binaries
|
||||
|
||||
Only 64-bit (x64) `node.exe` is supported.
|
||||
Ready-compiled sharp and libvips binaries are provided for use on the most common platforms:
|
||||
|
||||
### FreeBSD
|
||||
* macOS x64 (>= 10.13)
|
||||
* macOS ARM64
|
||||
* Linux ARM (glibc >= 2.28)
|
||||
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
|
||||
* Linux s390x (glibc >= 2.28)
|
||||
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
|
||||
* Windows x64
|
||||
* Windows x86
|
||||
|
||||
libvips must be installed before `npm install` is run.
|
||||
This can be achieved via [FreshPorts](https://www.freshports.org/graphics/vips/):
|
||||
This provides support for the
|
||||
JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats.
|
||||
|
||||
## Cross-platform
|
||||
|
||||
At install time, package managers will automatically select prebuilt binaries
|
||||
for the current OS platform and CPU architecture, where available.
|
||||
|
||||
Some package managers support multiple platforms and architectures
|
||||
within the same installation tree and/or using the same lockfile.
|
||||
|
||||
### npm v10+
|
||||
|
||||
> ⚠️ **npm `package-lock.json` files can cause installation problems due to [npm bug #4828](https://github.com/npm/cli/issues/4828)**
|
||||
|
||||
Provides limited support via `--os`, `--cpu` and `--libc` flags.
|
||||
|
||||
Example to support both Intel and ARM CPUs on macOS:
|
||||
```sh
|
||||
npm install --cpu=x64 --os=darwin sharp
|
||||
npm install --cpu=arm64 --os=darwin sharp
|
||||
```
|
||||
|
||||
Example to support both glibc and musl-based Linux:
|
||||
```sh
|
||||
npm install --cpu=x64 --os=linux sharp
|
||||
npm install --cpu=x64 --os=linux --libc=musl sharp
|
||||
```
|
||||
|
||||
### yarn v3+
|
||||
|
||||
Use the [supportedArchitectures](https://yarnpkg.com/configuration/yarnrc#supportedArchitectures) configuration.
|
||||
|
||||
### pnpm v8+
|
||||
|
||||
Use the [supportedArchitectures](https://pnpm.io/package_json#pnpmsupportedarchitectures) configuration.
|
||||
|
||||
## Custom libvips
|
||||
|
||||
To use a custom, globally-installed version of libvips instead of the provided binaries,
|
||||
make sure it is at least the version listed under `engines.libvips` in the `package.json` file
|
||||
and that it can be located using `pkg-config --modversion vips-cpp`.
|
||||
|
||||
For help compiling libvips and its dependencies, please see
|
||||
[building libvips from source](https://www.libvips.org/install.html#building-libvips-from-source).
|
||||
|
||||
The use of a globally-installed libvips is unsupported on Windows
|
||||
and on macOS when running Node.js under Rosetta.
|
||||
|
||||
## Building from source
|
||||
|
||||
This module will be compiled from source at `npm install` time when:
|
||||
|
||||
* a globally-installed libvips is detected (set the `SHARP_IGNORE_GLOBAL_LIBVIPS` environment variable to skip this), or
|
||||
* when the `npm install --build-from-source` flag is used.
|
||||
|
||||
Building from source requires:
|
||||
|
||||
* C++11 compiler
|
||||
* [node-addon-api](https://www.npmjs.com/package/node-addon-api) version 7+
|
||||
* [node-gyp](https://github.com/nodejs/node-gyp#installation) version 9+ and its dependencies
|
||||
|
||||
There is an install-time check for these dependencies.
|
||||
If `node-addon-api` or `node-gyp` cannot be found, try adding them via:
|
||||
|
||||
```sh
|
||||
npm install --save node-addon-api node-gyp
|
||||
```
|
||||
|
||||
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags
|
||||
(or the `npm_config_platform`, `npm_config_arch` and `npm_config_libc` environment variables)
|
||||
can be used to configure the target environment.
|
||||
|
||||
## WebAssembly
|
||||
|
||||
Experimental support is provided for runtime environments that provide
|
||||
multi-threaded Wasm via Workers.
|
||||
|
||||
Use in web browsers is unsupported.
|
||||
|
||||
Native text rendering is unsupported.
|
||||
|
||||
```sh
|
||||
npm install --cpu=wasm32 sharp
|
||||
```
|
||||
|
||||
## FreeBSD
|
||||
|
||||
The `vips` package must be installed before `npm install` is run.
|
||||
|
||||
```sh
|
||||
pkg install -y pkgconf vips
|
||||
```
|
||||
|
||||
```sh
|
||||
cd /usr/ports/graphics/vips/ && make install clean
|
||||
```
|
||||
|
||||
### Heroku
|
||||
## Linux memory allocator
|
||||
|
||||
[Alessandro Tagliapietra](https://github.com/alex88) maintains an
|
||||
[Heroku buildpack for libvips](https://github.com/alex88/heroku-buildpack-vips)
|
||||
and its dependencies.
|
||||
The default memory allocator on most glibc-based Linux systems
|
||||
(e.g. Debian, Red Hat) is unsuitable for long-running, multi-threaded
|
||||
processes that involve lots of small memory allocations.
|
||||
|
||||
### Docker
|
||||
For this reason, by default, sharp will limit the use of thread-based
|
||||
[concurrency](api-utility#concurrency) when the glibc allocator is
|
||||
detected at runtime.
|
||||
|
||||
[Marc Bachmann](https://github.com/marcbachmann) maintains an
|
||||
[Ubuntu-based Dockerfile for libvips](https://github.com/marcbachmann/dockerfile-libvips).
|
||||
To help avoid fragmentation and improve performance on these systems,
|
||||
the use of an alternative memory allocator such as
|
||||
[jemalloc](https://github.com/jemalloc/jemalloc) is recommended.
|
||||
|
||||
Those using musl-based Linux (e.g. Alpine) and non-Linux systems are
|
||||
unaffected.
|
||||
|
||||
## AWS Lambda
|
||||
|
||||
The `node_modules` directory of the
|
||||
[deployment package](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html)
|
||||
must include binaries for either the linux-x64 or linux-arm64 platforms
|
||||
depending on the chosen architecture.
|
||||
|
||||
When building your deployment package on a machine that differs from the target architecture,
|
||||
see the [cross-platform](#cross-platform) section to help decide which package manager is appropriate
|
||||
and how to configure it.
|
||||
|
||||
Some package managers use symbolic links
|
||||
but AWS Lambda does not support these within deployment packages.
|
||||
|
||||
To get the best performance select the largest memory available.
|
||||
A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
||||
|
||||
When integrating with AWS API Gateway, ensure it is configured with the relevant
|
||||
[binary media types](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html).
|
||||
|
||||
## Bundlers
|
||||
|
||||
### webpack
|
||||
|
||||
Ensure sharp is excluded from bundling via the
|
||||
[externals](https://webpack.js.org/configuration/externals/)
|
||||
configuration.
|
||||
|
||||
```js
|
||||
externals: {
|
||||
'sharp': 'commonjs sharp'
|
||||
}
|
||||
```
|
||||
|
||||
### esbuild
|
||||
|
||||
Ensure sharp is excluded from bundling via the
|
||||
[external](https://esbuild.github.io/api/#external)
|
||||
configuration.
|
||||
|
||||
```js
|
||||
buildSync({
|
||||
entryPoints: ['app.js'],
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
external: ['sharp'],
|
||||
})
|
||||
```
|
||||
|
||||
```sh
|
||||
docker pull marcbachmann/libvips
|
||||
esbuild app.js --bundle --platform=node --external:sharp
|
||||
```
|
||||
|
||||
[Will Jordan](https://github.com/wjordan) maintains an
|
||||
[Alpine-based Dockerfile for libvips](https://github.com/wjordan/dockerfile-libvips).
|
||||
For `serverless-esbuild`, ensure platform-specific binaries are installed
|
||||
via the `serverless.yml` configuration.
|
||||
|
||||
```sh
|
||||
docker pull wjordan/libvips
|
||||
```yaml
|
||||
custom:
|
||||
esbuild:
|
||||
external:
|
||||
- sharp
|
||||
packagerOptions:
|
||||
scripts:
|
||||
- npm install --os=linux --cpu=x64 sharp
|
||||
```
|
||||
|
||||
### AWS Lambda
|
||||
### electron
|
||||
|
||||
In order to use sharp on AWS Lambda, you need to [create a deployment package](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html). Because sharp
|
||||
downloads and links libraries for the current platform during `npm install` you have to
|
||||
do this on a system similar to the [Lambda Execution Environment](http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html). The easiest ways to do this, is to setup a
|
||||
small t2.micro instance using the AMI ID listed in the previous link, ssh into it as ec2-user
|
||||
and follow the instructions below.
|
||||
Ensure `sharp` is unpacked from the ASAR archive file using the
|
||||
[asarUnpack](https://www.electron.build/configuration/configuration.html)
|
||||
option.
|
||||
|
||||
Install dependencies:
|
||||
|
||||
```sh
|
||||
curl -s https://rpm.nodesource.com/setup_4.x | sudo bash -
|
||||
sudo yum install -y gcc-c++ nodejs
|
||||
```json
|
||||
{
|
||||
"build": {
|
||||
"asar": true,
|
||||
"asarUnpack": [
|
||||
"**/node_modules/sharp/**/*",
|
||||
"**/node_modules/@img/**/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Copy your code and package.json to the instance using `scp` and create a deployment package:
|
||||
## TypeScript
|
||||
|
||||
```sh
|
||||
cd sharp-lambda-example
|
||||
npm install
|
||||
zip -ur9 ../sharp-lambda-example.zip index.js node_modules
|
||||
TypeScript definitions are published as part of
|
||||
the `sharp` package from v0.32.0.
|
||||
|
||||
Previously these were available via the `@types/sharp` package,
|
||||
which is now deprecated.
|
||||
|
||||
When using Typescript, please ensure `devDependencies` includes
|
||||
the `@types/node` package.
|
||||
|
||||
## Fonts
|
||||
|
||||
When creating text images or rendering SVG images that contain text elements,
|
||||
`fontconfig` is used to find the relevant fonts.
|
||||
|
||||
On Windows and macOS systems, all system fonts are available for use.
|
||||
|
||||
On macOS systems using Homebrew, you may need to set the
|
||||
`PANGOCAIRO_BACKEND` environment variable to a value of `fontconfig`
|
||||
to ensure it is used for font discovery instead of Core Text.
|
||||
|
||||
On Linux systems, fonts that include the relevant
|
||||
[`fontconfig` configuration](https://www.freedesktop.org/software/fontconfig/fontconfig-user.html)
|
||||
when installed via package manager are available for use.
|
||||
|
||||
If `fontconfig` configuration is not found, the following error will occur:
|
||||
```
|
||||
Fontconfig error: Cannot load default config file
|
||||
```
|
||||
|
||||
You can now download your deployment ZIP using `scp` and upload it to Lambda. Be sure to set your Lambda runtime to Node.js 4.3.
|
||||
In serverless environments where there is no control over font packages,
|
||||
use the `FONTCONFIG_PATH` environment variable to point to a custom location.
|
||||
|
||||
**Performance Tip:** To get the best performance on Lambda choose the largest memory available because this also gives you the most cpu time (a 1536 MB function is 12x faster than a 128 MB function).
|
||||
Embedded SVG fonts are unsupported.
|
||||
|
||||
### Build tools
|
||||
## Known conflicts
|
||||
|
||||
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
||||
* [grunt-sharp](https://www.npmjs.com/package/grunt-sharp)
|
||||
### Canvas and Windows
|
||||
|
||||
### Security
|
||||
|
||||
Many users of this module process untrusted, user-supplied images,
|
||||
but there are aspects of security to consider when doing so.
|
||||
|
||||
It is possible to compile libvips with support for various third-party image loaders.
|
||||
Each of these libraries has undergone differing levels of security testing.
|
||||
|
||||
Whilst tools such as [American Fuzzy Lop](http://lcamtuf.coredump.cx/afl/)
|
||||
and [Valgrind](http://valgrind.org/) have been used to test
|
||||
the most popular web-based formats, as well as libvips itself,
|
||||
you are advised to perform your own testing and sandboxing.
|
||||
|
||||
ImageMagick in particular has a relatively large attack surface,
|
||||
which can be partially mitigated with a
|
||||
[policy.xml](http://www.imagemagick.org/script/resources.php)
|
||||
configuration file to prevent the use of coders known to be vulnerable.
|
||||
|
||||
```xml
|
||||
<policymap>
|
||||
<policy domain="coder" rights="none" pattern="EPHEMERAL" />
|
||||
<policy domain="coder" rights="none" pattern="URL" />
|
||||
<policy domain="coder" rights="none" pattern="HTTPS" />
|
||||
<policy domain="coder" rights="none" pattern="MVG" />
|
||||
<policy domain="coder" rights="none" pattern="MSL" />
|
||||
<policy domain="coder" rights="none" pattern="TEXT" />
|
||||
<policy domain="coder" rights="none" pattern="SHOW" />
|
||||
<policy domain="coder" rights="none" pattern="WIN" />
|
||||
<policy domain="coder" rights="none" pattern="PLT" />
|
||||
</policymap>
|
||||
If both `canvas` and `sharp` modules are used in the same Windows process, the following error may occur:
|
||||
```
|
||||
The specified procedure could not be found.
|
||||
```
|
||||
|
||||
Set the `MAGICK_CONFIGURE_PATH` environment variable
|
||||
to the directory containing the `policy.xml` file.
|
||||
|
||||
@@ -1,73 +1,111 @@
|
||||
# Performance
|
||||
|
||||
### Test environment
|
||||
|
||||
* AWS EC2 [c4.xlarge](http://aws.amazon.com/ec2/instance-types/#c4) (4x E5-2666 v3 @ 2.90GHz)
|
||||
* Amazon Linux AMI 2016.03.1 (HVM), SSD Volume Type
|
||||
* Node.js v6.2.0
|
||||
|
||||
### The contenders
|
||||
|
||||
* [jimp](https://www.npmjs.com/package/jimp) v0.2.24 - Image processing in pure JavaScript. Bilinear interpolation only.
|
||||
* [lwip](https://www.npmjs.com/package/lwip) v0.0.9 - Wrapper around CImg, compiles dependencies from source.
|
||||
* [imagemagick-native](https://www.npmjs.com/package/imagemagick-native) v1.9.2 - Wrapper around libmagick++, supports Buffers only.
|
||||
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
||||
* [gm](https://www.npmjs.com/package/gm) v1.22.0 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
||||
* sharp v0.15.0 / libvips v8.3.1 - Caching within libvips disabled to ensure a fair comparison.
|
||||
|
||||
### The task
|
||||
|
||||
Decompress a 2725x2225 JPEG image,
|
||||
resize to 720x480 using Lanczos 3 resampling (where available),
|
||||
then compress to JPEG.
|
||||
|
||||
### Results
|
||||
|
||||
| Module | Input | Output | Ops/sec | Speed-up |
|
||||
| :----------------- | :----- | :----- | ------: | -------: |
|
||||
| jimp (bilinear) | file | file | 0.94 | 1.0 |
|
||||
| jimp (bilinear) | buffer | buffer | 0.98 | 1.0 |
|
||||
| lwip | file | file | 1.14 | 1.2 |
|
||||
| lwip | buffer | buffer | 1.14 | 1.2 |
|
||||
| imagemagick-native | buffer | buffer | 1.66 | 1.8 |
|
||||
| imagemagick | file | file | 5.08 | 5.4 |
|
||||
| gm | buffer | buffer | 5.43 | 5.7 |
|
||||
| gm | file | file | 5.46 | 5.8 |
|
||||
| sharp | stream | stream | 26.52 | 28.2 |
|
||||
| sharp | file | file | 28.16 | 30.0 |
|
||||
| sharp | file | buffer | 28.27 | 30.1 |
|
||||
| sharp | buffer | file | 28.42 | 30.2 |
|
||||
| sharp | buffer | buffer | 28.42 | 30.2 |
|
||||
A test to benchmark the performance of this module relative to alternatives.
|
||||
|
||||
Greater libvips performance can be expected with caching enabled (default)
|
||||
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
||||
|
||||
The I/O limits of the relevant (de)compression library will generally determine maximum throughput.
|
||||
|
||||
### Benchmark test prerequisites
|
||||
## Contenders
|
||||
|
||||
Requires both _ImageMagick_ and _GraphicsMagick_:
|
||||
* [jimp](https://www.npmjs.com/package/jimp) v0.22.10 - Image processing in pure JavaScript.
|
||||
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
||||
* [gm](https://www.npmjs.com/package/gm) v1.25.0 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
||||
* [@squoosh/lib](https://www.npmjs.com/package/@squoosh/lib) v0.5.3 - Image libraries transpiled to WebAssembly, includes GPLv3 code, but "*Project no longer maintained*".
|
||||
* [@squoosh/cli](https://www.npmjs.com/package/@squoosh/cli) v0.7.3 - Command line wrapper around `@squoosh/lib`, avoids GPLv3 by spawning process, but "*Project no longer maintained*".
|
||||
* sharp v0.33.0 / libvips v8.15.0 - Caching within libvips disabled to ensure a fair comparison.
|
||||
|
||||
```sh
|
||||
brew install imagemagick
|
||||
brew install graphicsmagick
|
||||
```
|
||||
## Environment
|
||||
|
||||
```sh
|
||||
sudo apt-get install imagemagick libmagick++-dev graphicsmagick
|
||||
```
|
||||
### AMD64
|
||||
|
||||
```sh
|
||||
sudo yum install ImageMagick-devel ImageMagick-c++-devel GraphicsMagick
|
||||
```
|
||||
* AWS EC2 us-east-2 [c7a.xlarge](https://aws.amazon.com/ec2/instance-types/c7a/) (4x AMD EPYC 9R14)
|
||||
* Ubuntu 23.10 [13f233a16be2](https://hub.docker.com/layers/library/ubuntu/23.10/images/sha256-13f233a16be210b57907b98b0d927ceff7571df390701e14fe1f3901b2c4a4d7)
|
||||
* Node.js 20.10.0
|
||||
|
||||
### Running the benchmark test
|
||||
### ARM64
|
||||
|
||||
* AWS EC2 us-east-2 [c7g.xlarge](https://aws.amazon.com/ec2/instance-types/c7g/) (4x ARM Graviton3)
|
||||
* Ubuntu 23.10 [7708743264cb](https://hub.docker.com/layers/library/ubuntu/23.10/images/sha256-7708743264cbb7f6cf7fc13e915faece45a6cdda455748bc55e58e8de3d27b63)
|
||||
* Node.js 20.10.0
|
||||
|
||||
## Task: JPEG
|
||||
|
||||
Decompress a 2725x2225 JPEG image,
|
||||
resize to 720x588 using Lanczos 3 resampling (where available),
|
||||
then compress to JPEG at a "quality" setting of 80.
|
||||
|
||||
Note: jimp does not support Lanczos 3, bicubic resampling used instead.
|
||||
|
||||
#### Results: JPEG (AMD64)
|
||||
|
||||
| Module | Input | Output | Ops/sec | Speed-up |
|
||||
| :----------------- | :----- | :----- | ------: | -------: |
|
||||
| jimp | buffer | buffer | 0.84 | 1.0 |
|
||||
| squoosh-cli | file | file | 1.54 | 1.8 |
|
||||
| squoosh-lib | buffer | buffer | 2.24 | 2.7 |
|
||||
| imagemagick | file | file | 11.75 | 14.0 |
|
||||
| gm | buffer | buffer | 12.66 | 15.1 |
|
||||
| gm | file | file | 12.72 | 15.1 |
|
||||
| sharp | stream | stream | 48.31 | 57.5 |
|
||||
| sharp | file | file | 51.42 | 61.2 |
|
||||
| sharp | buffer | buffer | 52.41 | 62.4 |
|
||||
|
||||
#### Results: JPEG (ARM64)
|
||||
|
||||
| Module | Input | Output | Ops/sec | Speed-up |
|
||||
| :----------------- | :----- | :----- | ------: | -------: |
|
||||
| jimp | buffer | buffer | 0.88 | 1.0 |
|
||||
| squoosh-cli | file | file | 1.18 | 1.3 |
|
||||
| squoosh-lib | buffer | buffer | 1.99 | 2.3 |
|
||||
| gm | buffer | buffer | 6.06 | 6.9 |
|
||||
| gm | file | file | 10.81 | 12.3 |
|
||||
| imagemagick | file | file | 10.95 | 12.4 |
|
||||
| sharp | stream | stream | 33.15 | 37.7 |
|
||||
| sharp | file | file | 34.99 | 39.8 |
|
||||
| sharp | buffer | buffer | 36.05 | 41.0 |
|
||||
|
||||
## Task: PNG
|
||||
|
||||
Decompress a 2048x1536 RGBA PNG image,
|
||||
premultiply the alpha channel,
|
||||
resize to 720x540 using Lanczos 3 resampling (where available),
|
||||
unpremultiply then compress as PNG with a "default" zlib compression level of 6
|
||||
and without adaptive filtering.
|
||||
|
||||
Note: jimp does not support premultiply/unpremultiply.
|
||||
|
||||
### Results: PNG (AMD64)
|
||||
|
||||
| Module | Input | Output | Ops/sec | Speed-up |
|
||||
| :----------------- | :----- | :----- | ------: | -------: |
|
||||
| squoosh-cli | file | file | 0.34 | 1.0 |
|
||||
| squoosh-lib | buffer | buffer | 0.51 | 1.5 |
|
||||
| jimp | buffer | buffer | 3.59 | 10.6 |
|
||||
| gm | file | file | 8.54 | 25.1 |
|
||||
| imagemagick | file | file | 9.23 | 27.1 |
|
||||
| sharp | file | file | 25.43 | 74.8 |
|
||||
| sharp | buffer | buffer | 25.70 | 75.6 |
|
||||
|
||||
### Results: PNG (ARM64)
|
||||
|
||||
| Module | Input | Output | Ops/sec | Speed-up |
|
||||
| :----------------- | :----- | :----- | ------: | -------: |
|
||||
| squoosh-cli | file | file | 0.33 | 1.0 |
|
||||
| squoosh-lib | buffer | buffer | 0.46 | 1.4 |
|
||||
| jimp | buffer | buffer | 3.51 | 10.6 |
|
||||
| gm | file | file | 7.47 | 22.6 |
|
||||
| imagemagick | file | file | 8.06 | 24.4 |
|
||||
| sharp | file | file | 17.31 | 52.5 |
|
||||
| sharp | buffer | buffer | 17.66 | 53.5 |
|
||||
|
||||
## Running the benchmark test
|
||||
|
||||
Requires Docker.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/lovell/sharp.git
|
||||
cd sharp
|
||||
npm install
|
||||
cd test/bench
|
||||
npm install
|
||||
npm test
|
||||
cd sharp/test/bench
|
||||
./run-with-docker.sh
|
||||
```
|
||||
|
||||
2
docs/robots.txt
Normal file
2
docs/robots.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow:
|
||||
1
docs/search-index.json
Normal file
1
docs/search-index.json
Normal file
File diff suppressed because one or more lines are too long
64
docs/search-index/build.js
Normal file
64
docs/search-index/build.js
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { extractDescription, extractKeywords, extractParameters } = require('./extract');
|
||||
|
||||
const searchIndex = [];
|
||||
|
||||
// Install
|
||||
const contents = fs.readFileSync(path.join(__dirname, '..', 'install.md'), 'utf8');
|
||||
const matches = contents.matchAll(
|
||||
/## (?<title>[A-Za-z0-9 ]+)\n\n(?<body>[^#]+)/gs
|
||||
);
|
||||
for (const match of matches) {
|
||||
const { title, body } = match.groups;
|
||||
const description = extractDescription(body);
|
||||
|
||||
searchIndex.push({
|
||||
t: title,
|
||||
d: description,
|
||||
k: extractKeywords(`${title} ${description}`),
|
||||
l: `/install#${title.toLowerCase().replace(/ /g, '-')}`
|
||||
});
|
||||
}
|
||||
|
||||
// API
|
||||
[
|
||||
'constructor',
|
||||
'input',
|
||||
'output',
|
||||
'resize',
|
||||
'composite',
|
||||
'operation',
|
||||
'channel',
|
||||
'colour',
|
||||
'utility'
|
||||
].forEach((section) => {
|
||||
const contents = fs.readFileSync(path.join(__dirname, '..', `api-${section}.md`), 'utf8');
|
||||
const matches = contents.matchAll(
|
||||
/## (?<title>[A-Za-z]+)\n[^\n]+\n(?<firstparagraph>.+?)\n\n.+?(?<parameters>\| Param .+?\n\n)?\*\*Example/gs
|
||||
);
|
||||
for (const match of matches) {
|
||||
const { title, firstparagraph, parameters } = match.groups;
|
||||
const description = firstparagraph.startsWith('###')
|
||||
? 'Constructor'
|
||||
: extractDescription(firstparagraph);
|
||||
const parameterNames = parameters ? extractParameters(parameters) : '';
|
||||
|
||||
searchIndex.push({
|
||||
t: title,
|
||||
d: description,
|
||||
k: extractKeywords(`${title} ${description} ${parameterNames}`),
|
||||
l: `/api-${section}#${title.toLowerCase()}`
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '..', 'search-index.json'),
|
||||
JSON.stringify(searchIndex)
|
||||
);
|
||||
34
docs/search-index/extract.js
Normal file
34
docs/search-index/extract.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const stopWords = require('./stop-words');
|
||||
|
||||
const extractDescription = (str) =>
|
||||
str
|
||||
.replace(/### Examples.*/sg, '')
|
||||
.replace(/\(http[^)]+/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace(/[^A-Za-z0-9_/\-,. ]/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.substring(0, 200)
|
||||
.trim();
|
||||
|
||||
const extractParameters = (str) =>
|
||||
[...str.matchAll(/options\.(?<name>[^.`\] ]+)/gs)]
|
||||
.map((match) => match.groups.name)
|
||||
.map((name) => name.replace(/([A-Z])/g, ' $1').toLowerCase())
|
||||
.join(' ');
|
||||
|
||||
const extractKeywords = (str) =>
|
||||
[
|
||||
...new Set(
|
||||
str
|
||||
.split(/[ -/]/)
|
||||
.map((word) => word.toLowerCase().replace(/[^a-z]/g, ''))
|
||||
.filter((word) => word.length > 2 && word.length < 15 && !stopWords.includes(word))
|
||||
)
|
||||
].join(' ');
|
||||
|
||||
module.exports = { extractDescription, extractKeywords, extractParameters };
|
||||
135
docs/search-index/stop-words.js
Normal file
135
docs/search-index/stop-words.js
Normal file
@@ -0,0 +1,135 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = [
|
||||
'about',
|
||||
'after',
|
||||
'all',
|
||||
'allows',
|
||||
'already',
|
||||
'also',
|
||||
'alternative',
|
||||
'always',
|
||||
'and',
|
||||
'any',
|
||||
'are',
|
||||
'available',
|
||||
'based',
|
||||
'been',
|
||||
'before',
|
||||
'best',
|
||||
'both',
|
||||
'call',
|
||||
'callback',
|
||||
'can',
|
||||
'containing',
|
||||
'contains',
|
||||
'created',
|
||||
'current',
|
||||
'date',
|
||||
'default',
|
||||
'does',
|
||||
'each',
|
||||
'either',
|
||||
'ensure',
|
||||
'entirely',
|
||||
'etc',
|
||||
'every',
|
||||
'except',
|
||||
'following',
|
||||
'for',
|
||||
'from',
|
||||
'get',
|
||||
'gets',
|
||||
'given',
|
||||
'has',
|
||||
'have',
|
||||
'how',
|
||||
'image',
|
||||
'implies',
|
||||
'include',
|
||||
'including',
|
||||
'involve',
|
||||
'its',
|
||||
'last',
|
||||
'least',
|
||||
'lots',
|
||||
'make',
|
||||
'may',
|
||||
'more',
|
||||
'most',
|
||||
'much',
|
||||
'must',
|
||||
'non',
|
||||
'not',
|
||||
'now',
|
||||
'occur',
|
||||
'occurs',
|
||||
'one',
|
||||
'options',
|
||||
'other',
|
||||
'out',
|
||||
'over',
|
||||
'part',
|
||||
'perform',
|
||||
'performs',
|
||||
'please',
|
||||
'pre',
|
||||
'previously',
|
||||
'produce',
|
||||
'provide',
|
||||
'provided',
|
||||
'ready',
|
||||
'requires',
|
||||
'requiresharp',
|
||||
'returned',
|
||||
'run',
|
||||
'same',
|
||||
'see',
|
||||
'set',
|
||||
'sets',
|
||||
'sharp',
|
||||
'should',
|
||||
'since',
|
||||
'site',
|
||||
'some',
|
||||
'specified',
|
||||
'spelling',
|
||||
'such',
|
||||
'support',
|
||||
'supported',
|
||||
'sure',
|
||||
'take',
|
||||
'task',
|
||||
'than',
|
||||
'that',
|
||||
'the',
|
||||
'their',
|
||||
'then',
|
||||
'there',
|
||||
'therefore',
|
||||
'these',
|
||||
'this',
|
||||
'under',
|
||||
'unless',
|
||||
'unmaintained',
|
||||
'unsuitable',
|
||||
'until',
|
||||
'use',
|
||||
'used',
|
||||
'using',
|
||||
'value',
|
||||
'values',
|
||||
'via',
|
||||
'were',
|
||||
'when',
|
||||
'which',
|
||||
'while',
|
||||
'will',
|
||||
'with',
|
||||
'without',
|
||||
'you',
|
||||
'your'
|
||||
];
|
||||
Binary file not shown.
Binary file not shown.
41
install/check.js
Normal file
41
install/check.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
|
||||
|
||||
const buildFromSource = (msg) => {
|
||||
log(msg);
|
||||
log('Attempting to build from source via node-gyp');
|
||||
try {
|
||||
require('node-addon-api');
|
||||
log('Found node-addon-api');
|
||||
} catch (err) {
|
||||
log('Please add node-addon-api to your dependencies');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const gyp = require('node-gyp');
|
||||
log(`Found node-gyp version ${gyp().version}`);
|
||||
} catch (err) {
|
||||
log('Please add node-gyp to your dependencies');
|
||||
return;
|
||||
}
|
||||
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
||||
const status = spawnRebuild();
|
||||
if (status !== 0) {
|
||||
process.exit(status);
|
||||
}
|
||||
};
|
||||
|
||||
if (useGlobalLibvips()) {
|
||||
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
|
||||
} else if (process.env.npm_config_build_from_source) {
|
||||
buildFromSource('Detected --build-from-source flag');
|
||||
}
|
||||
} catch (err) {
|
||||
const summary = err.message.split(/\n/).slice(0, 1);
|
||||
console.log(`sharp: skipping install check: ${summary}`);
|
||||
}
|
||||
174
lib/channel.js
Normal file
174
lib/channel.js
Normal file
@@ -0,0 +1,174 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
* Boolean operations for bandbool.
|
||||
* @private
|
||||
*/
|
||||
const bool = {
|
||||
and: 'and',
|
||||
or: 'or',
|
||||
eor: 'eor'
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||
*
|
||||
* See also {@link /api-operation#flatten|flatten}.
|
||||
*
|
||||
* @example
|
||||
* sharp('rgba.png')
|
||||
* .removeAlpha()
|
||||
* .toFile('rgb.png', function(err, info) {
|
||||
* // rgb.png is a 3 channel image without an alpha channel
|
||||
* });
|
||||
*
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function removeAlpha () {
|
||||
this.options.removeAlpha = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the output image has an alpha transparency channel.
|
||||
* If missing, the added alpha channel will have the specified
|
||||
* transparency level, defaulting to fully-opaque (1).
|
||||
* This is a no-op if the image already has an alpha channel.
|
||||
*
|
||||
* @since 0.21.2
|
||||
*
|
||||
* @example
|
||||
* // rgba.png will be a 4 channel image with a fully-opaque alpha channel
|
||||
* await sharp('rgb.jpg')
|
||||
* .ensureAlpha()
|
||||
* .toFile('rgba.png')
|
||||
*
|
||||
* @example
|
||||
* // rgba is a 4 channel image with a fully-transparent alpha channel
|
||||
* const rgba = await sharp(rgb)
|
||||
* .ensureAlpha(0)
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {number} [alpha=1] - alpha transparency level (0=fully-transparent, 1=fully-opaque)
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid alpha transparency level
|
||||
*/
|
||||
function ensureAlpha (alpha) {
|
||||
if (is.defined(alpha)) {
|
||||
if (is.number(alpha) && is.inRange(alpha, 0, 1)) {
|
||||
this.options.ensureAlpha = alpha;
|
||||
} else {
|
||||
throw is.invalidParameterError('alpha', 'number between 0 and 1', alpha);
|
||||
}
|
||||
} else {
|
||||
this.options.ensureAlpha = 1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a single channel from a multi-channel image.
|
||||
*
|
||||
* @example
|
||||
* // green.jpg is a greyscale image containing the green channel of the input
|
||||
* await sharp(input)
|
||||
* .extractChannel('green')
|
||||
* .toFile('green.jpg');
|
||||
*
|
||||
* @example
|
||||
* // red1 is the red value of the first pixel, red2 the second pixel etc.
|
||||
* const [red1, red2, ...] = await sharp(input)
|
||||
* .extractChannel(0)
|
||||
* .raw()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid channel
|
||||
*/
|
||||
function extractChannel (channel) {
|
||||
const channelMap = { red: 0, green: 1, blue: 2, alpha: 3 };
|
||||
if (Object.keys(channelMap).includes(channel)) {
|
||||
channel = channelMap[channel];
|
||||
}
|
||||
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
|
||||
this.options.extractChannel = channel;
|
||||
} else {
|
||||
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join one or more channels to the image.
|
||||
* The meaning of the added channels depends on the output colourspace, set with `toColourspace()`.
|
||||
* By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||
* Channel ordering follows vips convention:
|
||||
* - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
||||
* - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
||||
*
|
||||
* Buffers may be any of the image formats supported by sharp.
|
||||
* For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
||||
*
|
||||
* @param {Array<string|Buffer>|string|Buffer} images - one or more images (file paths, Buffers).
|
||||
* @param {Object} options - image options, see `sharp()` constructor.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function joinChannel (images, options) {
|
||||
if (Array.isArray(images)) {
|
||||
images.forEach(function (image) {
|
||||
this.options.joinChannelIn.push(this._createInputDescriptor(image, options));
|
||||
}, this);
|
||||
} else {
|
||||
this.options.joinChannelIn.push(this._createInputDescriptor(images, options));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
|
||||
*
|
||||
* @example
|
||||
* sharp('3-channel-rgb-input.png')
|
||||
* .bandbool(sharp.bool.and)
|
||||
* .toFile('1-channel-output.png', function (err, info) {
|
||||
* // The output will be a single channel image where each pixel `P = R & G & B`.
|
||||
* // If `I(1,1) = [247, 170, 14] = [0b11110111, 0b10101010, 0b00001111]`
|
||||
* // then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
|
||||
* });
|
||||
*
|
||||
* @param {string} boolOp - one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function bandbool (boolOp) {
|
||||
if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
|
||||
this.options.bandBoolOp = boolOp;
|
||||
} else {
|
||||
throw is.invalidParameterError('boolOp', 'one of: and, or, eor', boolOp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with channel-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Public instance functions
|
||||
removeAlpha,
|
||||
ensureAlpha,
|
||||
extractChannel,
|
||||
joinChannel,
|
||||
bandbool
|
||||
});
|
||||
// Class attributes
|
||||
Sharp.bool = bool;
|
||||
};
|
||||
182
lib/colour.js
Normal file
182
lib/colour.js
Normal file
@@ -0,0 +1,182 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const color = require('color');
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
* Colourspaces.
|
||||
* @private
|
||||
*/
|
||||
const colourspace = {
|
||||
multiband: 'multiband',
|
||||
'b-w': 'b-w',
|
||||
bw: 'b-w',
|
||||
cmyk: 'cmyk',
|
||||
srgb: 'srgb'
|
||||
};
|
||||
|
||||
/**
|
||||
* Tint the image using the provided colour.
|
||||
* An alpha channel may be present and will be unchanged by the operation.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .tint({ r: 255, g: 240, b: 16 })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {string|Object} tint - Parsed by the [color](https://www.npmjs.org/package/color) module.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameter
|
||||
*/
|
||||
function tint (tint) {
|
||||
this._setBackgroundColourOption('tint', tint);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to 8-bit greyscale; 256 shades of grey.
|
||||
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
||||
* This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
||||
* which will produce an output image containing one color channel.
|
||||
* An alpha channel may be present, and will be unchanged by the operation.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input).greyscale().toBuffer();
|
||||
*
|
||||
* @param {Boolean} [greyscale=true]
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function greyscale (greyscale) {
|
||||
this.options.greyscale = is.bool(greyscale) ? greyscale : true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative spelling of `greyscale`.
|
||||
* @param {Boolean} [grayscale=true]
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function grayscale (grayscale) {
|
||||
return this.greyscale(grayscale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pipeline colourspace.
|
||||
*
|
||||
* The input image will be converted to the provided colourspace at the start of the pipeline.
|
||||
* All operations will use this colourspace before converting to the output colourspace,
|
||||
* as defined by {@link #tocolourspace|toColourspace}.
|
||||
*
|
||||
* This feature is experimental and has not yet been fully-tested with all operations.
|
||||
*
|
||||
* @since 0.29.0
|
||||
*
|
||||
* @example
|
||||
* // Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
|
||||
* await sharp(input)
|
||||
* .pipelineColourspace('rgb16')
|
||||
* .toColourspace('srgb')
|
||||
* .toFile('16bpc-pipeline-to-8bpc-output.png')
|
||||
*
|
||||
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774)
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function pipelineColourspace (colourspace) {
|
||||
if (!is.string(colourspace)) {
|
||||
throw is.invalidParameterError('colourspace', 'string', colourspace);
|
||||
}
|
||||
this.options.colourspaceInput = colourspace;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative spelling of `pipelineColourspace`.
|
||||
* @param {string} [colorspace] - pipeline colorspace.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function pipelineColorspace (colorspace) {
|
||||
return this.pipelineColourspace(colorspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the output colourspace.
|
||||
* By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||
*
|
||||
* @example
|
||||
* // Output 16 bits per pixel RGB
|
||||
* await sharp(input)
|
||||
* .toColourspace('rgb16')
|
||||
* .toFile('16-bpp.png')
|
||||
*
|
||||
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794)
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function toColourspace (colourspace) {
|
||||
if (!is.string(colourspace)) {
|
||||
throw is.invalidParameterError('colourspace', 'string', colourspace);
|
||||
}
|
||||
this.options.colourspace = colourspace;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative spelling of `toColourspace`.
|
||||
* @param {string} [colorspace] - output colorspace.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function toColorspace (colorspace) {
|
||||
return this.toColourspace(colorspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a colour attribute of the this.options Object.
|
||||
* @private
|
||||
* @param {string} key
|
||||
* @param {string|Object} value
|
||||
* @throws {Error} Invalid value
|
||||
*/
|
||||
function _setBackgroundColourOption (key, value) {
|
||||
if (is.defined(value)) {
|
||||
if (is.object(value) || is.string(value)) {
|
||||
const colour = color(value);
|
||||
this.options[key] = [
|
||||
colour.red(),
|
||||
colour.green(),
|
||||
colour.blue(),
|
||||
Math.round(colour.alpha() * 255)
|
||||
];
|
||||
} else {
|
||||
throw is.invalidParameterError('background', 'object or string', value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with colour-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Public
|
||||
tint,
|
||||
greyscale,
|
||||
grayscale,
|
||||
pipelineColourspace,
|
||||
pipelineColorspace,
|
||||
toColourspace,
|
||||
toColorspace,
|
||||
// Private
|
||||
_setBackgroundColourOption
|
||||
});
|
||||
// Class attributes
|
||||
Sharp.colourspace = colourspace;
|
||||
Sharp.colorspace = colourspace;
|
||||
};
|
||||
210
lib/composite.js
Normal file
210
lib/composite.js
Normal file
@@ -0,0 +1,210 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
* Blend modes.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const blend = {
|
||||
clear: 'clear',
|
||||
source: 'source',
|
||||
over: 'over',
|
||||
in: 'in',
|
||||
out: 'out',
|
||||
atop: 'atop',
|
||||
dest: 'dest',
|
||||
'dest-over': 'dest-over',
|
||||
'dest-in': 'dest-in',
|
||||
'dest-out': 'dest-out',
|
||||
'dest-atop': 'dest-atop',
|
||||
xor: 'xor',
|
||||
add: 'add',
|
||||
saturate: 'saturate',
|
||||
multiply: 'multiply',
|
||||
screen: 'screen',
|
||||
overlay: 'overlay',
|
||||
darken: 'darken',
|
||||
lighten: 'lighten',
|
||||
'colour-dodge': 'colour-dodge',
|
||||
'color-dodge': 'colour-dodge',
|
||||
'colour-burn': 'colour-burn',
|
||||
'color-burn': 'colour-burn',
|
||||
'hard-light': 'hard-light',
|
||||
'soft-light': 'soft-light',
|
||||
difference: 'difference',
|
||||
exclusion: 'exclusion'
|
||||
};
|
||||
|
||||
/**
|
||||
* Composite image(s) over the processed (resized, extracted etc.) image.
|
||||
*
|
||||
* The images to composite must be the same size or smaller than the processed image.
|
||||
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||
*
|
||||
* Any resize, rotate or extract operations in the same processing pipeline
|
||||
* will always be applied to the input image before composition.
|
||||
*
|
||||
* The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||
* `dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||
* `xor`, `add`, `saturate`, `multiply`, `screen`, `overlay`, `darken`, `lighten`,
|
||||
* `colour-dodge`, `color-dodge`, `colour-burn`,`color-burn`,
|
||||
* `hard-light`, `soft-light`, `difference`, `exclusion`.
|
||||
*
|
||||
* More information about blend modes can be found at
|
||||
* https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode
|
||||
* and https://www.cairographics.org/operators/
|
||||
*
|
||||
* @since 0.22.0
|
||||
*
|
||||
* @example
|
||||
* await sharp(background)
|
||||
* .composite([
|
||||
* { input: layer1, gravity: 'northwest' },
|
||||
* { input: layer2, gravity: 'southeast' },
|
||||
* ])
|
||||
* .toFile('combined.png');
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp('input.gif', { animated: true })
|
||||
* .composite([
|
||||
* { input: 'overlay.png', tile: true, blend: 'saturate' }
|
||||
* ])
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* sharp('input.png')
|
||||
* .rotate(180)
|
||||
* .resize(300)
|
||||
* .flatten( { background: '#ff6600' } )
|
||||
* .composite([{ input: 'overlay.png', gravity: 'southeast' }])
|
||||
* .sharpen()
|
||||
* .withMetadata()
|
||||
* .webp( { quality: 90 } )
|
||||
* .toBuffer()
|
||||
* .then(function(outputBuffer) {
|
||||
* // outputBuffer contains upside down, 300px wide, alpha channel flattened
|
||||
* // onto orange background, composited with overlay.png with SE gravity,
|
||||
* // sharpened, with metadata, 90% quality WebP image data. Phew!
|
||||
* });
|
||||
*
|
||||
* @param {Object[]} images - Ordered list of images to composite
|
||||
* @param {Buffer|String} [images[].input] - Buffer containing image data, String containing the path to an image file, or Create object (see below)
|
||||
* @param {Object} [images[].input.create] - describes a blank overlay to be created.
|
||||
* @param {Number} [images[].input.create.width]
|
||||
* @param {Number} [images[].input.create.height]
|
||||
* @param {Number} [images[].input.create.channels] - 3-4
|
||||
* @param {String|Object} [images[].input.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||
* @param {Object} [images[].input.text] - describes a new text image to be created.
|
||||
* @param {string} [images[].input.text.text] - text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
|
||||
* @param {string} [images[].input.text.font] - font name to render with.
|
||||
* @param {string} [images[].input.text.fontfile] - absolute filesystem path to a font file that can be used by `font`.
|
||||
* @param {number} [images[].input.text.width=0] - integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries.
|
||||
* @param {number} [images[].input.text.height=0] - integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0.
|
||||
* @param {string} [images[].input.text.align='left'] - text alignment (`'left'`, `'centre'`, `'center'`, `'right'`).
|
||||
* @param {boolean} [images[].input.text.justify=false] - set this to true to apply justification to the text.
|
||||
* @param {number} [images[].input.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
||||
* @param {boolean} [images[].input.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`.
|
||||
* @param {number} [images[].input.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
||||
* @param {String} [images[].blend='over'] - how to blend this image with the image below.
|
||||
* @param {String} [images[].gravity='centre'] - gravity at which to place the overlay.
|
||||
* @param {Number} [images[].top] - the pixel offset from the top edge.
|
||||
* @param {Number} [images[].left] - the pixel offset from the left edge.
|
||||
* @param {Boolean} [images[].tile=false] - set to true to repeat the overlay image across the entire image with the given `gravity`.
|
||||
* @param {Boolean} [images[].premultiplied=false] - set to true to avoid premultiplying the image below. Equivalent to the `--premultiplied` vips option.
|
||||
* @param {Number} [images[].density=72] - number representing the DPI for vector overlay image.
|
||||
* @param {Object} [images[].raw] - describes overlay when using raw pixel data.
|
||||
* @param {Number} [images[].raw.width]
|
||||
* @param {Number} [images[].raw.height]
|
||||
* @param {Number} [images[].raw.channels]
|
||||
* @param {boolean} [images[].animated=false] - Set to `true` to read all frames/pages of an animated image.
|
||||
* @param {string} [images[].failOn='warning'] - @see {@link /api-constructor#parameters|constructor parameters}
|
||||
* @param {number|boolean} [images[].limitInputPixels=268402689] - @see {@link /api-constructor#parameters|constructor parameters}
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function composite (images) {
|
||||
if (!Array.isArray(images)) {
|
||||
throw is.invalidParameterError('images to composite', 'array', images);
|
||||
}
|
||||
this.options.composite = images.map(image => {
|
||||
if (!is.object(image)) {
|
||||
throw is.invalidParameterError('image to composite', 'object', image);
|
||||
}
|
||||
const inputOptions = this._inputOptionsFromObject(image);
|
||||
const composite = {
|
||||
input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }),
|
||||
blend: 'over',
|
||||
tile: false,
|
||||
left: 0,
|
||||
top: 0,
|
||||
hasOffset: false,
|
||||
gravity: 0,
|
||||
premultiplied: false
|
||||
};
|
||||
if (is.defined(image.blend)) {
|
||||
if (is.string(blend[image.blend])) {
|
||||
composite.blend = blend[image.blend];
|
||||
} else {
|
||||
throw is.invalidParameterError('blend', 'valid blend name', image.blend);
|
||||
}
|
||||
}
|
||||
if (is.defined(image.tile)) {
|
||||
if (is.bool(image.tile)) {
|
||||
composite.tile = image.tile;
|
||||
} else {
|
||||
throw is.invalidParameterError('tile', 'boolean', image.tile);
|
||||
}
|
||||
}
|
||||
if (is.defined(image.left)) {
|
||||
if (is.integer(image.left)) {
|
||||
composite.left = image.left;
|
||||
} else {
|
||||
throw is.invalidParameterError('left', 'integer', image.left);
|
||||
}
|
||||
}
|
||||
if (is.defined(image.top)) {
|
||||
if (is.integer(image.top)) {
|
||||
composite.top = image.top;
|
||||
} else {
|
||||
throw is.invalidParameterError('top', 'integer', image.top);
|
||||
}
|
||||
}
|
||||
if (is.defined(image.top) !== is.defined(image.left)) {
|
||||
throw new Error('Expected both left and top to be set');
|
||||
} else {
|
||||
composite.hasOffset = is.integer(image.top) && is.integer(image.left);
|
||||
}
|
||||
if (is.defined(image.gravity)) {
|
||||
if (is.integer(image.gravity) && is.inRange(image.gravity, 0, 8)) {
|
||||
composite.gravity = image.gravity;
|
||||
} else if (is.string(image.gravity) && is.integer(this.constructor.gravity[image.gravity])) {
|
||||
composite.gravity = this.constructor.gravity[image.gravity];
|
||||
} else {
|
||||
throw is.invalidParameterError('gravity', 'valid gravity', image.gravity);
|
||||
}
|
||||
}
|
||||
if (is.defined(image.premultiplied)) {
|
||||
if (is.bool(image.premultiplied)) {
|
||||
composite.premultiplied = image.premultiplied;
|
||||
} else {
|
||||
throw is.invalidParameterError('premultiplied', 'boolean', image.premultiplied);
|
||||
}
|
||||
}
|
||||
return composite;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with composite-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Sharp.prototype.composite = composite;
|
||||
Sharp.blend = blend;
|
||||
};
|
||||
444
lib/constructor.js
Normal file
444
lib/constructor.js
Normal file
@@ -0,0 +1,444 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const util = require('node:util');
|
||||
const stream = require('node:stream');
|
||||
const is = require('./is');
|
||||
|
||||
require('./sharp');
|
||||
|
||||
// Use NODE_DEBUG=sharp to enable libvips warnings
|
||||
const debuglog = util.debuglog('sharp');
|
||||
|
||||
/**
|
||||
* Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
||||
*
|
||||
* JPEG, PNG, WebP, GIF, AVIF or TIFF format image data can be streamed out from this object.
|
||||
* When using Stream based output, derived attributes are available from the `info` event.
|
||||
*
|
||||
* Non-critical problems encountered during processing are emitted as `warning` events.
|
||||
*
|
||||
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||
*
|
||||
* When loading more than one page/frame of an animated image,
|
||||
* these are combined as a vertically-stacked "toilet roll" image
|
||||
* where the overall height is the `pageHeight` multiplied by the number of `pages`.
|
||||
*
|
||||
* @constructs Sharp
|
||||
*
|
||||
* @emits Sharp#info
|
||||
* @emits Sharp#warning
|
||||
*
|
||||
* @example
|
||||
* sharp('input.jpg')
|
||||
* .resize(300, 200)
|
||||
* .toFile('output.jpg', function(err) {
|
||||
* // output.jpg is a 300 pixels wide and 200 pixels high image
|
||||
* // containing a scaled and cropped version of input.jpg
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* // Read image data from readableStream,
|
||||
* // resize to 300 pixels wide,
|
||||
* // emit an 'info' event with calculated dimensions
|
||||
* // and finally write image data to writableStream
|
||||
* var transformer = sharp()
|
||||
* .resize(300)
|
||||
* .on('info', function(info) {
|
||||
* console.log('Image height is ' + info.height);
|
||||
* });
|
||||
* readableStream.pipe(transformer).pipe(writableStream);
|
||||
*
|
||||
* @example
|
||||
* // Create a blank 300x200 PNG image of semi-translucent red pixels
|
||||
* sharp({
|
||||
* create: {
|
||||
* width: 300,
|
||||
* height: 200,
|
||||
* channels: 4,
|
||||
* background: { r: 255, g: 0, b: 0, alpha: 0.5 }
|
||||
* }
|
||||
* })
|
||||
* .png()
|
||||
* .toBuffer()
|
||||
* .then( ... );
|
||||
*
|
||||
* @example
|
||||
* // Convert an animated GIF to an animated WebP
|
||||
* await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||
*
|
||||
* @example
|
||||
* // Read a raw array of pixels and save it to a png
|
||||
* const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
|
||||
* const image = sharp(input, {
|
||||
* // because the input does not contain its dimensions or how many channels it has
|
||||
* // we need to specify it in the constructor options
|
||||
* raw: {
|
||||
* width: 2,
|
||||
* height: 1,
|
||||
* channels: 3
|
||||
* }
|
||||
* });
|
||||
* await image.toFile('my-two-pixels.png');
|
||||
*
|
||||
* @example
|
||||
* // Generate RGB Gaussian noise
|
||||
* await sharp({
|
||||
* create: {
|
||||
* width: 300,
|
||||
* height: 200,
|
||||
* channels: 3,
|
||||
* noise: {
|
||||
* type: 'gaussian',
|
||||
* mean: 128,
|
||||
* sigma: 30
|
||||
* }
|
||||
* }
|
||||
* }).toFile('noise.png');
|
||||
*
|
||||
* @example
|
||||
* // Generate an image from text
|
||||
* await sharp({
|
||||
* text: {
|
||||
* text: 'Hello, world!',
|
||||
* width: 400, // max width
|
||||
* height: 300 // max height
|
||||
* }
|
||||
* }).toFile('text_bw.png');
|
||||
*
|
||||
* @example
|
||||
* // Generate an rgba image from text using pango markup and font
|
||||
* await sharp({
|
||||
* text: {
|
||||
* text: '<span foreground="red">Red!</span><span background="cyan">blue</span>',
|
||||
* font: 'sans',
|
||||
* rgba: true,
|
||||
* dpi: 300
|
||||
* }
|
||||
* }).toFile('text_rgba.png');
|
||||
*
|
||||
* @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string)} [input] - if present, can be
|
||||
* a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
|
||||
* a TypedArray containing raw pixel image data, or
|
||||
* a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
|
||||
* JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||
* @param {string} [options.failOn='warning'] - When to abort processing of invalid pixel data, one of (in order of sensitivity, least to most): 'none', 'truncated', 'error', 'warning'. Higher levels imply lower levels. Invalid metadata will always abort.
|
||||
* @param {number|boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
|
||||
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
||||
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
|
||||
* @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
|
||||
* @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
|
||||
* @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
|
||||
* @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
|
||||
* @param {number} [options.pages=1] - Number of pages to extract for multi-page input (GIF, WebP, TIFF), use -1 for all pages.
|
||||
* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
|
||||
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
|
||||
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
|
||||
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
|
||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||
* @param {number} [options.raw.width] - integral number of pixels wide.
|
||||
* @param {number} [options.raw.height] - integral number of pixels high.
|
||||
* @param {number} [options.raw.channels] - integral number of channels, between 1 and 4.
|
||||
* @param {boolean} [options.raw.premultiplied] - specifies that the raw input has already been premultiplied, set to `true`
|
||||
* to avoid sharp premultiplying the image. (optional, default `false`)
|
||||
* @param {Object} [options.create] - describes a new image to be created.
|
||||
* @param {number} [options.create.width] - integral number of pixels wide.
|
||||
* @param {number} [options.create.height] - integral number of pixels high.
|
||||
* @param {number} [options.create.channels] - integral number of channels, either 3 (RGB) or 4 (RGBA).
|
||||
* @param {string|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||
* @param {Object} [options.create.noise] - describes a noise to be created.
|
||||
* @param {string} [options.create.noise.type] - type of generated noise, currently only `gaussian` is supported.
|
||||
* @param {number} [options.create.noise.mean] - mean of pixels in generated noise.
|
||||
* @param {number} [options.create.noise.sigma] - standard deviation of pixels in generated noise.
|
||||
* @param {Object} [options.text] - describes a new text image to be created.
|
||||
* @param {string} [options.text.text] - text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
|
||||
* @param {string} [options.text.font] - font name to render with.
|
||||
* @param {string} [options.text.fontfile] - absolute filesystem path to a font file that can be used by `font`.
|
||||
* @param {number} [options.text.width=0] - Integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries.
|
||||
* @param {number} [options.text.height=0] - Maximum integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0.
|
||||
* @param {string} [options.text.align='left'] - Alignment style for multi-line text (`'left'`, `'centre'`, `'center'`, `'right'`).
|
||||
* @param {boolean} [options.text.justify=false] - set this to true to apply justification to the text.
|
||||
* @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
||||
* @param {boolean} [options.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`.
|
||||
* @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
||||
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
const Sharp = function (input, options) {
|
||||
if (arguments.length === 1 && !is.defined(input)) {
|
||||
throw new Error('Invalid input');
|
||||
}
|
||||
if (!(this instanceof Sharp)) {
|
||||
return new Sharp(input, options);
|
||||
}
|
||||
stream.Duplex.call(this);
|
||||
this.options = {
|
||||
// resize options
|
||||
topOffsetPre: -1,
|
||||
leftOffsetPre: -1,
|
||||
widthPre: -1,
|
||||
heightPre: -1,
|
||||
topOffsetPost: -1,
|
||||
leftOffsetPost: -1,
|
||||
widthPost: -1,
|
||||
heightPost: -1,
|
||||
width: -1,
|
||||
height: -1,
|
||||
canvas: 'crop',
|
||||
position: 0,
|
||||
resizeBackground: [0, 0, 0, 255],
|
||||
useExifOrientation: false,
|
||||
angle: 0,
|
||||
rotationAngle: 0,
|
||||
rotationBackground: [0, 0, 0, 255],
|
||||
rotateBeforePreExtract: false,
|
||||
flip: false,
|
||||
flop: false,
|
||||
extendTop: 0,
|
||||
extendBottom: 0,
|
||||
extendLeft: 0,
|
||||
extendRight: 0,
|
||||
extendBackground: [0, 0, 0, 255],
|
||||
extendWith: 'background',
|
||||
withoutEnlargement: false,
|
||||
withoutReduction: false,
|
||||
affineMatrix: [],
|
||||
affineBackground: [0, 0, 0, 255],
|
||||
affineIdx: 0,
|
||||
affineIdy: 0,
|
||||
affineOdx: 0,
|
||||
affineOdy: 0,
|
||||
affineInterpolator: this.constructor.interpolators.bilinear,
|
||||
kernel: 'lanczos3',
|
||||
fastShrinkOnLoad: true,
|
||||
// operations
|
||||
tint: [-1, 0, 0, 0],
|
||||
flatten: false,
|
||||
flattenBackground: [0, 0, 0],
|
||||
unflatten: false,
|
||||
negate: false,
|
||||
negateAlpha: true,
|
||||
medianSize: 0,
|
||||
blurSigma: 0,
|
||||
sharpenSigma: 0,
|
||||
sharpenM1: 1,
|
||||
sharpenM2: 2,
|
||||
sharpenX1: 2,
|
||||
sharpenY2: 10,
|
||||
sharpenY3: 20,
|
||||
threshold: 0,
|
||||
thresholdGrayscale: true,
|
||||
trimBackground: [],
|
||||
trimThreshold: -1,
|
||||
trimLineArt: false,
|
||||
gamma: 0,
|
||||
gammaOut: 0,
|
||||
greyscale: false,
|
||||
normalise: false,
|
||||
normaliseLower: 1,
|
||||
normaliseUpper: 99,
|
||||
claheWidth: 0,
|
||||
claheHeight: 0,
|
||||
claheMaxSlope: 3,
|
||||
brightness: 1,
|
||||
saturation: 1,
|
||||
hue: 0,
|
||||
lightness: 0,
|
||||
booleanBufferIn: null,
|
||||
booleanFileIn: '',
|
||||
joinChannelIn: [],
|
||||
extractChannel: -1,
|
||||
removeAlpha: false,
|
||||
ensureAlpha: -1,
|
||||
colourspace: 'srgb',
|
||||
colourspaceInput: 'last',
|
||||
composite: [],
|
||||
// output
|
||||
fileOut: '',
|
||||
formatOut: 'input',
|
||||
streamOut: false,
|
||||
keepMetadata: 0,
|
||||
withMetadataOrientation: -1,
|
||||
withMetadataDensity: 0,
|
||||
withIccProfile: '',
|
||||
withExif: {},
|
||||
withExifMerge: true,
|
||||
resolveWithObject: false,
|
||||
// output format
|
||||
jpegQuality: 80,
|
||||
jpegProgressive: false,
|
||||
jpegChromaSubsampling: '4:2:0',
|
||||
jpegTrellisQuantisation: false,
|
||||
jpegOvershootDeringing: false,
|
||||
jpegOptimiseScans: false,
|
||||
jpegOptimiseCoding: true,
|
||||
jpegQuantisationTable: 0,
|
||||
pngProgressive: false,
|
||||
pngCompressionLevel: 6,
|
||||
pngAdaptiveFiltering: false,
|
||||
pngPalette: false,
|
||||
pngQuality: 100,
|
||||
pngEffort: 7,
|
||||
pngBitdepth: 8,
|
||||
pngDither: 1,
|
||||
jp2Quality: 80,
|
||||
jp2TileHeight: 512,
|
||||
jp2TileWidth: 512,
|
||||
jp2Lossless: false,
|
||||
jp2ChromaSubsampling: '4:4:4',
|
||||
webpQuality: 80,
|
||||
webpAlphaQuality: 100,
|
||||
webpLossless: false,
|
||||
webpNearLossless: false,
|
||||
webpSmartSubsample: false,
|
||||
webpPreset: 'default',
|
||||
webpEffort: 4,
|
||||
webpMinSize: false,
|
||||
webpMixed: false,
|
||||
gifBitdepth: 8,
|
||||
gifEffort: 7,
|
||||
gifDither: 1,
|
||||
gifInterFrameMaxError: 0,
|
||||
gifInterPaletteMaxError: 3,
|
||||
gifReuse: true,
|
||||
gifProgressive: false,
|
||||
tiffQuality: 80,
|
||||
tiffCompression: 'jpeg',
|
||||
tiffPredictor: 'horizontal',
|
||||
tiffPyramid: false,
|
||||
tiffMiniswhite: false,
|
||||
tiffBitdepth: 8,
|
||||
tiffTile: false,
|
||||
tiffTileHeight: 256,
|
||||
tiffTileWidth: 256,
|
||||
tiffXres: 1.0,
|
||||
tiffYres: 1.0,
|
||||
tiffResolutionUnit: 'inch',
|
||||
heifQuality: 50,
|
||||
heifLossless: false,
|
||||
heifCompression: 'av1',
|
||||
heifEffort: 4,
|
||||
heifChromaSubsampling: '4:4:4',
|
||||
jxlDistance: 1,
|
||||
jxlDecodingTier: 0,
|
||||
jxlEffort: 7,
|
||||
jxlLossless: false,
|
||||
rawDepth: 'uchar',
|
||||
tileSize: 256,
|
||||
tileOverlap: 0,
|
||||
tileContainer: 'fs',
|
||||
tileLayout: 'dz',
|
||||
tileFormat: 'last',
|
||||
tileDepth: 'last',
|
||||
tileAngle: 0,
|
||||
tileSkipBlanks: -1,
|
||||
tileBackground: [255, 255, 255, 255],
|
||||
tileCentre: false,
|
||||
tileId: 'https://example.com/iiif',
|
||||
tileBasename: '',
|
||||
timeoutSeconds: 0,
|
||||
linearA: [],
|
||||
linearB: [],
|
||||
// Function to notify of libvips warnings
|
||||
debuglog: warning => {
|
||||
this.emit('warning', warning);
|
||||
debuglog(warning);
|
||||
},
|
||||
// Function to notify of queue length changes
|
||||
queueListener: function (queueLength) {
|
||||
Sharp.queue.emit('change', queueLength);
|
||||
}
|
||||
};
|
||||
this.options.input = this._createInputDescriptor(input, options, { allowStream: true });
|
||||
return this;
|
||||
};
|
||||
Object.setPrototypeOf(Sharp.prototype, stream.Duplex.prototype);
|
||||
Object.setPrototypeOf(Sharp, stream.Duplex);
|
||||
|
||||
/**
|
||||
* Take a "snapshot" of the Sharp instance, returning a new instance.
|
||||
* Cloned instances inherit the input of their parent instance.
|
||||
* This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
|
||||
*
|
||||
* @example
|
||||
* const pipeline = sharp().rotate();
|
||||
* pipeline.clone().resize(800, 600).pipe(firstWritableStream);
|
||||
* pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
|
||||
* readableStream.pipe(pipeline);
|
||||
* // firstWritableStream receives auto-rotated, resized readableStream
|
||||
* // secondWritableStream receives auto-rotated, extracted region of readableStream
|
||||
*
|
||||
* @example
|
||||
* // Create a pipeline that will download an image, resize it and format it to different files
|
||||
* // Using Promises to know when the pipeline is complete
|
||||
* const fs = require("fs");
|
||||
* const got = require("got");
|
||||
* const sharpStream = sharp({ failOn: 'none' });
|
||||
*
|
||||
* const promises = [];
|
||||
*
|
||||
* promises.push(
|
||||
* sharpStream
|
||||
* .clone()
|
||||
* .jpeg({ quality: 100 })
|
||||
* .toFile("originalFile.jpg")
|
||||
* );
|
||||
*
|
||||
* promises.push(
|
||||
* sharpStream
|
||||
* .clone()
|
||||
* .resize({ width: 500 })
|
||||
* .jpeg({ quality: 80 })
|
||||
* .toFile("optimized-500.jpg")
|
||||
* );
|
||||
*
|
||||
* promises.push(
|
||||
* sharpStream
|
||||
* .clone()
|
||||
* .resize({ width: 500 })
|
||||
* .webp({ quality: 80 })
|
||||
* .toFile("optimized-500.webp")
|
||||
* );
|
||||
*
|
||||
* // https://github.com/sindresorhus/got/blob/main/documentation/3-streams.md
|
||||
* got.stream("https://www.example.com/some-file.jpg").pipe(sharpStream);
|
||||
*
|
||||
* Promise.all(promises)
|
||||
* .then(res => { console.log("Done!", res); })
|
||||
* .catch(err => {
|
||||
* console.error("Error processing files, let's clean it up", err);
|
||||
* try {
|
||||
* fs.unlinkSync("originalFile.jpg");
|
||||
* fs.unlinkSync("optimized-500.jpg");
|
||||
* fs.unlinkSync("optimized-500.webp");
|
||||
* } catch (e) {}
|
||||
* });
|
||||
*
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function clone () {
|
||||
// Clone existing options
|
||||
const clone = this.constructor.call();
|
||||
clone.options = Object.assign({}, this.options);
|
||||
// Pass 'finish' event to clone for Stream-based input
|
||||
if (this._isStreamInput()) {
|
||||
this.on('finish', () => {
|
||||
// Clone inherits input data
|
||||
this._flattenBufferIn();
|
||||
clone.options.bufferIn = this.options.bufferIn;
|
||||
clone.emit('finish');
|
||||
});
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
Object.assign(Sharp.prototype, { clone });
|
||||
|
||||
/**
|
||||
* Export constructor.
|
||||
* @private
|
||||
*/
|
||||
module.exports = Sharp;
|
||||
1723
lib/index.d.ts
vendored
Normal file
1723
lib/index.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
16
lib/index.js
Normal file
16
lib/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const Sharp = require('./constructor');
|
||||
require('./input')(Sharp);
|
||||
require('./resize')(Sharp);
|
||||
require('./composite')(Sharp);
|
||||
require('./operation')(Sharp);
|
||||
require('./colour')(Sharp);
|
||||
require('./channel')(Sharp);
|
||||
require('./output')(Sharp);
|
||||
require('./utility')(Sharp);
|
||||
|
||||
module.exports = Sharp;
|
||||
657
lib/input.js
Normal file
657
lib/input.js
Normal file
@@ -0,0 +1,657 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const color = require('color');
|
||||
const is = require('./is');
|
||||
const sharp = require('./sharp');
|
||||
|
||||
/**
|
||||
* Justication alignment
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const align = {
|
||||
left: 'low',
|
||||
center: 'centre',
|
||||
centre: 'centre',
|
||||
right: 'high'
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract input options, if any, from an object.
|
||||
* @private
|
||||
*/
|
||||
function _inputOptionsFromObject (obj) {
|
||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd } = obj;
|
||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd].some(is.defined)
|
||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Object containing input and input-related options.
|
||||
* @private
|
||||
*/
|
||||
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
const inputDescriptor = {
|
||||
failOn: 'warning',
|
||||
limitInputPixels: Math.pow(0x3FFF, 2),
|
||||
ignoreIcc: false,
|
||||
unlimited: false,
|
||||
sequentialRead: true
|
||||
};
|
||||
if (is.string(input)) {
|
||||
// filesystem
|
||||
inputDescriptor.file = input;
|
||||
} else if (is.buffer(input)) {
|
||||
// Buffer
|
||||
if (input.length === 0) {
|
||||
throw Error('Input Buffer is empty');
|
||||
}
|
||||
inputDescriptor.buffer = input;
|
||||
} else if (is.arrayBuffer(input)) {
|
||||
if (input.byteLength === 0) {
|
||||
throw Error('Input bit Array is empty');
|
||||
}
|
||||
inputDescriptor.buffer = Buffer.from(input, 0, input.byteLength);
|
||||
} else if (is.typedArray(input)) {
|
||||
if (input.length === 0) {
|
||||
throw Error('Input Bit Array is empty');
|
||||
}
|
||||
inputDescriptor.buffer = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
||||
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
||||
// Plain Object descriptor, e.g. create
|
||||
inputOptions = input;
|
||||
if (_inputOptionsFromObject(inputOptions)) {
|
||||
// Stream with options
|
||||
inputDescriptor.buffer = [];
|
||||
}
|
||||
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
|
||||
// Stream without options
|
||||
inputDescriptor.buffer = [];
|
||||
} else {
|
||||
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
|
||||
is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : ''
|
||||
}`);
|
||||
}
|
||||
if (is.object(inputOptions)) {
|
||||
// Deprecated: failOnError
|
||||
if (is.defined(inputOptions.failOnError)) {
|
||||
if (is.bool(inputOptions.failOnError)) {
|
||||
inputDescriptor.failOn = inputOptions.failOnError ? 'warning' : 'none';
|
||||
} else {
|
||||
throw is.invalidParameterError('failOnError', 'boolean', inputOptions.failOnError);
|
||||
}
|
||||
}
|
||||
// failOn
|
||||
if (is.defined(inputOptions.failOn)) {
|
||||
if (is.string(inputOptions.failOn) && is.inArray(inputOptions.failOn, ['none', 'truncated', 'error', 'warning'])) {
|
||||
inputDescriptor.failOn = inputOptions.failOn;
|
||||
} else {
|
||||
throw is.invalidParameterError('failOn', 'one of: none, truncated, error, warning', inputOptions.failOn);
|
||||
}
|
||||
}
|
||||
// Density
|
||||
if (is.defined(inputOptions.density)) {
|
||||
if (is.inRange(inputOptions.density, 1, 100000)) {
|
||||
inputDescriptor.density = inputOptions.density;
|
||||
} else {
|
||||
throw is.invalidParameterError('density', 'number between 1 and 100000', inputOptions.density);
|
||||
}
|
||||
}
|
||||
// Ignore embeddded ICC profile
|
||||
if (is.defined(inputOptions.ignoreIcc)) {
|
||||
if (is.bool(inputOptions.ignoreIcc)) {
|
||||
inputDescriptor.ignoreIcc = inputOptions.ignoreIcc;
|
||||
} else {
|
||||
throw is.invalidParameterError('ignoreIcc', 'boolean', inputOptions.ignoreIcc);
|
||||
}
|
||||
}
|
||||
// limitInputPixels
|
||||
if (is.defined(inputOptions.limitInputPixels)) {
|
||||
if (is.bool(inputOptions.limitInputPixels)) {
|
||||
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels
|
||||
? Math.pow(0x3FFF, 2)
|
||||
: 0;
|
||||
} else if (is.integer(inputOptions.limitInputPixels) && is.inRange(inputOptions.limitInputPixels, 0, Number.MAX_SAFE_INTEGER)) {
|
||||
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels;
|
||||
} else {
|
||||
throw is.invalidParameterError('limitInputPixels', 'positive integer', inputOptions.limitInputPixels);
|
||||
}
|
||||
}
|
||||
// unlimited
|
||||
if (is.defined(inputOptions.unlimited)) {
|
||||
if (is.bool(inputOptions.unlimited)) {
|
||||
inputDescriptor.unlimited = inputOptions.unlimited;
|
||||
} else {
|
||||
throw is.invalidParameterError('unlimited', 'boolean', inputOptions.unlimited);
|
||||
}
|
||||
}
|
||||
// sequentialRead
|
||||
if (is.defined(inputOptions.sequentialRead)) {
|
||||
if (is.bool(inputOptions.sequentialRead)) {
|
||||
inputDescriptor.sequentialRead = inputOptions.sequentialRead;
|
||||
} else {
|
||||
throw is.invalidParameterError('sequentialRead', 'boolean', inputOptions.sequentialRead);
|
||||
}
|
||||
}
|
||||
// Raw pixel input
|
||||
if (is.defined(inputOptions.raw)) {
|
||||
if (
|
||||
is.object(inputOptions.raw) &&
|
||||
is.integer(inputOptions.raw.width) && inputOptions.raw.width > 0 &&
|
||||
is.integer(inputOptions.raw.height) && inputOptions.raw.height > 0 &&
|
||||
is.integer(inputOptions.raw.channels) && is.inRange(inputOptions.raw.channels, 1, 4)
|
||||
) {
|
||||
inputDescriptor.rawWidth = inputOptions.raw.width;
|
||||
inputDescriptor.rawHeight = inputOptions.raw.height;
|
||||
inputDescriptor.rawChannels = inputOptions.raw.channels;
|
||||
inputDescriptor.rawPremultiplied = !!inputOptions.raw.premultiplied;
|
||||
|
||||
switch (input.constructor) {
|
||||
case Uint8Array:
|
||||
case Uint8ClampedArray:
|
||||
inputDescriptor.rawDepth = 'uchar';
|
||||
break;
|
||||
case Int8Array:
|
||||
inputDescriptor.rawDepth = 'char';
|
||||
break;
|
||||
case Uint16Array:
|
||||
inputDescriptor.rawDepth = 'ushort';
|
||||
break;
|
||||
case Int16Array:
|
||||
inputDescriptor.rawDepth = 'short';
|
||||
break;
|
||||
case Uint32Array:
|
||||
inputDescriptor.rawDepth = 'uint';
|
||||
break;
|
||||
case Int32Array:
|
||||
inputDescriptor.rawDepth = 'int';
|
||||
break;
|
||||
case Float32Array:
|
||||
inputDescriptor.rawDepth = 'float';
|
||||
break;
|
||||
case Float64Array:
|
||||
inputDescriptor.rawDepth = 'double';
|
||||
break;
|
||||
default:
|
||||
inputDescriptor.rawDepth = 'uchar';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
throw new Error('Expected width, height and channels for raw pixel input');
|
||||
}
|
||||
}
|
||||
// Multi-page input (GIF, TIFF, PDF)
|
||||
if (is.defined(inputOptions.animated)) {
|
||||
if (is.bool(inputOptions.animated)) {
|
||||
inputDescriptor.pages = inputOptions.animated ? -1 : 1;
|
||||
} else {
|
||||
throw is.invalidParameterError('animated', 'boolean', inputOptions.animated);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.pages)) {
|
||||
if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {
|
||||
inputDescriptor.pages = inputOptions.pages;
|
||||
} else {
|
||||
throw is.invalidParameterError('pages', 'integer between -1 and 100000', inputOptions.pages);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.page)) {
|
||||
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
||||
inputDescriptor.page = inputOptions.page;
|
||||
} else {
|
||||
throw is.invalidParameterError('page', 'integer between 0 and 100000', inputOptions.page);
|
||||
}
|
||||
}
|
||||
// Multi-level input (OpenSlide)
|
||||
if (is.defined(inputOptions.level)) {
|
||||
if (is.integer(inputOptions.level) && is.inRange(inputOptions.level, 0, 256)) {
|
||||
inputDescriptor.level = inputOptions.level;
|
||||
} else {
|
||||
throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);
|
||||
}
|
||||
}
|
||||
// Sub Image File Directory (TIFF)
|
||||
if (is.defined(inputOptions.subifd)) {
|
||||
if (is.integer(inputOptions.subifd) && is.inRange(inputOptions.subifd, -1, 100000)) {
|
||||
inputDescriptor.subifd = inputOptions.subifd;
|
||||
} else {
|
||||
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
|
||||
}
|
||||
}
|
||||
// Create new image
|
||||
if (is.defined(inputOptions.create)) {
|
||||
if (
|
||||
is.object(inputOptions.create) &&
|
||||
is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
|
||||
is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
|
||||
is.integer(inputOptions.create.channels)
|
||||
) {
|
||||
inputDescriptor.createWidth = inputOptions.create.width;
|
||||
inputDescriptor.createHeight = inputOptions.create.height;
|
||||
inputDescriptor.createChannels = inputOptions.create.channels;
|
||||
// Noise
|
||||
if (is.defined(inputOptions.create.noise)) {
|
||||
if (!is.object(inputOptions.create.noise)) {
|
||||
throw new Error('Expected noise to be an object');
|
||||
}
|
||||
if (!is.inArray(inputOptions.create.noise.type, ['gaussian'])) {
|
||||
throw new Error('Only gaussian noise is supported at the moment');
|
||||
}
|
||||
if (!is.inRange(inputOptions.create.channels, 1, 4)) {
|
||||
throw is.invalidParameterError('create.channels', 'number between 1 and 4', inputOptions.create.channels);
|
||||
}
|
||||
inputDescriptor.createNoiseType = inputOptions.create.noise.type;
|
||||
if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {
|
||||
inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;
|
||||
} else {
|
||||
throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);
|
||||
}
|
||||
if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {
|
||||
inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;
|
||||
} else {
|
||||
throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);
|
||||
}
|
||||
} else if (is.defined(inputOptions.create.background)) {
|
||||
if (!is.inRange(inputOptions.create.channels, 3, 4)) {
|
||||
throw is.invalidParameterError('create.channels', 'number between 3 and 4', inputOptions.create.channels);
|
||||
}
|
||||
const background = color(inputOptions.create.background);
|
||||
inputDescriptor.createBackground = [
|
||||
background.red(),
|
||||
background.green(),
|
||||
background.blue(),
|
||||
Math.round(background.alpha() * 255)
|
||||
];
|
||||
} else {
|
||||
throw new Error('Expected valid noise or background to create a new input image');
|
||||
}
|
||||
delete inputDescriptor.buffer;
|
||||
} else {
|
||||
throw new Error('Expected valid width, height and channels to create a new input image');
|
||||
}
|
||||
}
|
||||
// Create a new image with text
|
||||
if (is.defined(inputOptions.text)) {
|
||||
if (is.object(inputOptions.text) && is.string(inputOptions.text.text)) {
|
||||
inputDescriptor.textValue = inputOptions.text.text;
|
||||
if (is.defined(inputOptions.text.height) && is.defined(inputOptions.text.dpi)) {
|
||||
throw new Error('Expected only one of dpi or height');
|
||||
}
|
||||
if (is.defined(inputOptions.text.font)) {
|
||||
if (is.string(inputOptions.text.font)) {
|
||||
inputDescriptor.textFont = inputOptions.text.font;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.font', 'string', inputOptions.text.font);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.fontfile)) {
|
||||
if (is.string(inputOptions.text.fontfile)) {
|
||||
inputDescriptor.textFontfile = inputOptions.text.fontfile;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.fontfile', 'string', inputOptions.text.fontfile);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.width)) {
|
||||
if (is.number(inputOptions.text.width)) {
|
||||
inputDescriptor.textWidth = inputOptions.text.width;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.textWidth', 'number', inputOptions.text.width);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.height)) {
|
||||
if (is.number(inputOptions.text.height)) {
|
||||
inputDescriptor.textHeight = inputOptions.text.height;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.height', 'number', inputOptions.text.height);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.align)) {
|
||||
if (is.string(inputOptions.text.align) && is.string(this.constructor.align[inputOptions.text.align])) {
|
||||
inputDescriptor.textAlign = this.constructor.align[inputOptions.text.align];
|
||||
} else {
|
||||
throw is.invalidParameterError('text.align', 'valid alignment', inputOptions.text.align);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.justify)) {
|
||||
if (is.bool(inputOptions.text.justify)) {
|
||||
inputDescriptor.textJustify = inputOptions.text.justify;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.justify', 'boolean', inputOptions.text.justify);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.dpi)) {
|
||||
if (is.number(inputOptions.text.dpi) && is.inRange(inputOptions.text.dpi, 1, 100000)) {
|
||||
inputDescriptor.textDpi = inputOptions.text.dpi;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.dpi', 'number between 1 and 100000', inputOptions.text.dpi);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.rgba)) {
|
||||
if (is.bool(inputOptions.text.rgba)) {
|
||||
inputDescriptor.textRgba = inputOptions.text.rgba;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.rgba', 'bool', inputOptions.text.rgba);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.spacing)) {
|
||||
if (is.number(inputOptions.text.spacing)) {
|
||||
inputDescriptor.textSpacing = inputOptions.text.spacing;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.spacing', 'number', inputOptions.text.spacing);
|
||||
}
|
||||
}
|
||||
if (is.defined(inputOptions.text.wrap)) {
|
||||
if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'wordChar', 'none'])) {
|
||||
inputDescriptor.textWrap = inputOptions.text.wrap;
|
||||
} else {
|
||||
throw is.invalidParameterError('text.wrap', 'one of: word, char, wordChar, none', inputOptions.text.wrap);
|
||||
}
|
||||
}
|
||||
delete inputDescriptor.buffer;
|
||||
} else {
|
||||
throw new Error('Expected a valid string to create an image with text.');
|
||||
}
|
||||
}
|
||||
} else if (is.defined(inputOptions)) {
|
||||
throw new Error('Invalid input options ' + inputOptions);
|
||||
}
|
||||
return inputDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming Buffer chunk on Writable Stream.
|
||||
* @private
|
||||
* @param {Buffer} chunk
|
||||
* @param {string} encoding - unused
|
||||
* @param {Function} callback
|
||||
*/
|
||||
function _write (chunk, encoding, callback) {
|
||||
/* istanbul ignore else */
|
||||
if (Array.isArray(this.options.input.buffer)) {
|
||||
/* istanbul ignore else */
|
||||
if (is.buffer(chunk)) {
|
||||
if (this.options.input.buffer.length === 0) {
|
||||
this.on('finish', () => {
|
||||
this.streamInFinished = true;
|
||||
});
|
||||
}
|
||||
this.options.input.buffer.push(chunk);
|
||||
callback();
|
||||
} else {
|
||||
callback(new Error('Non-Buffer data on Writable Stream'));
|
||||
}
|
||||
} else {
|
||||
callback(new Error('Unexpected data on Writable Stream'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens the array of chunks accumulated in input.buffer.
|
||||
* @private
|
||||
*/
|
||||
function _flattenBufferIn () {
|
||||
if (this._isStreamInput()) {
|
||||
this.options.input.buffer = Buffer.concat(this.options.input.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we expecting Stream-based input?
|
||||
* @private
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function _isStreamInput () {
|
||||
return Array.isArray(this.options.input.buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fast access to (uncached) image metadata without decoding any compressed pixel data.
|
||||
*
|
||||
* This is read from the header of the input image.
|
||||
* It does not take into consideration any operations to be applied to the output image,
|
||||
* such as resize or rotate.
|
||||
*
|
||||
* Dimensions in the response will respect the `page` and `pages` properties of the
|
||||
* {@link /api-constructor#parameters|constructor parameters}.
|
||||
*
|
||||
* A `Promise` is returned when `callback` is not provided.
|
||||
*
|
||||
* - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||
* - `size`: Total size of image in bytes, for Stream and Buffer input only
|
||||
* - `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
|
||||
* - `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
|
||||
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/VipsImage.html#VipsInterpretation)
|
||||
* - `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/VipsImage.html#VipsBandFormat)
|
||||
* - `density`: Number of pixels per inch (DPI), if present
|
||||
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||
* - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
||||
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||
* - `pagePrimary`: Number of the primary page in a HEIF image
|
||||
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||
* - `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
||||
* - `orientation`: Number value of the EXIF Orientation header, if present
|
||||
* - `exif`: Buffer containing raw EXIF data, if present
|
||||
* - `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
||||
* - `iptc`: Buffer containing raw IPTC data, if present
|
||||
* - `xmp`: Buffer containing raw XMP data, if present
|
||||
* - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||
* - `formatMagick`: String containing format for images loaded via *magick
|
||||
*
|
||||
* @example
|
||||
* const metadata = await sharp(input).metadata();
|
||||
*
|
||||
* @example
|
||||
* const image = sharp(inputJpg);
|
||||
* image
|
||||
* .metadata()
|
||||
* .then(function(metadata) {
|
||||
* return image
|
||||
* .resize(Math.round(metadata.width / 2))
|
||||
* .webp()
|
||||
* .toBuffer();
|
||||
* })
|
||||
* .then(function(data) {
|
||||
* // data contains a WebP image half the width and height of the original JPEG
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* // Based on EXIF rotation metadata, get the right-side-up width and height:
|
||||
*
|
||||
* const size = getNormalSize(await sharp(input).metadata());
|
||||
*
|
||||
* function getNormalSize({ width, height, orientation }) {
|
||||
* return (orientation || 0) >= 5
|
||||
* ? { width: height, height: width }
|
||||
* : { width, height };
|
||||
* }
|
||||
*
|
||||
* @param {Function} [callback] - called with the arguments `(err, metadata)`
|
||||
* @returns {Promise<Object>|Sharp}
|
||||
*/
|
||||
function metadata (callback) {
|
||||
const stack = Error();
|
||||
if (is.fn(callback)) {
|
||||
if (this._isStreamInput()) {
|
||||
this.on('finish', () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.metadata(this.options, (err, metadata) => {
|
||||
if (err) {
|
||||
callback(is.nativeError(err, stack));
|
||||
} else {
|
||||
callback(null, metadata);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
sharp.metadata(this.options, (err, metadata) => {
|
||||
if (err) {
|
||||
callback(is.nativeError(err, stack));
|
||||
} else {
|
||||
callback(null, metadata);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
} else {
|
||||
if (this._isStreamInput()) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const finished = () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.metadata(this.options, (err, metadata) => {
|
||||
if (err) {
|
||||
reject(is.nativeError(err, stack));
|
||||
} else {
|
||||
resolve(metadata);
|
||||
}
|
||||
});
|
||||
};
|
||||
if (this.writableFinished) {
|
||||
finished();
|
||||
} else {
|
||||
this.once('finish', finished);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
sharp.metadata(this.options, (err, metadata) => {
|
||||
if (err) {
|
||||
reject(is.nativeError(err, stack));
|
||||
} else {
|
||||
resolve(metadata);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to pixel-derived image statistics for every channel in the image.
|
||||
* A `Promise` is returned when `callback` is not provided.
|
||||
*
|
||||
* - `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||
* - `min` (minimum value in the channel)
|
||||
* - `max` (maximum value in the channel)
|
||||
* - `sum` (sum of all values in a channel)
|
||||
* - `squaresSum` (sum of squared values in a channel)
|
||||
* - `mean` (mean of the values in a channel)
|
||||
* - `stdev` (standard deviation for the values in a channel)
|
||||
* - `minX` (x-coordinate of one of the pixel where the minimum lies)
|
||||
* - `minY` (y-coordinate of one of the pixel where the minimum lies)
|
||||
* - `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||
* - `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||
* - `isOpaque`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
|
||||
* - `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any.
|
||||
* - `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any.
|
||||
* - `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram.
|
||||
*
|
||||
* **Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
||||
* written to a buffer in order to run `stats` on the result (see third example).
|
||||
*
|
||||
* @example
|
||||
* const image = sharp(inputJpg);
|
||||
* image
|
||||
* .stats()
|
||||
* .then(function(stats) {
|
||||
* // stats contains the channel-wise statistics array and the isOpaque value
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* const { entropy, sharpness, dominant } = await sharp(input).stats();
|
||||
* const { r, g, b } = dominant;
|
||||
*
|
||||
* @example
|
||||
* const image = sharp(input);
|
||||
* // store intermediate result
|
||||
* const part = await image.extract(region).toBuffer();
|
||||
* // create new instance to obtain statistics of extracted region
|
||||
* const stats = await sharp(part).stats();
|
||||
*
|
||||
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
function stats (callback) {
|
||||
const stack = Error();
|
||||
if (is.fn(callback)) {
|
||||
if (this._isStreamInput()) {
|
||||
this.on('finish', () => {
|
||||
this._flattenBufferIn();
|
||||
sharp.stats(this.options, (err, stats) => {
|
||||
if (err) {
|
||||
callback(is.nativeError(err, stack));
|
||||
} else {
|
||||
callback(null, stats);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
sharp.stats(this.options, (err, stats) => {
|
||||
if (err) {
|
||||
callback(is.nativeError(err, stack));
|
||||
} else {
|
||||
callback(null, stats);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
} else {
|
||||
if (this._isStreamInput()) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.on('finish', function () {
|
||||
this._flattenBufferIn();
|
||||
sharp.stats(this.options, (err, stats) => {
|
||||
if (err) {
|
||||
reject(is.nativeError(err, stack));
|
||||
} else {
|
||||
resolve(stats);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
sharp.stats(this.options, (err, stats) => {
|
||||
if (err) {
|
||||
reject(is.nativeError(err, stack));
|
||||
} else {
|
||||
resolve(stats);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with input-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Object.assign(Sharp.prototype, {
|
||||
// Private
|
||||
_inputOptionsFromObject,
|
||||
_createInputDescriptor,
|
||||
_write,
|
||||
_flattenBufferIn,
|
||||
_isStreamInput,
|
||||
// Public
|
||||
metadata,
|
||||
stats
|
||||
});
|
||||
// Class attributes
|
||||
Sharp.align = align;
|
||||
};
|
||||
169
lib/is.js
Normal file
169
lib/is.js
Normal file
@@ -0,0 +1,169 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Is this value defined and not null?
|
||||
* @private
|
||||
*/
|
||||
const defined = function (val) {
|
||||
return typeof val !== 'undefined' && val !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value an object?
|
||||
* @private
|
||||
*/
|
||||
const object = function (val) {
|
||||
return typeof val === 'object';
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a plain object?
|
||||
* @private
|
||||
*/
|
||||
const plainObject = function (val) {
|
||||
return Object.prototype.toString.call(val) === '[object Object]';
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a function?
|
||||
* @private
|
||||
*/
|
||||
const fn = function (val) {
|
||||
return typeof val === 'function';
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a boolean?
|
||||
* @private
|
||||
*/
|
||||
const bool = function (val) {
|
||||
return typeof val === 'boolean';
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a Buffer object?
|
||||
* @private
|
||||
*/
|
||||
const buffer = function (val) {
|
||||
return val instanceof Buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
|
||||
* @private
|
||||
*/
|
||||
const typedArray = function (val) {
|
||||
if (defined(val)) {
|
||||
switch (val.constructor) {
|
||||
case Uint8Array:
|
||||
case Uint8ClampedArray:
|
||||
case Int8Array:
|
||||
case Uint16Array:
|
||||
case Int16Array:
|
||||
case Uint32Array:
|
||||
case Int32Array:
|
||||
case Float32Array:
|
||||
case Float64Array:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value an ArrayBuffer object?
|
||||
* @private
|
||||
*/
|
||||
const arrayBuffer = function (val) {
|
||||
return val instanceof ArrayBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a non-empty string?
|
||||
* @private
|
||||
*/
|
||||
const string = function (val) {
|
||||
return typeof val === 'string' && val.length > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value a real number?
|
||||
* @private
|
||||
*/
|
||||
const number = function (val) {
|
||||
return typeof val === 'number' && !Number.isNaN(val);
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value an integer?
|
||||
* @private
|
||||
*/
|
||||
const integer = function (val) {
|
||||
return Number.isInteger(val);
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value within an inclusive given range?
|
||||
* @private
|
||||
*/
|
||||
const inRange = function (val, min, max) {
|
||||
return val >= min && val <= max;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this value within the elements of an array?
|
||||
* @private
|
||||
*/
|
||||
const inArray = function (val, list) {
|
||||
return list.includes(val);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an Error with a message relating to an invalid parameter.
|
||||
*
|
||||
* @param {string} name - parameter name.
|
||||
* @param {string} expected - description of the type/value/range expected.
|
||||
* @param {*} actual - the value received.
|
||||
* @returns {Error} Containing the formatted message.
|
||||
* @private
|
||||
*/
|
||||
const invalidParameterError = function (name, expected, actual) {
|
||||
return new Error(
|
||||
`Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensures an Error from C++ contains a JS stack.
|
||||
*
|
||||
* @param {Error} native - Error with message from C++.
|
||||
* @param {Error} context - Error with stack from JS.
|
||||
* @returns {Error} Error with message and stack.
|
||||
* @private
|
||||
*/
|
||||
const nativeError = function (native, context) {
|
||||
context.message = native.message;
|
||||
return context;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
defined,
|
||||
object,
|
||||
plainObject,
|
||||
fn,
|
||||
bool,
|
||||
buffer,
|
||||
typedArray,
|
||||
arrayBuffer,
|
||||
string,
|
||||
number,
|
||||
integer,
|
||||
inRange,
|
||||
inArray,
|
||||
invalidParameterError,
|
||||
nativeError
|
||||
};
|
||||
195
lib/libvips.js
Normal file
195
lib/libvips.js
Normal file
@@ -0,0 +1,195 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { createHash } = require('node:crypto');
|
||||
const semverCoerce = require('semver/functions/coerce');
|
||||
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
||||
const semverSatisfies = require('semver/functions/satisfies');
|
||||
const detectLibc = require('detect-libc');
|
||||
|
||||
const { engines, optionalDependencies } = require('../package.json');
|
||||
|
||||
const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || /* istanbul ignore next */
|
||||
engines.libvips;
|
||||
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
||||
|
||||
const prebuiltPlatforms = [
|
||||
'darwin-arm64', 'darwin-x64',
|
||||
'linux-arm', 'linux-arm64', 'linux-s390x', 'linux-x64',
|
||||
'linuxmusl-arm64', 'linuxmusl-x64',
|
||||
'win32-ia32', 'win32-x64'
|
||||
];
|
||||
|
||||
const spawnSyncOptions = {
|
||||
encoding: 'utf8',
|
||||
shell: true
|
||||
};
|
||||
|
||||
const log = (item) => {
|
||||
if (item instanceof Error) {
|
||||
console.error(`sharp: Installation error: ${item.message}`);
|
||||
} else {
|
||||
console.log(`sharp: ${item}`);
|
||||
}
|
||||
};
|
||||
|
||||
/* istanbul ignore next */
|
||||
const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
|
||||
|
||||
const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
|
||||
|
||||
/* istanbul ignore next */
|
||||
const buildPlatformArch = () => {
|
||||
if (isEmscripten()) {
|
||||
return 'wasm32';
|
||||
}
|
||||
/* eslint camelcase: ["error", { allow: ["^npm_config_"] }] */
|
||||
const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
|
||||
const libc = typeof npm_config_libc === 'string' ? npm_config_libc : runtimeLibc();
|
||||
return `${npm_config_platform || process.platform}${libc}-${npm_config_arch || process.arch}`;
|
||||
};
|
||||
|
||||
const buildSharpLibvipsIncludeDir = () => {
|
||||
try {
|
||||
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
|
||||
} catch {
|
||||
try {
|
||||
return require('@img/sharp-libvips-dev/include');
|
||||
} catch {}
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
return '';
|
||||
};
|
||||
|
||||
const buildSharpLibvipsCPlusPlusDir = () => {
|
||||
try {
|
||||
return require('@img/sharp-libvips-dev/cplusplus');
|
||||
} catch {}
|
||||
/* istanbul ignore next */
|
||||
return '';
|
||||
};
|
||||
|
||||
const buildSharpLibvipsLibDir = () => {
|
||||
try {
|
||||
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
|
||||
} catch {
|
||||
try {
|
||||
return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
|
||||
} catch {}
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
return '';
|
||||
};
|
||||
|
||||
const isUnsupportedNodeRuntime = () => {
|
||||
/* istanbul ignore next */
|
||||
if (process.release?.name === 'node' && process.versions) {
|
||||
if (!semverSatisfies(process.versions.node, engines.node)) {
|
||||
return { found: process.versions.node, expected: engines.node };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* istanbul ignore next */
|
||||
const isEmscripten = () => {
|
||||
const { CC } = process.env;
|
||||
return Boolean(CC && CC.endsWith('/emcc'));
|
||||
};
|
||||
|
||||
const isRosetta = () => {
|
||||
/* istanbul ignore next */
|
||||
if (process.platform === 'darwin' && process.arch === 'x64') {
|
||||
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
|
||||
return (translated || '').trim() === 'sysctl.proc_translated: 1';
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const sha512 = (s) => createHash('sha512').update(s).digest('hex');
|
||||
|
||||
const yarnLocator = () => {
|
||||
try {
|
||||
const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
|
||||
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version;
|
||||
return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
|
||||
} catch {}
|
||||
return '';
|
||||
};
|
||||
|
||||
/* istanbul ignore next */
|
||||
const spawnRebuild = () =>
|
||||
spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, {
|
||||
...spawnSyncOptions,
|
||||
stdio: 'inherit'
|
||||
}).status;
|
||||
|
||||
const globalLibvipsVersion = () => {
|
||||
if (process.platform !== 'win32') {
|
||||
const globalLibvipsVersion = spawnSync('pkg-config --modversion vips-cpp', {
|
||||
...spawnSyncOptions,
|
||||
env: {
|
||||
...process.env,
|
||||
PKG_CONFIG_PATH: pkgConfigPath()
|
||||
}
|
||||
}).stdout;
|
||||
/* istanbul ignore next */
|
||||
return (globalLibvipsVersion || '').trim();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
/* istanbul ignore next */
|
||||
const pkgConfigPath = () => {
|
||||
if (process.platform !== 'win32') {
|
||||
const brewPkgConfigPath = spawnSync(
|
||||
'which brew >/dev/null 2>&1 && brew environment --plain | grep PKG_CONFIG_LIBDIR | cut -d" " -f2',
|
||||
spawnSyncOptions
|
||||
).stdout || '';
|
||||
return [
|
||||
brewPkgConfigPath.trim(),
|
||||
process.env.PKG_CONFIG_PATH,
|
||||
'/usr/local/lib/pkgconfig',
|
||||
'/usr/lib/pkgconfig',
|
||||
'/usr/local/libdata/pkgconfig',
|
||||
'/usr/libdata/pkgconfig'
|
||||
].filter(Boolean).join(':');
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const useGlobalLibvips = () => {
|
||||
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||
log('Detected SHARP_IGNORE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips');
|
||||
return false;
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
if (isRosetta()) {
|
||||
log('Detected Rosetta, skipping search for globally-installed libvips');
|
||||
return false;
|
||||
}
|
||||
const globalVipsVersion = globalLibvipsVersion();
|
||||
return !!globalVipsVersion && /* istanbul ignore next */
|
||||
semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
minimumLibvipsVersion,
|
||||
prebuiltPlatforms,
|
||||
buildPlatformArch,
|
||||
buildSharpLibvipsIncludeDir,
|
||||
buildSharpLibvipsCPlusPlusDir,
|
||||
buildSharpLibvipsLibDir,
|
||||
isUnsupportedNodeRuntime,
|
||||
runtimePlatformArch,
|
||||
log,
|
||||
yarnLocator,
|
||||
spawnRebuild,
|
||||
globalLibvipsVersion,
|
||||
pkgConfigPath,
|
||||
useGlobalLibvips
|
||||
};
|
||||
921
lib/operation.js
Normal file
921
lib/operation.js
Normal file
@@ -0,0 +1,921 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const color = require('color');
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
* Rotate the output image by either an explicit angle
|
||||
* or auto-orient based on the EXIF `Orientation` tag.
|
||||
*
|
||||
* If an angle is provided, it is converted to a valid positive degree rotation.
|
||||
* For example, `-450` will produce a 270 degree rotation.
|
||||
*
|
||||
* When rotating by an angle other than a multiple of 90,
|
||||
* the background colour can be provided with the `background` option.
|
||||
*
|
||||
* If no angle is provided, it is determined from the EXIF data.
|
||||
* Mirroring is supported and may infer the use of a flip operation.
|
||||
*
|
||||
* The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
||||
*
|
||||
* Only one rotation can occur per pipeline.
|
||||
* Previous calls to `rotate` in the same pipeline will be ignored.
|
||||
*
|
||||
* Multi-page images can only be rotated by 180 degrees.
|
||||
*
|
||||
* Method order is important when rotating, resizing and/or extracting regions,
|
||||
* for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
||||
*
|
||||
* @example
|
||||
* const pipeline = sharp()
|
||||
* .rotate()
|
||||
* .resize(null, 200)
|
||||
* .toBuffer(function (err, outputBuffer, info) {
|
||||
* // outputBuffer contains 200px high JPEG image data,
|
||||
* // auto-rotated using EXIF Orientation tag
|
||||
* // info.width and info.height contain the dimensions of the resized image
|
||||
* });
|
||||
* readableStream.pipe(pipeline);
|
||||
*
|
||||
* @example
|
||||
* const rotateThenResize = await sharp(input)
|
||||
* .rotate(90)
|
||||
* .resize({ width: 16, height: 8, fit: 'fill' })
|
||||
* .toBuffer();
|
||||
* const resizeThenRotate = await sharp(input)
|
||||
* .resize({ width: 16, height: 8, fit: 'fill' })
|
||||
* .rotate(90)
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {number} [angle=auto] angle of rotation.
|
||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||
* @param {string|Object} [options.background="#000000"] parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function rotate (angle, options) {
|
||||
if (this.options.useExifOrientation || this.options.angle || this.options.rotationAngle) {
|
||||
this.options.debuglog('ignoring previous rotate options');
|
||||
}
|
||||
if (!is.defined(angle)) {
|
||||
this.options.useExifOrientation = true;
|
||||
} else if (is.integer(angle) && !(angle % 90)) {
|
||||
this.options.angle = angle;
|
||||
} else if (is.number(angle)) {
|
||||
this.options.rotationAngle = angle;
|
||||
if (is.object(options) && options.background) {
|
||||
const backgroundColour = color(options.background);
|
||||
this.options.rotationBackground = [
|
||||
backgroundColour.red(),
|
||||
backgroundColour.green(),
|
||||
backgroundColour.blue(),
|
||||
Math.round(backgroundColour.alpha() * 255)
|
||||
];
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('angle', 'numeric', angle);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror the image vertically (up-down) about the x-axis.
|
||||
* This always occurs before rotation, if any.
|
||||
*
|
||||
* This operation does not work correctly with multi-page images.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input).flip().toBuffer();
|
||||
*
|
||||
* @param {Boolean} [flip=true]
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function flip (flip) {
|
||||
this.options.flip = is.bool(flip) ? flip : true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror the image horizontally (left-right) about the y-axis.
|
||||
* This always occurs before rotation, if any.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input).flop().toBuffer();
|
||||
*
|
||||
* @param {Boolean} [flop=true]
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function flop (flop) {
|
||||
this.options.flop = is.bool(flop) ? flop : true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||
*
|
||||
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||
*
|
||||
* In the case of a 2x2 matrix, the transform is:
|
||||
* - X = `matrix[0, 0]` \* (x + `idx`) + `matrix[0, 1]` \* (y + `idy`) + `odx`
|
||||
* - Y = `matrix[1, 0]` \* (x + `idx`) + `matrix[1, 1]` \* (y + `idy`) + `ody`
|
||||
*
|
||||
* where:
|
||||
* - x and y are the coordinates in input image.
|
||||
* - X and Y are the coordinates in output image.
|
||||
* - (0,0) is the upper left corner.
|
||||
*
|
||||
* @since 0.27.0
|
||||
*
|
||||
* @example
|
||||
* const pipeline = sharp()
|
||||
* .affine([[1, 0.3], [0.1, 0.7]], {
|
||||
* background: 'white',
|
||||
* interpolator: sharp.interpolators.nohalo
|
||||
* })
|
||||
* .toBuffer((err, outputBuffer, info) => {
|
||||
* // outputBuffer contains the transformed image
|
||||
* // info.width and info.height contain the new dimensions
|
||||
* });
|
||||
*
|
||||
* inputStream
|
||||
* .pipe(pipeline);
|
||||
*
|
||||
* @param {Array<Array<number>>|Array<number>} matrix - affine transformation matrix
|
||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||
* @param {String|Object} [options.background="#000000"] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||
* @param {Number} [options.idx=0] - input horizontal offset
|
||||
* @param {Number} [options.idy=0] - input vertical offset
|
||||
* @param {Number} [options.odx=0] - output horizontal offset
|
||||
* @param {Number} [options.ody=0] - output vertical offset
|
||||
* @param {String} [options.interpolator=sharp.interpolators.bicubic] - interpolator
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function affine (matrix, options) {
|
||||
const flatMatrix = [].concat(...matrix);
|
||||
if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
|
||||
this.options.affineMatrix = flatMatrix;
|
||||
} else {
|
||||
throw is.invalidParameterError('matrix', '1x4 or 2x2 array', matrix);
|
||||
}
|
||||
|
||||
if (is.defined(options)) {
|
||||
if (is.object(options)) {
|
||||
this._setBackgroundColourOption('affineBackground', options.background);
|
||||
if (is.defined(options.idx)) {
|
||||
if (is.number(options.idx)) {
|
||||
this.options.affineIdx = options.idx;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.idx', 'number', options.idx);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.idy)) {
|
||||
if (is.number(options.idy)) {
|
||||
this.options.affineIdy = options.idy;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.idy', 'number', options.idy);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.odx)) {
|
||||
if (is.number(options.odx)) {
|
||||
this.options.affineOdx = options.odx;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.odx', 'number', options.odx);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.ody)) {
|
||||
if (is.number(options.ody)) {
|
||||
this.options.affineOdy = options.ody;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.ody', 'number', options.ody);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.interpolator)) {
|
||||
if (is.inArray(options.interpolator, Object.values(this.constructor.interpolators))) {
|
||||
this.options.affineInterpolator = options.interpolator;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.interpolator', 'valid interpolator name', options.interpolator);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('options', 'object', options);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sharpen the image.
|
||||
*
|
||||
* When used without parameters, performs a fast, mild sharpen of the output image.
|
||||
*
|
||||
* When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
||||
* Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
|
||||
*
|
||||
* See {@link https://www.libvips.org/API/current/libvips-convolution.html#vips-sharpen|libvips sharpen} operation.
|
||||
*
|
||||
* @example
|
||||
* const data = await sharp(input).sharpen().toBuffer();
|
||||
*
|
||||
* @example
|
||||
* const data = await sharp(input).sharpen({ sigma: 2 }).toBuffer();
|
||||
*
|
||||
* @example
|
||||
* const data = await sharp(input)
|
||||
* .sharpen({
|
||||
* sigma: 2,
|
||||
* m1: 0,
|
||||
* m2: 3,
|
||||
* x1: 3,
|
||||
* y2: 15,
|
||||
* y3: 15,
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object|number} [options] - if present, is an Object with attributes
|
||||
* @param {number} [options.sigma] - the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`, between 0.000001 and 10
|
||||
* @param {number} [options.m1=1.0] - the level of sharpening to apply to "flat" areas, between 0 and 1000000
|
||||
* @param {number} [options.m2=2.0] - the level of sharpening to apply to "jagged" areas, between 0 and 1000000
|
||||
* @param {number} [options.x1=2.0] - threshold between "flat" and "jagged", between 0 and 1000000
|
||||
* @param {number} [options.y2=10.0] - maximum amount of brightening, between 0 and 1000000
|
||||
* @param {number} [options.y3=20.0] - maximum amount of darkening, between 0 and 1000000
|
||||
* @param {number} [flat] - (deprecated) see `options.m1`.
|
||||
* @param {number} [jagged] - (deprecated) see `options.m2`.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function sharpen (options, flat, jagged) {
|
||||
if (!is.defined(options)) {
|
||||
// No arguments: default to mild sharpen
|
||||
this.options.sharpenSigma = -1;
|
||||
} else if (is.bool(options)) {
|
||||
// Deprecated boolean argument: apply mild sharpen?
|
||||
this.options.sharpenSigma = options ? -1 : 0;
|
||||
} else if (is.number(options) && is.inRange(options, 0.01, 10000)) {
|
||||
// Deprecated numeric argument: specific sigma
|
||||
this.options.sharpenSigma = options;
|
||||
// Deprecated control over flat areas
|
||||
if (is.defined(flat)) {
|
||||
if (is.number(flat) && is.inRange(flat, 0, 10000)) {
|
||||
this.options.sharpenM1 = flat;
|
||||
} else {
|
||||
throw is.invalidParameterError('flat', 'number between 0 and 10000', flat);
|
||||
}
|
||||
}
|
||||
// Deprecated control over jagged areas
|
||||
if (is.defined(jagged)) {
|
||||
if (is.number(jagged) && is.inRange(jagged, 0, 10000)) {
|
||||
this.options.sharpenM2 = jagged;
|
||||
} else {
|
||||
throw is.invalidParameterError('jagged', 'number between 0 and 10000', jagged);
|
||||
}
|
||||
}
|
||||
} else if (is.plainObject(options)) {
|
||||
if (is.number(options.sigma) && is.inRange(options.sigma, 0.000001, 10)) {
|
||||
this.options.sharpenSigma = options.sigma;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.sigma', 'number between 0.000001 and 10', options.sigma);
|
||||
}
|
||||
if (is.defined(options.m1)) {
|
||||
if (is.number(options.m1) && is.inRange(options.m1, 0, 1000000)) {
|
||||
this.options.sharpenM1 = options.m1;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.m1', 'number between 0 and 1000000', options.m1);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.m2)) {
|
||||
if (is.number(options.m2) && is.inRange(options.m2, 0, 1000000)) {
|
||||
this.options.sharpenM2 = options.m2;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.m2', 'number between 0 and 1000000', options.m2);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.x1)) {
|
||||
if (is.number(options.x1) && is.inRange(options.x1, 0, 1000000)) {
|
||||
this.options.sharpenX1 = options.x1;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.x1', 'number between 0 and 1000000', options.x1);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.y2)) {
|
||||
if (is.number(options.y2) && is.inRange(options.y2, 0, 1000000)) {
|
||||
this.options.sharpenY2 = options.y2;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.y2', 'number between 0 and 1000000', options.y2);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.y3)) {
|
||||
if (is.number(options.y3) && is.inRange(options.y3, 0, 1000000)) {
|
||||
this.options.sharpenY3 = options.y3;
|
||||
} else {
|
||||
throw is.invalidParameterError('options.y3', 'number between 0 and 1000000', options.y3);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('sigma', 'number between 0.01 and 10000', options);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply median filter.
|
||||
* When used without parameters the default window is 3x3.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input).median().toBuffer();
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input).median(5).toBuffer();
|
||||
*
|
||||
* @param {number} [size=3] square mask size: size x size
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function median (size) {
|
||||
if (!is.defined(size)) {
|
||||
// No arguments: default to 3x3
|
||||
this.options.medianSize = 3;
|
||||
} else if (is.integer(size) && is.inRange(size, 1, 1000)) {
|
||||
// Numeric argument: specific sigma
|
||||
this.options.medianSize = size;
|
||||
} else {
|
||||
throw is.invalidParameterError('size', 'integer between 1 and 1000', size);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blur the image.
|
||||
*
|
||||
* When used without parameters, performs a fast 3x3 box blur (equivalent to a box linear filter).
|
||||
*
|
||||
* When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
||||
*
|
||||
* @example
|
||||
* const boxBlurred = await sharp(input)
|
||||
* .blur()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* const gaussianBlurred = await sharp(input)
|
||||
* .blur(5)
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {number} [sigma] a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function blur (sigma) {
|
||||
if (!is.defined(sigma)) {
|
||||
// No arguments: default to mild blur
|
||||
this.options.blurSigma = -1;
|
||||
} else if (is.bool(sigma)) {
|
||||
// Boolean argument: apply mild blur?
|
||||
this.options.blurSigma = sigma ? -1 : 0;
|
||||
} else if (is.number(sigma) && is.inRange(sigma, 0.3, 1000)) {
|
||||
// Numeric argument: specific sigma
|
||||
this.options.blurSigma = sigma;
|
||||
} else {
|
||||
throw is.invalidParameterError('sigma', 'number between 0.3 and 1000', sigma);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
||||
*
|
||||
* See also {@link /api-channel#removealpha|removeAlpha}.
|
||||
*
|
||||
* @example
|
||||
* await sharp(rgbaInput)
|
||||
* .flatten({ background: '#F0A703' })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {string|Object} [options.background={r: 0, g: 0, b: 0}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black.
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function flatten (options) {
|
||||
this.options.flatten = is.bool(options) ? options : true;
|
||||
if (is.object(options)) {
|
||||
this._setBackgroundColourOption('flattenBackground', options.background);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the image has an alpha channel
|
||||
* with all white pixel values made fully transparent.
|
||||
*
|
||||
* Existing alpha channel values for non-white pixels remain unchanged.
|
||||
*
|
||||
* This feature is experimental and the API may change.
|
||||
*
|
||||
* @since 0.32.1
|
||||
*
|
||||
* @example
|
||||
* await sharp(rgbInput)
|
||||
* .unflatten()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* await sharp(rgbInput)
|
||||
* .threshold(128, { grayscale: false }) // converter bright pixels to white
|
||||
* .unflatten()
|
||||
* .toBuffer();
|
||||
*/
|
||||
function unflatten () {
|
||||
this.options.unflatten = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma`
|
||||
* then increasing the encoding (brighten) post-resize at a factor of `gamma`.
|
||||
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||
* JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
||||
* when applying a gamma correction.
|
||||
*
|
||||
* Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
||||
*
|
||||
* @param {number} [gamma=2.2] value between 1.0 and 3.0.
|
||||
* @param {number} [gammaOut] value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function gamma (gamma, gammaOut) {
|
||||
if (!is.defined(gamma)) {
|
||||
// Default gamma correction of 2.2 (sRGB)
|
||||
this.options.gamma = 2.2;
|
||||
} else if (is.number(gamma) && is.inRange(gamma, 1, 3)) {
|
||||
this.options.gamma = gamma;
|
||||
} else {
|
||||
throw is.invalidParameterError('gamma', 'number between 1.0 and 3.0', gamma);
|
||||
}
|
||||
if (!is.defined(gammaOut)) {
|
||||
// Default gamma correction for output is same as input
|
||||
this.options.gammaOut = this.options.gamma;
|
||||
} else if (is.number(gammaOut) && is.inRange(gammaOut, 1, 3)) {
|
||||
this.options.gammaOut = gammaOut;
|
||||
} else {
|
||||
throw is.invalidParameterError('gammaOut', 'number between 1.0 and 3.0', gammaOut);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce the "negative" of the image.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .negate()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .negate({ alpha: false })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.alpha=true] Whether or not to negate any alpha channel
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function negate (options) {
|
||||
this.options.negate = is.bool(options) ? options : true;
|
||||
if (is.plainObject(options) && 'alpha' in options) {
|
||||
if (!is.bool(options.alpha)) {
|
||||
throw is.invalidParameterError('alpha', 'should be boolean value', options.alpha);
|
||||
} else {
|
||||
this.options.negateAlpha = options.alpha;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enhance output image contrast by stretching its luminance to cover a full dynamic range.
|
||||
*
|
||||
* Uses a histogram-based approach, taking a default range of 1% to 99% to reduce sensitivity to noise at the extremes.
|
||||
*
|
||||
* Luminance values below the `lower` percentile will be underexposed by clipping to zero.
|
||||
* Luminance values above the `upper` percentile will be overexposed by clipping to the max pixel value.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .normalise()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .normalise({ lower: 0, upper: 100 })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {number} [options.lower=1] - Percentile below which luminance values will be underexposed.
|
||||
* @param {number} [options.upper=99] - Percentile above which luminance values will be overexposed.
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function normalise (options) {
|
||||
if (is.plainObject(options)) {
|
||||
if (is.defined(options.lower)) {
|
||||
if (is.number(options.lower) && is.inRange(options.lower, 0, 99)) {
|
||||
this.options.normaliseLower = options.lower;
|
||||
} else {
|
||||
throw is.invalidParameterError('lower', 'number between 0 and 99', options.lower);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.upper)) {
|
||||
if (is.number(options.upper) && is.inRange(options.upper, 1, 100)) {
|
||||
this.options.normaliseUpper = options.upper;
|
||||
} else {
|
||||
throw is.invalidParameterError('upper', 'number between 1 and 100', options.upper);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.options.normaliseLower >= this.options.normaliseUpper) {
|
||||
throw is.invalidParameterError('range', 'lower to be less than upper',
|
||||
`${this.options.normaliseLower} >= ${this.options.normaliseUpper}`);
|
||||
}
|
||||
this.options.normalise = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative spelling of normalise.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .normalize()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {number} [options.lower=1] - Percentile below which luminance values will be underexposed.
|
||||
* @param {number} [options.upper=99] - Percentile above which luminance values will be overexposed.
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function normalize (options) {
|
||||
return this.normalise(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform contrast limiting adaptive histogram equalization
|
||||
* {@link https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE|CLAHE}.
|
||||
*
|
||||
* This will, in general, enhance the clarity of the image by bringing out darker details.
|
||||
*
|
||||
* @since 0.28.3
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .clahe({
|
||||
* width: 3,
|
||||
* height: 3,
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {number} options.width - Integral width of the search window, in pixels.
|
||||
* @param {number} options.height - Integral height of the search window, in pixels.
|
||||
* @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function clahe (options) {
|
||||
if (is.plainObject(options)) {
|
||||
if (is.integer(options.width) && options.width > 0) {
|
||||
this.options.claheWidth = options.width;
|
||||
} else {
|
||||
throw is.invalidParameterError('width', 'integer greater than zero', options.width);
|
||||
}
|
||||
if (is.integer(options.height) && options.height > 0) {
|
||||
this.options.claheHeight = options.height;
|
||||
} else {
|
||||
throw is.invalidParameterError('height', 'integer greater than zero', options.height);
|
||||
}
|
||||
if (is.defined(options.maxSlope)) {
|
||||
if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
|
||||
this.options.claheMaxSlope = options.maxSlope;
|
||||
} else {
|
||||
throw is.invalidParameterError('maxSlope', 'integer between 0 and 100', options.maxSlope);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('options', 'plain object', options);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convolve the image with the specified kernel.
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .convolve({
|
||||
* width: 3,
|
||||
* height: 3,
|
||||
* kernel: [-1, 0, 1, -2, 0, 2, -1, 0, 1]
|
||||
* })
|
||||
* .raw()
|
||||
* .toBuffer(function(err, data, info) {
|
||||
* // data contains the raw pixel data representing the convolution
|
||||
* // of the input image with the horizontal Sobel operator
|
||||
* });
|
||||
*
|
||||
* @param {Object} kernel
|
||||
* @param {number} kernel.width - width of the kernel in pixels.
|
||||
* @param {number} kernel.height - height of the kernel in pixels.
|
||||
* @param {Array<number>} kernel.kernel - Array of length `width*height` containing the kernel values.
|
||||
* @param {number} [kernel.scale=sum] - the scale of the kernel in pixels.
|
||||
* @param {number} [kernel.offset=0] - the offset of the kernel in pixels.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function convolve (kernel) {
|
||||
if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
|
||||
!is.integer(kernel.width) || !is.integer(kernel.height) ||
|
||||
!is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
|
||||
kernel.height * kernel.width !== kernel.kernel.length
|
||||
) {
|
||||
// must pass in a kernel
|
||||
throw new Error('Invalid convolution kernel');
|
||||
}
|
||||
// Default scale is sum of kernel values
|
||||
if (!is.integer(kernel.scale)) {
|
||||
kernel.scale = kernel.kernel.reduce(function (a, b) {
|
||||
return a + b;
|
||||
}, 0);
|
||||
}
|
||||
// Clip scale to a minimum value of 1
|
||||
if (kernel.scale < 1) {
|
||||
kernel.scale = 1;
|
||||
}
|
||||
if (!is.integer(kernel.offset)) {
|
||||
kernel.offset = 0;
|
||||
}
|
||||
this.options.convKernel = kernel;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
||||
* @param {number} [threshold=128] - a value in the range 0-255 representing the level at which the threshold will be applied.
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.greyscale=true] - convert to single channel greyscale.
|
||||
* @param {Boolean} [options.grayscale=true] - alternative spelling for greyscale.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function threshold (threshold, options) {
|
||||
if (!is.defined(threshold)) {
|
||||
this.options.threshold = 128;
|
||||
} else if (is.bool(threshold)) {
|
||||
this.options.threshold = threshold ? 128 : 0;
|
||||
} else if (is.integer(threshold) && is.inRange(threshold, 0, 255)) {
|
||||
this.options.threshold = threshold;
|
||||
} else {
|
||||
throw is.invalidParameterError('threshold', 'integer between 0 and 255', threshold);
|
||||
}
|
||||
if (!is.object(options) || options.greyscale === true || options.grayscale === true) {
|
||||
this.options.thresholdGrayscale = true;
|
||||
} else {
|
||||
this.options.thresholdGrayscale = false;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a bitwise boolean operation with operand image.
|
||||
*
|
||||
* This operation creates an output image where each pixel is the result of
|
||||
* the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
||||
*
|
||||
* @param {Buffer|string} operand - Buffer containing image data or string containing the path to an image file.
|
||||
* @param {string} operator - one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||
* @param {Object} [options]
|
||||
* @param {Object} [options.raw] - describes operand when using raw pixel data.
|
||||
* @param {number} [options.raw.width]
|
||||
* @param {number} [options.raw.height]
|
||||
* @param {number} [options.raw.channels]
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function boolean (operand, operator, options) {
|
||||
this.options.boolean = this._createInputDescriptor(operand, options);
|
||||
if (is.string(operator) && is.inArray(operator, ['and', 'or', 'eor'])) {
|
||||
this.options.booleanOp = operator;
|
||||
} else {
|
||||
throw is.invalidParameterError('operator', 'one of: and, or, eor', operator);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the linear formula `a` * input + `b` to the image to adjust image levels.
|
||||
*
|
||||
* When a single number is provided, it will be used for all image channels.
|
||||
* When an array of numbers is provided, the array length must match the number of channels.
|
||||
*
|
||||
* @example
|
||||
* await sharp(input)
|
||||
* .linear(0.5, 2)
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* await sharp(rgbInput)
|
||||
* .linear(
|
||||
* [0.25, 0.5, 0.75],
|
||||
* [150, 100, 50]
|
||||
* )
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {(number|number[])} [a=[]] multiplier
|
||||
* @param {(number|number[])} [b=[]] offset
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function linear (a, b) {
|
||||
if (!is.defined(a) && is.number(b)) {
|
||||
a = 1.0;
|
||||
} else if (is.number(a) && !is.defined(b)) {
|
||||
b = 0.0;
|
||||
}
|
||||
if (!is.defined(a)) {
|
||||
this.options.linearA = [];
|
||||
} else if (is.number(a)) {
|
||||
this.options.linearA = [a];
|
||||
} else if (Array.isArray(a) && a.length && a.every(is.number)) {
|
||||
this.options.linearA = a;
|
||||
} else {
|
||||
throw is.invalidParameterError('a', 'number or array of numbers', a);
|
||||
}
|
||||
if (!is.defined(b)) {
|
||||
this.options.linearB = [];
|
||||
} else if (is.number(b)) {
|
||||
this.options.linearB = [b];
|
||||
} else if (Array.isArray(b) && b.length && b.every(is.number)) {
|
||||
this.options.linearB = b;
|
||||
} else {
|
||||
throw is.invalidParameterError('b', 'number or array of numbers', b);
|
||||
}
|
||||
if (this.options.linearA.length !== this.options.linearB.length) {
|
||||
throw new Error('Expected a and b to be arrays of the same length');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recombine the image with the specified matrix.
|
||||
*
|
||||
* @since 0.21.1
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .recomb([
|
||||
* [0.3588, 0.7044, 0.1368],
|
||||
* [0.2990, 0.5870, 0.1140],
|
||||
* [0.2392, 0.4696, 0.0912],
|
||||
* ])
|
||||
* .raw()
|
||||
* .toBuffer(function(err, data, info) {
|
||||
* // data contains the raw pixel data after applying the matrix
|
||||
* // With this example input, a sepia filter has been applied
|
||||
* });
|
||||
*
|
||||
* @param {Array<Array<number>>} inputMatrix - 3x3 Recombination matrix
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function recomb (inputMatrix) {
|
||||
if (!Array.isArray(inputMatrix) || inputMatrix.length !== 3 ||
|
||||
inputMatrix[0].length !== 3 ||
|
||||
inputMatrix[1].length !== 3 ||
|
||||
inputMatrix[2].length !== 3
|
||||
) {
|
||||
// must pass in a kernel
|
||||
throw new Error('Invalid recombination matrix');
|
||||
}
|
||||
this.options.recombMatrix = [
|
||||
inputMatrix[0][0], inputMatrix[0][1], inputMatrix[0][2],
|
||||
inputMatrix[1][0], inputMatrix[1][1], inputMatrix[1][2],
|
||||
inputMatrix[2][0], inputMatrix[2][1], inputMatrix[2][2]
|
||||
].map(Number);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the image using brightness, saturation, hue rotation, and lightness.
|
||||
* Brightness and lightness both operate on luminance, with the difference being that
|
||||
* brightness is multiplicative whereas lightness is additive.
|
||||
*
|
||||
* @since 0.22.1
|
||||
*
|
||||
* @example
|
||||
* // increase brightness by a factor of 2
|
||||
* const output = await sharp(input)
|
||||
* .modulate({
|
||||
* brightness: 2
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // hue-rotate by 180 degrees
|
||||
* const output = await sharp(input)
|
||||
* .modulate({
|
||||
* hue: 180
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // increase lightness by +50
|
||||
* const output = await sharp(input)
|
||||
* .modulate({
|
||||
* lightness: 50
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // decrease brightness and saturation while also hue-rotating by 90 degrees
|
||||
* const output = await sharp(input)
|
||||
* .modulate({
|
||||
* brightness: 0.5,
|
||||
* saturation: 0.5,
|
||||
* hue: 90,
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {number} [options.brightness] Brightness multiplier
|
||||
* @param {number} [options.saturation] Saturation multiplier
|
||||
* @param {number} [options.hue] Degrees for hue rotation
|
||||
* @param {number} [options.lightness] Lightness addend
|
||||
* @returns {Sharp}
|
||||
*/
|
||||
function modulate (options) {
|
||||
if (!is.plainObject(options)) {
|
||||
throw is.invalidParameterError('options', 'plain object', options);
|
||||
}
|
||||
if ('brightness' in options) {
|
||||
if (is.number(options.brightness) && options.brightness >= 0) {
|
||||
this.options.brightness = options.brightness;
|
||||
} else {
|
||||
throw is.invalidParameterError('brightness', 'number above zero', options.brightness);
|
||||
}
|
||||
}
|
||||
if ('saturation' in options) {
|
||||
if (is.number(options.saturation) && options.saturation >= 0) {
|
||||
this.options.saturation = options.saturation;
|
||||
} else {
|
||||
throw is.invalidParameterError('saturation', 'number above zero', options.saturation);
|
||||
}
|
||||
}
|
||||
if ('hue' in options) {
|
||||
if (is.integer(options.hue)) {
|
||||
this.options.hue = options.hue % 360;
|
||||
} else {
|
||||
throw is.invalidParameterError('hue', 'number', options.hue);
|
||||
}
|
||||
}
|
||||
if ('lightness' in options) {
|
||||
if (is.number(options.lightness)) {
|
||||
this.options.lightness = options.lightness;
|
||||
} else {
|
||||
throw is.invalidParameterError('lightness', 'number', options.lightness);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with operation-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Object.assign(Sharp.prototype, {
|
||||
rotate,
|
||||
flip,
|
||||
flop,
|
||||
affine,
|
||||
sharpen,
|
||||
median,
|
||||
blur,
|
||||
flatten,
|
||||
unflatten,
|
||||
gamma,
|
||||
negate,
|
||||
normalise,
|
||||
normalize,
|
||||
clahe,
|
||||
convolve,
|
||||
threshold,
|
||||
boolean,
|
||||
linear,
|
||||
recomb,
|
||||
modulate
|
||||
});
|
||||
};
|
||||
1561
lib/output.js
Normal file
1561
lib/output.js
Normal file
File diff suppressed because it is too large
Load Diff
582
lib/resize.js
Normal file
582
lib/resize.js
Normal file
@@ -0,0 +1,582 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
/**
|
||||
* Weighting to apply when using contain/cover fit.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const gravity = {
|
||||
center: 0,
|
||||
centre: 0,
|
||||
north: 1,
|
||||
east: 2,
|
||||
south: 3,
|
||||
west: 4,
|
||||
northeast: 5,
|
||||
southeast: 6,
|
||||
southwest: 7,
|
||||
northwest: 8
|
||||
};
|
||||
|
||||
/**
|
||||
* Position to apply when using contain/cover fit.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const position = {
|
||||
top: 1,
|
||||
right: 2,
|
||||
bottom: 3,
|
||||
left: 4,
|
||||
'right top': 5,
|
||||
'right bottom': 6,
|
||||
'left bottom': 7,
|
||||
'left top': 8
|
||||
};
|
||||
|
||||
/**
|
||||
* How to extend the image.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const extendWith = {
|
||||
background: 'background',
|
||||
copy: 'copy',
|
||||
repeat: 'repeat',
|
||||
mirror: 'mirror'
|
||||
};
|
||||
|
||||
/**
|
||||
* Strategies for automagic cover behaviour.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const strategy = {
|
||||
entropy: 16,
|
||||
attention: 17
|
||||
};
|
||||
|
||||
/**
|
||||
* Reduction kernels.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const kernel = {
|
||||
nearest: 'nearest',
|
||||
cubic: 'cubic',
|
||||
mitchell: 'mitchell',
|
||||
lanczos2: 'lanczos2',
|
||||
lanczos3: 'lanczos3'
|
||||
};
|
||||
|
||||
/**
|
||||
* Methods by which an image can be resized to fit the provided dimensions.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const fit = {
|
||||
contain: 'contain',
|
||||
cover: 'cover',
|
||||
fill: 'fill',
|
||||
inside: 'inside',
|
||||
outside: 'outside'
|
||||
};
|
||||
|
||||
/**
|
||||
* Map external fit property to internal canvas property.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const mapFitToCanvas = {
|
||||
contain: 'embed',
|
||||
cover: 'crop',
|
||||
fill: 'ignore_aspect',
|
||||
inside: 'max',
|
||||
outside: 'min'
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function isRotationExpected (options) {
|
||||
return (options.angle % 360) !== 0 || options.useExifOrientation === true || options.rotationAngle !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function isResizeExpected (options) {
|
||||
return options.width !== -1 || options.height !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image to `width`, `height` or `width x height`.
|
||||
*
|
||||
* When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
||||
* - `cover`: (default) Preserving aspect ratio, attempt to ensure the image covers both provided dimensions by cropping/clipping to fit.
|
||||
* - `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
||||
* - `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
||||
* - `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
||||
* - `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
||||
*
|
||||
* Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
|
||||
*
|
||||
* <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.svg">
|
||||
*
|
||||
* When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
||||
* - `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
||||
* - `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
|
||||
* - `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
|
||||
*
|
||||
* Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
||||
*
|
||||
* The experimental strategy-based approach resizes so one dimension is at its target length
|
||||
* then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
||||
* - `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
||||
* - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
||||
*
|
||||
* Possible interpolation kernels are:
|
||||
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||
* - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
||||
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||
*
|
||||
* Only one resize can occur per pipeline.
|
||||
* Previous calls to `resize` in the same pipeline will be ignored.
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .resize({ width: 100 })
|
||||
* .toBuffer()
|
||||
* .then(data => {
|
||||
* // 100 pixels wide, auto-scaled height
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .resize({ height: 100 })
|
||||
* .toBuffer()
|
||||
* .then(data => {
|
||||
* // 100 pixels high, auto-scaled width
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .resize(200, 300, {
|
||||
* kernel: sharp.kernel.nearest,
|
||||
* fit: 'contain',
|
||||
* position: 'right top',
|
||||
* background: { r: 255, g: 255, b: 255, alpha: 0.5 }
|
||||
* })
|
||||
* .toFile('output.png')
|
||||
* .then(() => {
|
||||
* // output.png is a 200 pixels wide and 300 pixels high image
|
||||
* // containing a nearest-neighbour scaled version
|
||||
* // contained within the north-east corner of a semi-transparent white canvas
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* const transformer = sharp()
|
||||
* .resize({
|
||||
* width: 200,
|
||||
* height: 200,
|
||||
* fit: sharp.fit.cover,
|
||||
* position: sharp.strategy.entropy
|
||||
* });
|
||||
* // Read image data from readableStream
|
||||
* // Write 200px square auto-cropped image data to writableStream
|
||||
* readableStream
|
||||
* .pipe(transformer)
|
||||
* .pipe(writableStream);
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .resize(200, 200, {
|
||||
* fit: sharp.fit.inside,
|
||||
* withoutEnlargement: true
|
||||
* })
|
||||
* .toFormat('jpeg')
|
||||
* .toBuffer()
|
||||
* .then(function(outputBuffer) {
|
||||
* // outputBuffer contains JPEG image data
|
||||
* // no wider and no higher than 200 pixels
|
||||
* // and no larger than the input image
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .resize(200, 200, {
|
||||
* fit: sharp.fit.outside,
|
||||
* withoutReduction: true
|
||||
* })
|
||||
* .toFormat('jpeg')
|
||||
* .toBuffer()
|
||||
* .then(function(outputBuffer) {
|
||||
* // outputBuffer contains JPEG image data
|
||||
* // of at least 200 pixels wide and 200 pixels high while maintaining aspect ratio
|
||||
* // and no smaller than the input image
|
||||
* });
|
||||
*
|
||||
* @example
|
||||
* const scaleByHalf = await sharp(input)
|
||||
* .metadata()
|
||||
* .then(({ width }) => sharp(input)
|
||||
* .resize(Math.round(width * 0.5))
|
||||
* .toBuffer()
|
||||
* );
|
||||
*
|
||||
* @param {number} [width] - How many pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
||||
* @param {number} [height] - How many pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
||||
* @param {Object} [options]
|
||||
* @param {number} [options.width] - An alternative means of specifying `width`. If both are present this takes priority.
|
||||
* @param {number} [options.height] - An alternative means of specifying `height`. If both are present this takes priority.
|
||||
* @param {String} [options.fit='cover'] - How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`.
|
||||
* @param {String} [options.position='centre'] - A position, gravity or strategy to use when `fit` is `cover` or `contain`.
|
||||
* @param {String|Object} [options.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
||||
* @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.
|
||||
* @param {Boolean} [options.withoutEnlargement=false] - Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions.
|
||||
* @param {Boolean} [options.withoutReduction=false] - Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions.
|
||||
* @param {Boolean} [options.fastShrinkOnLoad=true] - Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function resize (widthOrOptions, height, options) {
|
||||
if (isResizeExpected(this.options)) {
|
||||
this.options.debuglog('ignoring previous resize options');
|
||||
}
|
||||
if (this.options.widthPost !== -1) {
|
||||
this.options.debuglog('operation order will be: extract, resize, extract');
|
||||
}
|
||||
if (is.defined(widthOrOptions)) {
|
||||
if (is.object(widthOrOptions) && !is.defined(options)) {
|
||||
options = widthOrOptions;
|
||||
} else if (is.integer(widthOrOptions) && widthOrOptions > 0) {
|
||||
this.options.width = widthOrOptions;
|
||||
} else {
|
||||
throw is.invalidParameterError('width', 'positive integer', widthOrOptions);
|
||||
}
|
||||
} else {
|
||||
this.options.width = -1;
|
||||
}
|
||||
if (is.defined(height)) {
|
||||
if (is.integer(height) && height > 0) {
|
||||
this.options.height = height;
|
||||
} else {
|
||||
throw is.invalidParameterError('height', 'positive integer', height);
|
||||
}
|
||||
} else {
|
||||
this.options.height = -1;
|
||||
}
|
||||
if (is.object(options)) {
|
||||
// Width
|
||||
if (is.defined(options.width)) {
|
||||
if (is.integer(options.width) && options.width > 0) {
|
||||
this.options.width = options.width;
|
||||
} else {
|
||||
throw is.invalidParameterError('width', 'positive integer', options.width);
|
||||
}
|
||||
}
|
||||
// Height
|
||||
if (is.defined(options.height)) {
|
||||
if (is.integer(options.height) && options.height > 0) {
|
||||
this.options.height = options.height;
|
||||
} else {
|
||||
throw is.invalidParameterError('height', 'positive integer', options.height);
|
||||
}
|
||||
}
|
||||
// Fit
|
||||
if (is.defined(options.fit)) {
|
||||
const canvas = mapFitToCanvas[options.fit];
|
||||
if (is.string(canvas)) {
|
||||
this.options.canvas = canvas;
|
||||
} else {
|
||||
throw is.invalidParameterError('fit', 'valid fit', options.fit);
|
||||
}
|
||||
}
|
||||
// Position
|
||||
if (is.defined(options.position)) {
|
||||
const pos = is.integer(options.position)
|
||||
? options.position
|
||||
: strategy[options.position] || position[options.position] || gravity[options.position];
|
||||
if (is.integer(pos) && (is.inRange(pos, 0, 8) || is.inRange(pos, 16, 17))) {
|
||||
this.options.position = pos;
|
||||
} else {
|
||||
throw is.invalidParameterError('position', 'valid position/gravity/strategy', options.position);
|
||||
}
|
||||
}
|
||||
// Background
|
||||
this._setBackgroundColourOption('resizeBackground', options.background);
|
||||
// Kernel
|
||||
if (is.defined(options.kernel)) {
|
||||
if (is.string(kernel[options.kernel])) {
|
||||
this.options.kernel = kernel[options.kernel];
|
||||
} else {
|
||||
throw is.invalidParameterError('kernel', 'valid kernel name', options.kernel);
|
||||
}
|
||||
}
|
||||
// Without enlargement
|
||||
if (is.defined(options.withoutEnlargement)) {
|
||||
this._setBooleanOption('withoutEnlargement', options.withoutEnlargement);
|
||||
}
|
||||
// Without reduction
|
||||
if (is.defined(options.withoutReduction)) {
|
||||
this._setBooleanOption('withoutReduction', options.withoutReduction);
|
||||
}
|
||||
// Shrink on load
|
||||
if (is.defined(options.fastShrinkOnLoad)) {
|
||||
this._setBooleanOption('fastShrinkOnLoad', options.fastShrinkOnLoad);
|
||||
}
|
||||
}
|
||||
if (isRotationExpected(this.options) && isResizeExpected(this.options)) {
|
||||
this.options.rotateBeforePreExtract = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend / pad / extrude one or more edges of the image with either
|
||||
* the provided background colour or pixels derived from the image.
|
||||
* This operation will always occur after resizing and extraction, if any.
|
||||
*
|
||||
* @example
|
||||
* // Resize to 140 pixels wide, then add 10 transparent pixels
|
||||
* // to the top, left and right edges and 20 to the bottom edge
|
||||
* sharp(input)
|
||||
* .resize(140)
|
||||
* .extend({
|
||||
* top: 10,
|
||||
* bottom: 20,
|
||||
* left: 10,
|
||||
* right: 10,
|
||||
* background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
* })
|
||||
* ...
|
||||
*
|
||||
* @example
|
||||
* // Add a row of 10 red pixels to the bottom
|
||||
* sharp(input)
|
||||
* .extend({
|
||||
* bottom: 10,
|
||||
* background: 'red'
|
||||
* })
|
||||
* ...
|
||||
*
|
||||
* @example
|
||||
* // Extrude image by 8 pixels to the right, mirroring existing right hand edge
|
||||
* sharp(input)
|
||||
* .extend({
|
||||
* right: 8,
|
||||
* background: 'mirror'
|
||||
* })
|
||||
* ...
|
||||
*
|
||||
* @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
|
||||
* @param {number} [extend.top=0]
|
||||
* @param {number} [extend.left=0]
|
||||
* @param {number} [extend.bottom=0]
|
||||
* @param {number} [extend.right=0]
|
||||
* @param {String} [extend.extendWith='background'] - populate new pixels using this method, one of: background, copy, repeat, mirror.
|
||||
* @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function extend (extend) {
|
||||
if (is.integer(extend) && extend > 0) {
|
||||
this.options.extendTop = extend;
|
||||
this.options.extendBottom = extend;
|
||||
this.options.extendLeft = extend;
|
||||
this.options.extendRight = extend;
|
||||
} else if (is.object(extend)) {
|
||||
if (is.defined(extend.top)) {
|
||||
if (is.integer(extend.top) && extend.top >= 0) {
|
||||
this.options.extendTop = extend.top;
|
||||
} else {
|
||||
throw is.invalidParameterError('top', 'positive integer', extend.top);
|
||||
}
|
||||
}
|
||||
if (is.defined(extend.bottom)) {
|
||||
if (is.integer(extend.bottom) && extend.bottom >= 0) {
|
||||
this.options.extendBottom = extend.bottom;
|
||||
} else {
|
||||
throw is.invalidParameterError('bottom', 'positive integer', extend.bottom);
|
||||
}
|
||||
}
|
||||
if (is.defined(extend.left)) {
|
||||
if (is.integer(extend.left) && extend.left >= 0) {
|
||||
this.options.extendLeft = extend.left;
|
||||
} else {
|
||||
throw is.invalidParameterError('left', 'positive integer', extend.left);
|
||||
}
|
||||
}
|
||||
if (is.defined(extend.right)) {
|
||||
if (is.integer(extend.right) && extend.right >= 0) {
|
||||
this.options.extendRight = extend.right;
|
||||
} else {
|
||||
throw is.invalidParameterError('right', 'positive integer', extend.right);
|
||||
}
|
||||
}
|
||||
this._setBackgroundColourOption('extendBackground', extend.background);
|
||||
if (is.defined(extend.extendWith)) {
|
||||
if (is.string(extendWith[extend.extendWith])) {
|
||||
this.options.extendWith = extendWith[extend.extendWith];
|
||||
} else {
|
||||
throw is.invalidParameterError('extendWith', 'one of: background, copy, repeat, mirror', extend.extendWith);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('extend', 'integer or object', extend);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract/crop a region of the image.
|
||||
*
|
||||
* - Use `extract` before `resize` for pre-resize extraction.
|
||||
* - Use `extract` after `resize` for post-resize extraction.
|
||||
* - Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order.
|
||||
*
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .extract({ left: left, top: top, width: width, height: height })
|
||||
* .toFile(output, function(err) {
|
||||
* // Extract a region of the input image, saving in the same format.
|
||||
* });
|
||||
* @example
|
||||
* sharp(input)
|
||||
* .extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
|
||||
* .resize(width, height)
|
||||
* .extract({ left: leftOffsetPost, top: topOffsetPost, width: widthPost, height: heightPost })
|
||||
* .toFile(output, function(err) {
|
||||
* // Extract a region, resize, then extract from the resized image
|
||||
* });
|
||||
*
|
||||
* @param {Object} options - describes the region to extract using integral pixel values
|
||||
* @param {number} options.left - zero-indexed offset from left edge
|
||||
* @param {number} options.top - zero-indexed offset from top edge
|
||||
* @param {number} options.width - width of region to extract
|
||||
* @param {number} options.height - height of region to extract
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function extract (options) {
|
||||
const suffix = isResizeExpected(this.options) || this.options.widthPre !== -1 ? 'Post' : 'Pre';
|
||||
if (this.options[`width${suffix}`] !== -1) {
|
||||
this.options.debuglog('ignoring previous extract options');
|
||||
}
|
||||
['left', 'top', 'width', 'height'].forEach(function (name) {
|
||||
const value = options[name];
|
||||
if (is.integer(value) && value >= 0) {
|
||||
this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
|
||||
} else {
|
||||
throw is.invalidParameterError(name, 'integer', value);
|
||||
}
|
||||
}, this);
|
||||
// Ensure existing rotation occurs before pre-resize extraction
|
||||
if (isRotationExpected(this.options) && !isResizeExpected(this.options)) {
|
||||
if (this.options.widthPre === -1 || this.options.widthPost === -1) {
|
||||
this.options.rotateBeforePreExtract = true;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
||||
*
|
||||
* Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
|
||||
*
|
||||
* If the result of this operation would trim an image to nothing then no change is made.
|
||||
*
|
||||
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||
*
|
||||
* @example
|
||||
* // Trim pixels with a colour similar to that of the top-left pixel.
|
||||
* await sharp(input)
|
||||
* .trim()
|
||||
* .toFile(output);
|
||||
*
|
||||
* @example
|
||||
* // Trim pixels with the exact same colour as that of the top-left pixel.
|
||||
* await sharp(input)
|
||||
* .trim({
|
||||
* threshold: 0
|
||||
* })
|
||||
* .toFile(output);
|
||||
*
|
||||
* @example
|
||||
* // Assume input is line art and trim only pixels with a similar colour to red.
|
||||
* const output = await sharp(input)
|
||||
* .trim({
|
||||
* background: "#FF0000",
|
||||
* lineArt: true
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
||||
* const output = await sharp(input)
|
||||
* .trim({
|
||||
* background: "yellow",
|
||||
* threshold: 42,
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
|
||||
* @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
|
||||
* @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function trim (options) {
|
||||
this.options.trimThreshold = 10;
|
||||
if (is.defined(options)) {
|
||||
if (is.object(options)) {
|
||||
if (is.defined(options.background)) {
|
||||
this._setBackgroundColourOption('trimBackground', options.background);
|
||||
}
|
||||
if (is.defined(options.threshold)) {
|
||||
if (is.number(options.threshold) && options.threshold >= 0) {
|
||||
this.options.trimThreshold = options.threshold;
|
||||
} else {
|
||||
throw is.invalidParameterError('threshold', 'positive number', options.threshold);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.lineArt)) {
|
||||
this._setBooleanOption('trimLineArt', options.lineArt);
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('trim', 'object', options);
|
||||
}
|
||||
}
|
||||
if (isRotationExpected(this.options)) {
|
||||
this.options.rotateBeforePreExtract = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with resize-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Object.assign(Sharp.prototype, {
|
||||
resize,
|
||||
extend,
|
||||
extract,
|
||||
trim
|
||||
});
|
||||
// Class attributes
|
||||
Sharp.gravity = gravity;
|
||||
Sharp.strategy = strategy;
|
||||
Sharp.kernel = kernel;
|
||||
Sharp.fit = fit;
|
||||
Sharp.position = position;
|
||||
};
|
||||
115
lib/sharp.js
Normal file
115
lib/sharp.js
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
// Inspects the runtime environment and exports the relevant sharp.node binary
|
||||
|
||||
const { familySync, versionSync } = require('detect-libc');
|
||||
|
||||
const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
||||
const runtimePlatform = runtimePlatformArch();
|
||||
|
||||
const paths = [
|
||||
`../src/build/Release/sharp-${runtimePlatform}.node`,
|
||||
'../src/build/Release/sharp-wasm32.node',
|
||||
`@img/sharp-${runtimePlatform}/sharp.node`,
|
||||
'@img/sharp-wasm32/sharp.node'
|
||||
];
|
||||
|
||||
let sharp;
|
||||
const errors = [];
|
||||
for (const path of paths) {
|
||||
try {
|
||||
sharp = require(path);
|
||||
break;
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
errors.push(err);
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (sharp) {
|
||||
module.exports = sharp;
|
||||
} else {
|
||||
const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
|
||||
|
||||
const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
|
||||
errors.forEach(err => {
|
||||
if (err.code !== 'MODULE_NOT_FOUND') {
|
||||
help.push(`${err.code}: ${err.message}`);
|
||||
}
|
||||
});
|
||||
const messages = errors.map(err => err.message).join(' ');
|
||||
help.push('Possible solutions:');
|
||||
// Common error messages
|
||||
if (isUnsupportedNodeRuntime()) {
|
||||
const { found, expected } = isUnsupportedNodeRuntime();
|
||||
help.push(
|
||||
'- Please upgrade Node.js:',
|
||||
` Found ${found}`,
|
||||
` Requires ${expected}`
|
||||
);
|
||||
} else if (prebuiltPlatforms.includes(runtimePlatform)) {
|
||||
const [os, cpu] = runtimePlatform.split('-');
|
||||
const libc = os.endsWith('musl') ? ' --libc=musl' : '';
|
||||
help.push(
|
||||
'- Ensure optional dependencies can be installed:',
|
||||
' npm install --include=optional sharp',
|
||||
' yarn add sharp --ignore-engines',
|
||||
'- Ensure your package manager supports multi-platform installation:',
|
||||
' See https://sharp.pixelplumbing.com/install#cross-platform',
|
||||
'- Add platform-specific dependencies:',
|
||||
` npm install --os=${os.replace('musl', '')}${libc} --cpu=${cpu} sharp`
|
||||
);
|
||||
} else {
|
||||
help.push(
|
||||
`- Manually install libvips >= ${minimumLibvipsVersion}`,
|
||||
'- Add experimental WebAssembly-based dependencies:',
|
||||
' npm install --cpu=wasm32 sharp',
|
||||
' npm install @img/sharp-wasm32'
|
||||
);
|
||||
}
|
||||
if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
|
||||
try {
|
||||
const { engines } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
|
||||
const libcFound = `${familySync()} ${versionSync()}`;
|
||||
const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`;
|
||||
help.push(
|
||||
'- Update your OS:',
|
||||
` Found ${libcFound}`,
|
||||
` Requires ${libcRequires}`
|
||||
);
|
||||
} catch (errEngines) {}
|
||||
}
|
||||
if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
|
||||
help.push(
|
||||
'- Remove the Node.js Snap, which does not support native modules',
|
||||
' snap remove node'
|
||||
);
|
||||
}
|
||||
if (isMacOs && /Incompatible library version/.test(messages)) {
|
||||
help.push(
|
||||
'- Update Homebrew:',
|
||||
' brew update && brew upgrade vips'
|
||||
);
|
||||
}
|
||||
if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
|
||||
help.push('- Run Node.js without using the --no-addons flag');
|
||||
}
|
||||
// Link to installation docs
|
||||
if (isWindows && /The specified procedure could not be found/.test(messages)) {
|
||||
help.push(
|
||||
'- Using the canvas package on Windows?',
|
||||
' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
|
||||
'- Check for outdated versions of sharp in the dependency tree:',
|
||||
' npm ls sharp'
|
||||
);
|
||||
}
|
||||
help.push(
|
||||
'- Consult the installation documentation:',
|
||||
' See https://sharp.pixelplumbing.com/install'
|
||||
);
|
||||
throw new Error(help.join('\n'));
|
||||
}
|
||||
286
lib/utility.js
Normal file
286
lib/utility.js
Normal file
@@ -0,0 +1,286 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const events = require('node:events');
|
||||
const detectLibc = require('detect-libc');
|
||||
|
||||
const is = require('./is');
|
||||
const { runtimePlatformArch } = require('./libvips');
|
||||
const sharp = require('./sharp');
|
||||
|
||||
const runtimePlatform = runtimePlatformArch();
|
||||
const libvipsVersion = sharp.libvipsVersion();
|
||||
|
||||
/**
|
||||
* An Object containing nested boolean values representing the available input and output formats/methods.
|
||||
* @member
|
||||
* @example
|
||||
* console.log(sharp.format);
|
||||
* @returns {Object}
|
||||
*/
|
||||
const format = sharp.format();
|
||||
format.heif.output.alias = ['avif', 'heic'];
|
||||
format.jpeg.output.alias = ['jpe', 'jpg'];
|
||||
format.tiff.output.alias = ['tif'];
|
||||
format.jp2k.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
|
||||
|
||||
/**
|
||||
* An Object containing the available interpolators and their proper values
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
const interpolators = {
|
||||
/** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
|
||||
nearest: 'nearest',
|
||||
/** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
|
||||
bilinear: 'bilinear',
|
||||
/** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
|
||||
bicubic: 'bicubic',
|
||||
/** [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. */
|
||||
locallyBoundedBicubic: 'lbb',
|
||||
/** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
|
||||
nohalo: 'nohalo',
|
||||
/** [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
|
||||
vertexSplitQuadraticBasisSpline: 'vsqbs'
|
||||
};
|
||||
|
||||
/**
|
||||
* An Object containing the version numbers of sharp, libvips
|
||||
* and (when using prebuilt binaries) its dependencies.
|
||||
*
|
||||
* @member
|
||||
* @example
|
||||
* console.log(sharp.versions);
|
||||
*/
|
||||
let versions = {
|
||||
vips: libvipsVersion.semver
|
||||
};
|
||||
/* istanbul ignore next */
|
||||
if (!libvipsVersion.isGlobal) {
|
||||
if (!libvipsVersion.isWasm) {
|
||||
try {
|
||||
versions = require(`@img/sharp-${runtimePlatform}/versions`);
|
||||
} catch (_) {
|
||||
try {
|
||||
versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
|
||||
} catch (_) {}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
versions = require('@img/sharp-wasm32/versions');
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
versions.sharp = require('../package.json').version;
|
||||
|
||||
/**
|
||||
* Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
||||
* Existing entries in the cache will be trimmed after any change in limits.
|
||||
* This method always returns cache statistics,
|
||||
* useful for determining how much working memory is required for a particular task.
|
||||
*
|
||||
* @example
|
||||
* const stats = sharp.cache();
|
||||
* @example
|
||||
* sharp.cache( { items: 200 } );
|
||||
* sharp.cache( { files: 0 } );
|
||||
* sharp.cache(false);
|
||||
*
|
||||
* @param {Object|boolean} [options=true] - Object with the following attributes, or boolean where true uses default cache settings and false removes all caching
|
||||
* @param {number} [options.memory=50] - is the maximum memory in MB to use for this cache
|
||||
* @param {number} [options.files=20] - is the maximum number of files to hold open
|
||||
* @param {number} [options.items=100] - is the maximum number of operations to cache
|
||||
* @returns {Object}
|
||||
*/
|
||||
function cache (options) {
|
||||
if (is.bool(options)) {
|
||||
if (options) {
|
||||
// Default cache settings of 50MB, 20 files, 100 items
|
||||
return sharp.cache(50, 20, 100);
|
||||
} else {
|
||||
return sharp.cache(0, 0, 0);
|
||||
}
|
||||
} else if (is.object(options)) {
|
||||
return sharp.cache(options.memory, options.files, options.items);
|
||||
} else {
|
||||
return sharp.cache();
|
||||
}
|
||||
}
|
||||
cache(true);
|
||||
|
||||
/**
|
||||
* Gets or, when a concurrency is provided, sets
|
||||
* the maximum number of threads _libvips_ should use to process _each image_.
|
||||
* These are from a thread pool managed by glib,
|
||||
* which helps avoid the overhead of creating new threads.
|
||||
*
|
||||
* This method always returns the current concurrency.
|
||||
*
|
||||
* The default value is the number of CPU cores,
|
||||
* except when using glibc-based Linux without jemalloc,
|
||||
* where the default is `1` to help reduce memory fragmentation.
|
||||
*
|
||||
* A value of `0` will reset this to the number of CPU cores.
|
||||
*
|
||||
* Some image format libraries spawn additional threads,
|
||||
* e.g. libaom manages its own 4 threads when encoding AVIF images,
|
||||
* and these are independent of the value set here.
|
||||
*
|
||||
* The maximum number of images that sharp can process in parallel
|
||||
* is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
|
||||
* which defaults to 4.
|
||||
*
|
||||
* https://nodejs.org/api/cli.html#uv_threadpool_sizesize
|
||||
*
|
||||
* For example, by default, a machine with 8 CPU cores will process
|
||||
* 4 images in parallel and use up to 8 threads per image,
|
||||
* so there will be up to 32 concurrent threads.
|
||||
*
|
||||
* @example
|
||||
* const threads = sharp.concurrency(); // 4
|
||||
* sharp.concurrency(2); // 2
|
||||
* sharp.concurrency(0); // 4
|
||||
*
|
||||
* @param {number} [concurrency]
|
||||
* @returns {number} concurrency
|
||||
*/
|
||||
function concurrency (concurrency) {
|
||||
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
|
||||
// Reduce default concurrency to 1 when using glibc memory allocator
|
||||
sharp.concurrency(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* An EventEmitter that emits a `change` event when a task is either:
|
||||
* - queued, waiting for _libuv_ to provide a worker thread
|
||||
* - complete
|
||||
* @member
|
||||
* @example
|
||||
* sharp.queue.on('change', function(queueLength) {
|
||||
* console.log('Queue contains ' + queueLength + ' task(s)');
|
||||
* });
|
||||
*/
|
||||
const queue = new events.EventEmitter();
|
||||
|
||||
/**
|
||||
* Provides access to internal task counters.
|
||||
* - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
|
||||
* - process is the number of resize tasks currently being processed.
|
||||
*
|
||||
* @example
|
||||
* const counters = sharp.counters(); // { queue: 2, process: 4 }
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
function counters () {
|
||||
return sharp.counters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set use of SIMD vector unit instructions.
|
||||
* Requires libvips to have been compiled with highway support.
|
||||
*
|
||||
* Improves the performance of `resize`, `blur` and `sharpen` operations
|
||||
* by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||
*
|
||||
* @example
|
||||
* const simd = sharp.simd();
|
||||
* // simd is `true` if the runtime use of highway is currently enabled
|
||||
* @example
|
||||
* const simd = sharp.simd(false);
|
||||
* // prevent libvips from using highway at runtime
|
||||
*
|
||||
* @param {boolean} [simd=true]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function simd (simd) {
|
||||
return sharp.simd(is.bool(simd) ? simd : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Block libvips operations at runtime.
|
||||
*
|
||||
* This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
|
||||
* which when set will block all "untrusted" operations.
|
||||
*
|
||||
* @since 0.32.4
|
||||
*
|
||||
* @example <caption>Block all TIFF input.</caption>
|
||||
* sharp.block({
|
||||
* operation: ['VipsForeignLoadTiff']
|
||||
* });
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Array<string>} options.operation - List of libvips low-level operation names to block.
|
||||
*/
|
||||
function block (options) {
|
||||
if (is.object(options)) {
|
||||
if (Array.isArray(options.operation) && options.operation.every(is.string)) {
|
||||
sharp.block(options.operation, true);
|
||||
} else {
|
||||
throw is.invalidParameterError('operation', 'Array<string>', options.operation);
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('options', 'object', options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unblock libvips operations at runtime.
|
||||
*
|
||||
* This is useful for defining a list of allowed operations.
|
||||
*
|
||||
* @since 0.32.4
|
||||
*
|
||||
* @example <caption>Block all input except WebP from the filesystem.</caption>
|
||||
* sharp.block({
|
||||
* operation: ['VipsForeignLoad']
|
||||
* });
|
||||
* sharp.unblock({
|
||||
* operation: ['VipsForeignLoadWebpFile']
|
||||
* });
|
||||
*
|
||||
* @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
|
||||
* sharp.block({
|
||||
* operation: ['VipsForeignLoad']
|
||||
* });
|
||||
* sharp.unblock({
|
||||
* operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
|
||||
* });
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
|
||||
*/
|
||||
function unblock (options) {
|
||||
if (is.object(options)) {
|
||||
if (Array.isArray(options.operation) && options.operation.every(is.string)) {
|
||||
sharp.block(options.operation, false);
|
||||
} else {
|
||||
throw is.invalidParameterError('operation', 'Array<string>', options.operation);
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('options', 'object', options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate the Sharp class with utility-related functions.
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
Sharp.cache = cache;
|
||||
Sharp.concurrency = concurrency;
|
||||
Sharp.counters = counters;
|
||||
Sharp.simd = simd;
|
||||
Sharp.format = format;
|
||||
Sharp.interpolators = interpolators;
|
||||
Sharp.versions = versions;
|
||||
Sharp.queue = queue;
|
||||
Sharp.block = block;
|
||||
Sharp.unblock = unblock;
|
||||
};
|
||||
17
mkdocs.yml
17
mkdocs.yml
@@ -1,17 +0,0 @@
|
||||
site_name: sharp
|
||||
site_url: http://sharp.dimens.io/
|
||||
repo_url: https://github.com/lovell/sharp
|
||||
site_description: The fastest Node.js module for resizing JPEG, PNG, WebP and TIFF images. Uses the libvips library.
|
||||
copyright: <a href="https://dimens.io/">dimens.io</a>
|
||||
google_analytics: ['UA-13034748-12', 'sharp.dimens.io']
|
||||
theme: readthedocs
|
||||
markdown_extensions:
|
||||
- toc:
|
||||
permalink: True
|
||||
dev_addr: 0.0.0.0:10101
|
||||
pages:
|
||||
- Home: index.md
|
||||
- Installation: install.md
|
||||
- API: api.md
|
||||
- Performance: performance.md
|
||||
- Changelog: changelog.md
|
||||
44
npm/darwin-arm64/package.json
Normal file
44
npm/darwin-arm64/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@img/sharp-darwin-arm64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with macOS 64-bit ARM",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/darwin-arm64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-darwin-arm64": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-darwin-arm64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"glibc": ">=2.26"
|
||||
},
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
]
|
||||
}
|
||||
44
npm/darwin-x64/package.json
Normal file
44
npm/darwin-x64/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@img/sharp-darwin-x64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with macOS x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/darwin-x64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-darwin-x64": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-darwin-x64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"glibc": ">=2.26"
|
||||
},
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
73
npm/from-github-release.js
Normal file
73
npm/from-github-release.js
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
// Populate contents of all packages with the current GitHub release
|
||||
|
||||
const { readFile, writeFile, appendFile, copyFile, rm } = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const { Readable } = require('node:stream');
|
||||
const { pipeline } = require('node:stream/promises');
|
||||
const { createGunzip } = require('node:zlib');
|
||||
const { extract } = require('tar-fs');
|
||||
|
||||
const { workspaces } = require('./package.json');
|
||||
const { version } = require('../package.json');
|
||||
|
||||
const mapTarballEntry = (header) => {
|
||||
header.name = path.basename(header.name);
|
||||
return header;
|
||||
};
|
||||
|
||||
const licensing = `
|
||||
## Licensing
|
||||
|
||||
Copyright 2013 Lovell Fuller and others.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
`;
|
||||
|
||||
workspaces.map(async platform => {
|
||||
const prebuildPlatform = platform === 'wasm32' ? 'emscripten-wasm32' : platform;
|
||||
const url = `https://github.com/lovell/sharp/releases/download/v${version}/sharp-v${version}-napi-v9-${prebuildPlatform}.tar.gz`;
|
||||
const dir = path.join(__dirname, platform);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
console.log(`Skipping ${platform}: ${response.statusText}`);
|
||||
return;
|
||||
}
|
||||
// Extract prebuild tarball
|
||||
const lib = path.join(dir, 'lib');
|
||||
await rm(lib, { force: true, recursive: true });
|
||||
await pipeline(
|
||||
Readable.fromWeb(response.body),
|
||||
createGunzip(),
|
||||
extract(lib, { map: mapTarballEntry })
|
||||
);
|
||||
// Generate README
|
||||
const { name, description } = require(`./${platform}/package.json`);
|
||||
await writeFile(path.join(dir, 'README.md'), `# \`${name}\`\n\n${description}.\n${licensing}`);
|
||||
// Copy Apache-2.0 LICENSE
|
||||
await copyFile(path.join(__dirname, '..', 'LICENSE'), path.join(dir, 'LICENSE'));
|
||||
// Copy files for packages without an explicit sharp-libvips dependency (Windows, wasm)
|
||||
if (platform.startsWith('win') || platform.startsWith('wasm')) {
|
||||
const libvipsPlatform = platform === 'wasm32' ? 'dev-wasm32' : platform;
|
||||
const sharpLibvipsDir = path.join(require(`@img/sharp-libvips-${libvipsPlatform}/lib`), '..');
|
||||
// Copy versions.json
|
||||
await copyFile(path.join(sharpLibvipsDir, 'versions.json'), path.join(dir, 'versions.json'));
|
||||
// Append third party licensing to README
|
||||
const readme = await readFile(path.join(sharpLibvipsDir, 'README.md'), { encoding: 'utf-8' });
|
||||
const thirdParty = readme.substring(readme.indexOf('\nThis software contains'));
|
||||
appendFile(path.join(dir, 'README.md'), thirdParty);
|
||||
}
|
||||
});
|
||||
26
npm/from-local-build.js
Normal file
26
npm/from-local-build.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
// Populate contents of a single npm/sharpen-sharp-<build-platform> package
|
||||
// with the local/CI build directory for local/CI prebuild testing
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const { buildPlatformArch } = require('../lib/libvips');
|
||||
const platform = buildPlatformArch();
|
||||
const dest = path.join(__dirname, platform);
|
||||
|
||||
// Use same config as prebuild to copy binary files
|
||||
const release = path.join(__dirname, '..', 'src', 'build', 'Release');
|
||||
const prebuildrc = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '.prebuildrc'), 'utf8'));
|
||||
const include = new RegExp(prebuildrc['include-regex'], 'i');
|
||||
fs.cpSync(release, path.join(dest, 'lib'), {
|
||||
recursive: true,
|
||||
filter: (file) => {
|
||||
const name = path.basename(file);
|
||||
return name === 'Release' || include.test(name);
|
||||
}
|
||||
});
|
||||
47
npm/linux-arm/package.json
Normal file
47
npm/linux-arm/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-arm",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linux-arm"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-arm": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linux-arm.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"glibc": ">=2.28"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"cpu": [
|
||||
"arm"
|
||||
]
|
||||
}
|
||||
47
npm/linux-arm64/package.json
Normal file
47
npm/linux-arm64/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-arm64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linux-arm64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-arm64": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linux-arm64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"glibc": ">=2.26"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
]
|
||||
}
|
||||
47
npm/linux-s390x/package.json
Normal file
47
npm/linux-s390x/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-s390x",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) s390x",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linux-s390x"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-s390x": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linux-s390x.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"glibc": ">=2.28"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"cpu": [
|
||||
"s390x"
|
||||
]
|
||||
}
|
||||
47
npm/linux-x64/package.json
Normal file
47
npm/linux-x64/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-x64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linux-x64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-x64": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linux-x64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"glibc": ">=2.26"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
47
npm/linuxmusl-arm64/package.json
Normal file
47
npm/linuxmusl-arm64/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@img/sharp-linuxmusl-arm64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linuxmusl-arm64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linuxmusl-arm64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"musl": ">=1.2.2"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
]
|
||||
}
|
||||
47
npm/linuxmusl-x64/package.json
Normal file
47
npm/linuxmusl-x64/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@img/sharp-linuxmusl-x64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Linux (musl) x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linuxmusl-x64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.0.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linuxmusl-x64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0",
|
||||
"musl": ">=1.2.2"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
18
npm/package.json
Normal file
18
npm/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@img/sharp",
|
||||
"version": "0.33.2",
|
||||
"private": "true",
|
||||
"workspaces": [
|
||||
"darwin-arm64",
|
||||
"darwin-x64",
|
||||
"linux-arm",
|
||||
"linux-arm64",
|
||||
"linux-s390x",
|
||||
"linux-x64",
|
||||
"linuxmusl-arm64",
|
||||
"linuxmusl-x64",
|
||||
"wasm32",
|
||||
"win32-ia32",
|
||||
"win32-x64"
|
||||
]
|
||||
}
|
||||
42
npm/wasm32/package.json
Normal file
42
npm/wasm32/package.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@img/sharp-wasm32",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with wasm32",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/wasm32"
|
||||
},
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"files": [
|
||||
"lib",
|
||||
"versions.json"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-wasm32.node.js",
|
||||
"./package": "./package.json",
|
||||
"./versions": "./versions.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emnapi/runtime": "^0.45.0"
|
||||
},
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
]
|
||||
}
|
||||
42
npm/win32-ia32/package.json
Normal file
42
npm/win32-ia32/package.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@img/sharp-win32-ia32",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Windows x86 (32-bit)",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/win32-ia32"
|
||||
},
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"files": [
|
||||
"lib",
|
||||
"versions.json"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-win32-ia32.node",
|
||||
"./package": "./package.json",
|
||||
"./versions": "./versions.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0"
|
||||
},
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"cpu": [
|
||||
"ia32"
|
||||
]
|
||||
}
|
||||
42
npm/win32-x64/package.json
Normal file
42
npm/win32-x64/package.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@img/sharp-win32-x64",
|
||||
"version": "0.33.2",
|
||||
"description": "Prebuilt sharp for use with Windows x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/win32-x64"
|
||||
},
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"files": [
|
||||
"lib",
|
||||
"versions.json"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-win32-x64.node",
|
||||
"./package": "./package.json",
|
||||
"./versions": "./versions.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"npm": ">=9.6.5",
|
||||
"yarn": ">=3.2.0",
|
||||
"pnpm": ">=7.1.0"
|
||||
},
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
197
package.json
197
package.json
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"name": "sharp",
|
||||
"version": "0.15.0",
|
||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
||||
"version": "0.33.2",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"contributors": [
|
||||
"Pierre Inglebert <pierre.inglebert@gmail.com>",
|
||||
"Jonathan Ong <jonathanrichardong@gmail.com>",
|
||||
@@ -22,63 +24,196 @@
|
||||
"John Tobin <john@limelightmobileinc.com>",
|
||||
"Kenton Gray <kentongray@gmail.com>",
|
||||
"Felix Bünemann <Felix.Buenemann@gmail.com>",
|
||||
"Samy Al Zahrani <samyalzahrany@gmail.com>"
|
||||
"Samy Al Zahrani <samyalzahrany@gmail.com>",
|
||||
"Chintan Thakkar <lemnisk8@gmail.com>",
|
||||
"F. Orlando Galashan <frulo@gmx.de>",
|
||||
"Kleis Auke Wolthuizen <info@kleisauke.nl>",
|
||||
"Matt Hirsch <mhirsch@media.mit.edu>",
|
||||
"Matthias Thoemmes <thoemmes@gmail.com>",
|
||||
"Patrick Paskaris <patrick@paskaris.gr>",
|
||||
"Jérémy Lal <kapouer@melix.org>",
|
||||
"Rahul Nanwani <r.nanwani@gmail.com>",
|
||||
"Alice Monday <alice0meta@gmail.com>",
|
||||
"Kristo Jorgenson <kristo.jorgenson@gmail.com>",
|
||||
"YvesBos <yves_bos@outlook.com>",
|
||||
"Guy Maliar <guy@tailorbrands.com>",
|
||||
"Nicolas Coden <nicolas@ncoden.fr>",
|
||||
"Matt Parrish <matt.r.parrish@gmail.com>",
|
||||
"Marcel Bretschneider <marcel.bretschneider@gmail.com>",
|
||||
"Matthew McEachen <matthew+github@mceachen.org>",
|
||||
"Jarda Kotěšovec <jarda.kotesovec@gmail.com>",
|
||||
"Kenric D'Souza <kenric.dsouza@gmail.com>",
|
||||
"Oleh Aleinyk <oleg.aleynik@gmail.com>",
|
||||
"Marcel Bretschneider <marcel.bretschneider@gmail.com>",
|
||||
"Andrea Bianco <andrea.bianco@unibas.ch>",
|
||||
"Rik Heywood <rik@rik.org>",
|
||||
"Thomas Parisot <hi@oncletom.io>",
|
||||
"Nathan Graves <nathanrgraves+github@gmail.com>",
|
||||
"Tom Lokhorst <tom@lokhorst.eu>",
|
||||
"Espen Hovlandsdal <espen@hovlandsdal.com>",
|
||||
"Sylvain Dumont <sylvain.dumont35@gmail.com>",
|
||||
"Alun Davies <alun.owain.davies@googlemail.com>",
|
||||
"Aidan Hoolachan <ajhoolachan21@gmail.com>",
|
||||
"Axel Eirola <axel.eirola@iki.fi>",
|
||||
"Freezy <freezy@xbmc.org>",
|
||||
"Daiz <taneli.vatanen@gmail.com>",
|
||||
"Julian Aubourg <j@ubourg.net>",
|
||||
"Keith Belovay <keith@picthrive.com>",
|
||||
"Michael B. Klein <mbklein@gmail.com>",
|
||||
"Jordan Prudhomme <jordan@raboland.fr>",
|
||||
"Ilya Ovdin <iovdin@gmail.com>",
|
||||
"Andargor <andargor@yahoo.com>",
|
||||
"Paul Neave <paul.neave@gmail.com>",
|
||||
"Brendan Kennedy <brenwken@gmail.com>",
|
||||
"Brychan Bennett-Odlum <git@brychan.io>",
|
||||
"Edward Silverton <e.silverton@gmail.com>",
|
||||
"Roman Malieiev <aromaleev@gmail.com>",
|
||||
"Tomas Szabo <tomas.szabo@deftomat.com>",
|
||||
"Robert O'Rourke <robert@o-rourke.org>",
|
||||
"Guillermo Alfonso Varela Chouciño <guillevch@gmail.com>",
|
||||
"Christian Flintrup <chr@gigahost.dk>",
|
||||
"Manan Jadhav <manan@motionden.com>",
|
||||
"Leon Radley <leon@radley.se>",
|
||||
"alza54 <alza54@thiocod.in>",
|
||||
"Jacob Smith <jacob@frende.me>",
|
||||
"Michael Nutt <michael@nutt.im>",
|
||||
"Brad Parham <baparham@gmail.com>",
|
||||
"Taneli Vatanen <taneli.vatanen@gmail.com>",
|
||||
"Joris Dugué <zaruike10@gmail.com>",
|
||||
"Chris Banks <christopher.bradley.banks@gmail.com>",
|
||||
"Ompal Singh <ompal.hitm09@gmail.com>",
|
||||
"Brodan <christopher.hranj@gmail.com",
|
||||
"Ankur Parihar <ankur.github@gmail.com>",
|
||||
"Brahim Ait elhaj <brahima@gmail.com>",
|
||||
"Mart Jansink <m.jansink@gmail.com>",
|
||||
"Lachlan Newman <lachnewman007@gmail.com>",
|
||||
"Dennis Beatty <dennis@dcbeatty.com>",
|
||||
"Ingvar Stepanyan <me@rreverser.com>"
|
||||
],
|
||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
||||
"scripts": {
|
||||
"clean": "rm -rf node_modules/ build/ include/ lib/ coverage/ test/fixtures/output.*",
|
||||
"test": "VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=30000 ./test/unit/*.js",
|
||||
"test-win": "node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
||||
"install": "node install/check",
|
||||
"clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
|
||||
"test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
|
||||
"test-lint": "semistandard && cpplint",
|
||||
"test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
|
||||
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
|
||||
"test-leak": "./test/leak/leak.sh",
|
||||
"test-packaging": "./packaging/test.sh",
|
||||
"test-clean": "rm -rf coverage/ test/fixtures/output.* && npm install && npm test"
|
||||
"test-types": "tsd",
|
||||
"package-from-local-build": "node npm/from-local-build",
|
||||
"package-from-github-release": "node npm/from-github-release",
|
||||
"docs-build": "node docs/build && node docs/search-index/build",
|
||||
"docs-serve": "cd docs && npx serve",
|
||||
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
||||
},
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"files": [
|
||||
"install",
|
||||
"lib",
|
||||
"src/*.{cc,h,gyp}"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/lovell/sharp"
|
||||
"url": "git://github.com/lovell/sharp.git"
|
||||
},
|
||||
"keywords": [
|
||||
"jpeg",
|
||||
"png",
|
||||
"webp",
|
||||
"avif",
|
||||
"tiff",
|
||||
"gif",
|
||||
"svg",
|
||||
"jp2",
|
||||
"dzi",
|
||||
"image",
|
||||
"resize",
|
||||
"thumbnail",
|
||||
"crop",
|
||||
"embed",
|
||||
"libvips",
|
||||
"vips"
|
||||
],
|
||||
"dependencies": {
|
||||
"bluebird": "^3.3.5",
|
||||
"color": "^0.11.1",
|
||||
"nan": "^2.2.1",
|
||||
"semver": "^5.1.0",
|
||||
"request": "^2.71.0",
|
||||
"tar": "^2.2.1"
|
||||
"color": "^4.2.3",
|
||||
"detect-libc": "^2.0.2",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-darwin-arm64": "0.33.2",
|
||||
"@img/sharp-darwin-x64": "0.33.2",
|
||||
"@img/sharp-libvips-darwin-arm64": "1.0.1",
|
||||
"@img/sharp-libvips-darwin-x64": "1.0.1",
|
||||
"@img/sharp-libvips-linux-arm": "1.0.1",
|
||||
"@img/sharp-libvips-linux-arm64": "1.0.1",
|
||||
"@img/sharp-libvips-linux-s390x": "1.0.1",
|
||||
"@img/sharp-libvips-linux-x64": "1.0.1",
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.0.1",
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.0.1",
|
||||
"@img/sharp-linux-arm": "0.33.2",
|
||||
"@img/sharp-linux-arm64": "0.33.2",
|
||||
"@img/sharp-linux-s390x": "0.33.2",
|
||||
"@img/sharp-linux-x64": "0.33.2",
|
||||
"@img/sharp-linuxmusl-arm64": "0.33.2",
|
||||
"@img/sharp-linuxmusl-x64": "0.33.2",
|
||||
"@img/sharp-wasm32": "0.33.2",
|
||||
"@img/sharp-win32-ia32": "0.33.2",
|
||||
"@img/sharp-win32-x64": "0.33.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "^1.5.2",
|
||||
"bufferutil": "^1.2.1",
|
||||
"coveralls": "^2.11.9",
|
||||
"exif-reader": "^1.0.0",
|
||||
"icc": "^0.0.2",
|
||||
"istanbul": "^0.4.3",
|
||||
"mocha": "^2.4.5",
|
||||
"mocha-jshint": "^2.3.1",
|
||||
"node-cpplint": "^0.4.0",
|
||||
"rimraf": "^2.5.2",
|
||||
"unzip": "^0.1.11"
|
||||
"@emnapi/runtime": "^0.45.0",
|
||||
"@img/sharp-libvips-dev": "1.0.1",
|
||||
"@img/sharp-libvips-dev-wasm32": "1.0.1",
|
||||
"@img/sharp-libvips-win32-ia32": "1.0.1",
|
||||
"@img/sharp-libvips-win32-x64": "1.0.1",
|
||||
"@types/node": "*",
|
||||
"async": "^3.2.5",
|
||||
"cc": "^3.0.1",
|
||||
"emnapi": "^0.45.0",
|
||||
"exif-reader": "^2.0.0",
|
||||
"extract-zip": "^2.0.1",
|
||||
"icc": "^3.0.0",
|
||||
"jsdoc-to-markdown": "^8.0.0",
|
||||
"license-checker": "^25.0.1",
|
||||
"mocha": "^10.2.0",
|
||||
"node-addon-api": "^7.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
"prebuild": "^12.1.0",
|
||||
"semistandard": "^17.0.0",
|
||||
"tar-fs": "^3.0.4",
|
||||
"tsd": "^0.30.3"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"config": {
|
||||
"libvips": "8.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
||||
"libvips": ">=8.15.1"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"binary": {
|
||||
"napi_versions": [
|
||||
9
|
||||
]
|
||||
},
|
||||
"semistandard": {
|
||||
"env": [
|
||||
"mocha"
|
||||
]
|
||||
},
|
||||
"cc": {
|
||||
"linelength": "120",
|
||||
"filter": [
|
||||
"build/include"
|
||||
]
|
||||
},
|
||||
"nyc": {
|
||||
"include": [
|
||||
"lib"
|
||||
]
|
||||
},
|
||||
"tsd": {
|
||||
"directory": "test/types/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 IP"
|
||||
echo "Build libvips for ARM using Docker, where IP is"
|
||||
echo "the address of a Raspberry Pi running HypriotOS"
|
||||
exit 1
|
||||
fi
|
||||
IP="$1"
|
||||
|
||||
echo "Verifying connectivity to $IP"
|
||||
if ! ping -c 1 $IP; then
|
||||
echo "Could not connect to $IP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! type sshpass >/dev/null; then
|
||||
echo "Please install sshpass"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export SSHPASS=hypriot
|
||||
|
||||
echo "Copying arm/Dockerfile and arm/build.sh to device"
|
||||
sshpass -e scp -o PreferredAuthentications=password -r arm root@${IP}:/root
|
||||
|
||||
echo "Building Raspbian-based container"
|
||||
sshpass -e ssh -o PreferredAuthentications=password -t root@${IP} "docker build -t vips-dev-arm arm"
|
||||
|
||||
echo "Running arm/build.sh within container"
|
||||
sshpass -e ssh -o PreferredAuthentications=password -t root@${IP} "docker run -i -t --rm -v \${PWD}/arm:/arm vips-dev-arm sh -c 'cd /arm && ./build.sh' | tee arm/build.log"
|
||||
|
||||
echo "Copying resultant tar.gz file from device"
|
||||
sshpass -e scp -o PreferredAuthentications=password root@${IP}:/root/arm/*.tar.gz .
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 IP"
|
||||
echo "Test sharp on ARM using Docker, where IP is"
|
||||
echo "the address of a Raspberry Pi running HypriotOS"
|
||||
exit 1
|
||||
fi
|
||||
IP="$1"
|
||||
|
||||
echo "Verifying connectivity to $IP"
|
||||
if ! ping -c 1 $IP; then
|
||||
echo "Could not connect to $IP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! type sshpass >/dev/null; then
|
||||
echo "Please install sshpass"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export SSHPASS=hypriot
|
||||
|
||||
echo "Copying sharp source to device"
|
||||
sshpass -e scp -o PreferredAuthentications=password -r ../../sharp root@${IP}:/root/sharp
|
||||
|
||||
echo "Compile and test within container"
|
||||
sshpass -e ssh -o PreferredAuthentications=password -t root@${IP} "docker run -i -t --rm -v \${PWD}/sharp:/s hypriot/rpi-node:5 sh -c 'cd /s && npm install --unsafe-perm && npm test'"
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM resin/rpi-raspbian:jessie
|
||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
||||
|
||||
# Build dependencies
|
||||
RUN apt-get update && apt-get install -y build-essential autoconf libtool nasm gtk-doc-tools texinfo curl
|
||||
@@ -1,211 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# To be run inside a Raspbian container
|
||||
|
||||
# Working directories
|
||||
DEPS=/deps
|
||||
TARGET=/target
|
||||
mkdir ${DEPS}
|
||||
mkdir ${TARGET}
|
||||
|
||||
# Common build paths and flags
|
||||
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${TARGET}/lib/pkgconfig"
|
||||
export PATH="${PATH}:${TARGET}/bin"
|
||||
export CPPFLAGS="-I${TARGET}/include"
|
||||
export LDFLAGS="-L${TARGET}/lib"
|
||||
export CFLAGS="-O3"
|
||||
export CXXFLAGS="-O3"
|
||||
|
||||
# Dependency version numbers
|
||||
VERSION_ZLIB=1.2.8
|
||||
VERSION_FFI=3.2.1
|
||||
VERSION_GLIB=2.48.0
|
||||
VERSION_XML2=2.9.3
|
||||
VERSION_GSF=1.14.36
|
||||
VERSION_EXIF=0.6.21
|
||||
VERSION_LCMS2=2.7
|
||||
VERSION_JPEG=1.4.90
|
||||
VERSION_PNG16=1.6.21
|
||||
VERSION_WEBP=0.5.0
|
||||
VERSION_TIFF=4.0.6
|
||||
VERSION_ORC=0.4.25
|
||||
VERSION_GDKPIXBUF=2.34.0
|
||||
VERSION_FREETYPE=2.6.3
|
||||
VERSION_FONTCONFIG=2.11.95
|
||||
VERSION_HARFBUZZ=1.2.6
|
||||
VERSION_PIXMAN=0.34.0
|
||||
VERSION_CAIRO=1.14.6
|
||||
VERSION_PANGO=1.40.1
|
||||
VERSION_CROCO=0.6.11
|
||||
VERSION_SVG=2.40.15
|
||||
VERSION_GIF=5.1.4
|
||||
VERSION_VIPS=8.3.1
|
||||
|
||||
# Least out-of-sync Sourceforge mirror
|
||||
SOURCEFORGE_MIRROR=netix
|
||||
|
||||
mkdir ${DEPS}/zlib
|
||||
curl -Ls http://zlib.net/zlib-${VERSION_ZLIB}.tar.xz | tar xJC ${DEPS}/zlib --strip-components=1
|
||||
cd ${DEPS}/zlib
|
||||
./configure --prefix=${TARGET} && make install
|
||||
rm ${TARGET}/lib/libz.a
|
||||
|
||||
mkdir ${DEPS}/ffi
|
||||
curl -Ls ftp://sourceware.org/pub/libffi/libffi-${VERSION_FFI}.tar.gz | tar xzC ${DEPS}/ffi --strip-components=1
|
||||
cd ${DEPS}/ffi
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-builddir && make install-strip
|
||||
|
||||
mkdir ${DEPS}/glib
|
||||
curl -Ls https://download.gnome.org/sources/glib/2.48/glib-${VERSION_GLIB}.tar.xz | tar xJC ${DEPS}/glib --strip-components=1
|
||||
cd ${DEPS}/glib
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-pcre=internal && make install-strip
|
||||
|
||||
mkdir ${DEPS}/xml2
|
||||
curl -Ls http://xmlsoft.org/sources/libxml2-${VERSION_XML2}.tar.gz | tar xzC ${DEPS}/xml2 --strip-components=1
|
||||
cd ${DEPS}/xml2
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --without-python --with-zlib=${TARGET} && make install-strip
|
||||
|
||||
mkdir ${DEPS}/gsf
|
||||
curl -Ls https://download.gnome.org/sources/libgsf/1.14/libgsf-${VERSION_GSF}.tar.xz | tar xJC ${DEPS}/gsf --strip-components=1
|
||||
cd ${DEPS}/gsf
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/exif
|
||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/libexif/libexif/${VERSION_EXIF}/libexif-${VERSION_EXIF}.tar.bz2 | tar xjC ${DEPS}/exif --strip-components=1
|
||||
cd ${DEPS}/exif
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/lcms2
|
||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/lcms/lcms/${VERSION_LCMS2}/lcms2-${VERSION_LCMS2}.tar.gz | tar xzC ${DEPS}/lcms2 --strip-components=1
|
||||
cd ${DEPS}/lcms2
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/jpeg
|
||||
curl -Ls https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION_JPEG}.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1
|
||||
cd ${DEPS}/jpeg
|
||||
autoreconf -fiv && ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-jpeg8 --without-turbojpeg && make install-strip
|
||||
|
||||
mkdir ${DEPS}/png16
|
||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/libpng/libpng16/${VERSION_PNG16}/libpng-${VERSION_PNG16}.tar.xz | tar xJC ${DEPS}/png16 --strip-components=1
|
||||
cd ${DEPS}/png16
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/webp
|
||||
curl -Ls http://downloads.webmproject.org/releases/webp/libwebp-${VERSION_WEBP}.tar.gz | tar xzC ${DEPS}/webp --strip-components=1
|
||||
cd ${DEPS}/webp
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/tiff
|
||||
curl -Ls http://download.osgeo.org/libtiff/tiff-${VERSION_TIFF}.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1
|
||||
cd ${DEPS}/tiff
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
rm ${TARGET}/lib/libtiffxx*
|
||||
|
||||
mkdir ${DEPS}/orc
|
||||
curl -Ls http://gstreamer.freedesktop.org/data/src/orc/orc-${VERSION_ORC}.tar.xz | tar xJC ${DEPS}/orc --strip-components=1
|
||||
cd ${DEPS}/orc
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/gdkpixbuf
|
||||
curl -Ls https://download.gnome.org/sources/gdk-pixbuf/2.34/gdk-pixbuf-${VERSION_GDKPIXBUF}.tar.xz | tar xJC ${DEPS}/gdkpixbuf --strip-components=1
|
||||
cd ${DEPS}/gdkpixbuf
|
||||
LD_LIBRARY_PATH=${TARGET}/lib ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-introspection --disable-modules --without-libpng --without-libjpeg --without-libtiff --without-gdiplus --with-included-loaders= \
|
||||
&& make install-strip
|
||||
|
||||
mkdir ${DEPS}/freetype
|
||||
curl -Ls http://download.savannah.gnu.org/releases/freetype/freetype-${VERSION_FREETYPE}.tar.gz | tar xzC ${DEPS}/freetype --strip-components=1
|
||||
cd ${DEPS}/freetype
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static && make install
|
||||
|
||||
mkdir ${DEPS}/fontconfig
|
||||
curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1
|
||||
cd ${DEPS}/fontconfig
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --enable-libxml2 && make install-strip
|
||||
|
||||
mkdir ${DEPS}/harfbuzz
|
||||
curl -Ls https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-${VERSION_HARFBUZZ}.tar.bz2 | tar xjC ${DEPS}/harfbuzz --strip-components=1
|
||||
cd ${DEPS}/harfbuzz
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/pixman
|
||||
curl -Ls http://cairographics.org/releases/pixman-${VERSION_PIXMAN}.tar.gz | tar xzC ${DEPS}/pixman --strip-components=1
|
||||
cd ${DEPS}/pixman
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-libpng --disable-arm-iwmmxt && make install-strip
|
||||
|
||||
mkdir ${DEPS}/cairo
|
||||
curl -Ls http://cairographics.org/releases/cairo-${VERSION_CAIRO}.tar.xz | tar xJC ${DEPS}/cairo --strip-components=1
|
||||
cd ${DEPS}/cairo
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-xlib --disable-xcb --disable-quartz --disable-win32 --disable-egl --disable-glx --disable-wgl \
|
||||
--disable-script --disable-ps --disable-gobject --disable-trace --disable-interpreter \
|
||||
&& make install-strip
|
||||
|
||||
mkdir ${DEPS}/pango
|
||||
curl -Ls https://download.gnome.org/sources/pango/1.40/pango-${VERSION_PANGO}.tar.xz | tar xJC ${DEPS}/pango --strip-components=1
|
||||
cd ${DEPS}/pango
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/croco
|
||||
curl -Ls https://download.gnome.org/sources/libcroco/0.6/libcroco-${VERSION_CROCO}.tar.xz | tar xJC ${DEPS}/croco --strip-components=1
|
||||
cd ${DEPS}/croco
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/svg
|
||||
curl -Ls https://download.gnome.org/sources/librsvg/2.40/librsvg-${VERSION_SVG}.tar.xz | tar xJC ${DEPS}/svg --strip-components=1
|
||||
cd ${DEPS}/svg
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-introspection --disable-tools \
|
||||
&& make install-strip
|
||||
|
||||
mkdir ${DEPS}/gif
|
||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/giflib/giflib-${VERSION_GIF}.tar.gz | tar xzC ${DEPS}/gif --strip-components=1
|
||||
cd ${DEPS}/gif
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
mkdir ${DEPS}/vips
|
||||
curl -Ls http://www.vips.ecs.soton.ac.uk/supported/8.3/vips-${VERSION_VIPS}.tar.gz | tar xzC ${DEPS}/vips --strip-components=1
|
||||
cd ${DEPS}/vips
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-debug --disable-introspection --without-python --without-fftw \
|
||||
--without-magick --without-pangoft2 --without-ppm --without-analyze --without-radiance \
|
||||
--with-zip-includes=${TARGET}/include --with-zip-libraries=${TARGET}/lib \
|
||||
--with-jpeg-includes=${TARGET}/include --with-jpeg-libraries=${TARGET}/lib \
|
||||
&& make install-strip
|
||||
|
||||
# Remove the old C++ bindings
|
||||
cd ${TARGET}/include
|
||||
rm -rf vips/vipsc++.h vips/vipscpp.h
|
||||
cd ${TARGET}/lib
|
||||
rm -rf pkgconfig .libs *.la libvipsCC*
|
||||
|
||||
# Create JSON file of version numbers
|
||||
cd ${TARGET}
|
||||
echo "{\n\
|
||||
\"cairo\": \"${VERSION_CAIRO}\",\n\
|
||||
\"croco\": \"${VERSION_CROCO}\",\n\
|
||||
\"exif\": \"${VERSION_EXIF}\",\n\
|
||||
\"ffi\": \"${VERSION_FFI}\",\n\
|
||||
\"fontconfig\": \"${VERSION_FONTCONFIG}\",\n\
|
||||
\"freetype\": \"${VERSION_FREETYPE}\",\n\
|
||||
\"gdkpixbuf\": \"${VERSION_GDKPIXBUF}\",\n\
|
||||
\"gif\": \"${VERSION_GIF}\",\n\
|
||||
\"glib\": \"${VERSION_GLIB}\",\n\
|
||||
\"gsf\": \"${VERSION_GSF}\",\n\
|
||||
\"harfbuzz\": \"${VERSION_HARFBUZZ}\",\n\
|
||||
\"jpeg\": \"${VERSION_JPEG}\",\n\
|
||||
\"lcms\": \"${VERSION_LCMS2}\",\n\
|
||||
\"orc\": \"${VERSION_ORC}\",\n\
|
||||
\"pango\": \"${VERSION_PANGO}\",\n\
|
||||
\"pixman\": \"${VERSION_PIXMAN}\",\n\
|
||||
\"png\": \"${VERSION_PNG16}\",\n\
|
||||
\"svg\": \"${VERSION_SVG}\",\n\
|
||||
\"tiff\": \"${VERSION_TIFF}\",\n\
|
||||
\"vips\": \"${VERSION_VIPS}\",\n\
|
||||
\"webp\": \"${VERSION_WEBP}\",\n\
|
||||
\"xml\": \"${VERSION_XML2}\",\n\
|
||||
\"zlib\": \"${VERSION_ZLIB}\"\n\
|
||||
}" >lib/versions.json
|
||||
|
||||
# Create .tar.gz
|
||||
GZIP=-9 tar czf /arm/libvips-${VERSION_VIPS}-arm.tar.gz include lib
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
VERSION_VIPS=8.3.1
|
||||
|
||||
# Is docker available?
|
||||
|
||||
if ! type docker >/dev/null; then
|
||||
echo "Please install docker"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# TODO: docker v1.9.0 allows build-time args - https://github.com/docker/docker/pull/15182
|
||||
|
||||
# Windows
|
||||
|
||||
docker build -t vips-dev-win win
|
||||
WIN_CONTAINER_ID=$(docker run -d vips-dev-win)
|
||||
docker cp "${WIN_CONTAINER_ID}:/libvips-${VERSION_VIPS}-win.tar.gz" .
|
||||
docker rm "${WIN_CONTAINER_ID}"
|
||||
|
||||
# Linux
|
||||
|
||||
docker build -t vips-dev-lin lin
|
||||
LIN_CONTAINER_ID=$(docker run -d vips-dev-lin)
|
||||
docker cp "${LIN_CONTAINER_ID}:/libvips-${VERSION_VIPS}-lin.tar.gz" .
|
||||
docker rm "${LIN_CONTAINER_ID}"
|
||||
|
||||
# Checksums
|
||||
|
||||
sha256sum *.tar.gz
|
||||
@@ -1,221 +0,0 @@
|
||||
FROM debian:wheezy
|
||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
||||
|
||||
# Build dependencies
|
||||
RUN apt-get update && apt-get install -y build-essential autoconf libtool nasm gtk-doc-tools texinfo
|
||||
|
||||
# Create working directories
|
||||
ENV DEPS=/deps \
|
||||
TARGET=/target
|
||||
RUN mkdir ${DEPS} && mkdir ${TARGET}
|
||||
|
||||
# Common build paths and flags
|
||||
ENV PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${TARGET}/lib/pkgconfig" \
|
||||
PATH="${PATH}:${TARGET}/bin" \
|
||||
CPPFLAGS="-I${TARGET}/include" \
|
||||
LDFLAGS="-L${TARGET}/lib" \
|
||||
CFLAGS="-O3" \
|
||||
CXXFLAGS="-O3"
|
||||
|
||||
# Dependency version numbers
|
||||
ENV VERSION_ZLIB=1.2.8 \
|
||||
VERSION_FFI=3.2.1 \
|
||||
VERSION_GLIB=2.48.0 \
|
||||
VERSION_XML2=2.9.3 \
|
||||
VERSION_GSF=1.14.36 \
|
||||
VERSION_EXIF=0.6.21 \
|
||||
VERSION_LCMS2=2.7 \
|
||||
VERSION_JPEG=1.4.90 \
|
||||
VERSION_PNG16=1.6.21 \
|
||||
VERSION_WEBP=0.5.0 \
|
||||
VERSION_TIFF=4.0.6 \
|
||||
VERSION_ORC=0.4.25 \
|
||||
VERSION_GDKPIXBUF=2.34.0 \
|
||||
VERSION_FREETYPE=2.6.3 \
|
||||
VERSION_FONTCONFIG=2.11.95 \
|
||||
VERSION_HARFBUZZ=1.2.6 \
|
||||
VERSION_PIXMAN=0.34.0 \
|
||||
VERSION_CAIRO=1.14.6 \
|
||||
VERSION_PANGO=1.40.1 \
|
||||
VERSION_CROCO=0.6.11 \
|
||||
VERSION_SVG=2.40.15 \
|
||||
VERSION_GIF=5.1.4 \
|
||||
VERSION_VIPS=8.3.1
|
||||
|
||||
# Least out-of-sync Sourceforge mirror
|
||||
ENV SOURCEFORGE_MIRROR=netix
|
||||
|
||||
RUN mkdir ${DEPS}/zlib
|
||||
RUN curl -Ls http://zlib.net/zlib-${VERSION_ZLIB}.tar.xz | tar xJC ${DEPS}/zlib --strip-components=1
|
||||
WORKDIR ${DEPS}/zlib
|
||||
RUN ./configure --prefix=${TARGET} && make install
|
||||
RUN rm ${TARGET}/lib/libz.a
|
||||
|
||||
RUN mkdir ${DEPS}/ffi
|
||||
RUN curl -Ls ftp://sourceware.org/pub/libffi/libffi-${VERSION_FFI}.tar.gz | tar xzC ${DEPS}/ffi --strip-components=1
|
||||
WORKDIR ${DEPS}/ffi
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-builddir && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/glib
|
||||
RUN curl -Ls https://download.gnome.org/sources/glib/2.48/glib-${VERSION_GLIB}.tar.xz | tar xJC ${DEPS}/glib --strip-components=1
|
||||
WORKDIR ${DEPS}/glib
|
||||
RUN CFLAGS="${CFLAGS} -Wl,--default-symver" CXXFLAGS="${CXXFLAGS} -Wl,--default-symver" \
|
||||
./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-pcre=internal && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/xml2
|
||||
RUN curl -Ls http://xmlsoft.org/sources/libxml2-${VERSION_XML2}.tar.gz | tar xzC ${DEPS}/xml2 --strip-components=1
|
||||
WORKDIR ${DEPS}/xml2
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--without-python --without-debug --without-docbook --without-ftp --without-html --without-legacy \
|
||||
--without-pattern --without-push --without-regexps --without-schemas --without-schematron --with-zlib=${TARGET} \
|
||||
&& make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/gsf
|
||||
RUN curl -Ls https://download.gnome.org/sources/libgsf/1.14/libgsf-${VERSION_GSF}.tar.xz | tar xJC ${DEPS}/gsf --strip-components=1
|
||||
WORKDIR ${DEPS}/gsf
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/exif
|
||||
RUN curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/libexif/libexif/${VERSION_EXIF}/libexif-${VERSION_EXIF}.tar.bz2 | tar xjC ${DEPS}/exif --strip-components=1
|
||||
WORKDIR ${DEPS}/exif
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/lcms2
|
||||
RUN curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/lcms/lcms/${VERSION_LCMS2}/lcms2-${VERSION_LCMS2}.tar.gz | tar xzC ${DEPS}/lcms2 --strip-components=1
|
||||
WORKDIR ${DEPS}/lcms2
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/jpeg
|
||||
RUN curl -Ls https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION_JPEG}.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1
|
||||
WORKDIR ${DEPS}/jpeg
|
||||
RUN autoreconf -fiv && ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-jpeg8 --without-turbojpeg && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/png16
|
||||
RUN curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/libpng/libpng16/${VERSION_PNG16}/libpng-${VERSION_PNG16}.tar.xz | tar xJC ${DEPS}/png16 --strip-components=1
|
||||
WORKDIR ${DEPS}/png16
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/webp
|
||||
RUN curl -Ls http://downloads.webmproject.org/releases/webp/libwebp-${VERSION_WEBP}.tar.gz | tar xzC ${DEPS}/webp --strip-components=1
|
||||
WORKDIR ${DEPS}/webp
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/tiff
|
||||
RUN curl -Ls http://download.osgeo.org/libtiff/tiff-${VERSION_TIFF}.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1
|
||||
WORKDIR ${DEPS}/tiff
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
RUN rm ${TARGET}/lib/libtiffxx*
|
||||
|
||||
RUN mkdir ${DEPS}/orc
|
||||
RUN curl -Ls http://gstreamer.freedesktop.org/data/src/orc/orc-${VERSION_ORC}.tar.xz | tar xJC ${DEPS}/orc --strip-components=1
|
||||
WORKDIR ${DEPS}/orc
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
RUN rm ${TARGET}/lib/liborc-test-*
|
||||
|
||||
RUN mkdir ${DEPS}/gdkpixbuf
|
||||
RUN curl -Ls https://download.gnome.org/sources/gdk-pixbuf/2.34/gdk-pixbuf-${VERSION_GDKPIXBUF}.tar.xz | tar xJC ${DEPS}/gdkpixbuf --strip-components=1
|
||||
WORKDIR ${DEPS}/gdkpixbuf
|
||||
RUN LD_LIBRARY_PATH=${TARGET}/lib ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-introspection --disable-modules --without-libpng --without-libjpeg --without-libtiff --without-gdiplus --with-included-loaders= \
|
||||
&& make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/freetype
|
||||
RUN curl -Ls http://download.savannah.gnu.org/releases/freetype/freetype-${VERSION_FREETYPE}.tar.gz | tar xzC ${DEPS}/freetype --strip-components=1
|
||||
WORKDIR ${DEPS}/freetype
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static && make install
|
||||
|
||||
RUN mkdir ${DEPS}/fontconfig
|
||||
RUN curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1
|
||||
WORKDIR ${DEPS}/fontconfig
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --enable-libxml2 && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/harfbuzz
|
||||
RUN curl -Ls https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-${VERSION_HARFBUZZ}.tar.bz2 | tar xjC ${DEPS}/harfbuzz --strip-components=1
|
||||
WORKDIR ${DEPS}/harfbuzz
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/pixman
|
||||
RUN curl -Ls http://cairographics.org/releases/pixman-${VERSION_PIXMAN}.tar.gz | tar xzC ${DEPS}/pixman --strip-components=1
|
||||
WORKDIR ${DEPS}/pixman
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-libpng && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/cairo
|
||||
RUN curl -Ls http://cairographics.org/releases/cairo-${VERSION_CAIRO}.tar.xz | tar xJC ${DEPS}/cairo --strip-components=1
|
||||
WORKDIR ${DEPS}/cairo
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-xlib --disable-xcb --disable-quartz --disable-win32 --disable-egl --disable-glx --disable-wgl \
|
||||
--disable-script --disable-ps --disable-gobject --disable-trace --disable-interpreter \
|
||||
&& make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/pango
|
||||
RUN curl -Ls https://download.gnome.org/sources/pango/1.40/pango-${VERSION_PANGO}.tar.xz | tar xJC ${DEPS}/pango --strip-components=1
|
||||
WORKDIR ${DEPS}/pango
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/croco
|
||||
RUN curl -Ls https://download.gnome.org/sources/libcroco/0.6/libcroco-${VERSION_CROCO}.tar.xz | tar xJC ${DEPS}/croco --strip-components=1
|
||||
WORKDIR ${DEPS}/croco
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/svg
|
||||
RUN curl -Ls https://download.gnome.org/sources/librsvg/2.40/librsvg-${VERSION_SVG}.tar.xz | tar xJC ${DEPS}/svg --strip-components=1
|
||||
WORKDIR ${DEPS}/svg
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-introspection --disable-tools \
|
||||
&& make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/gif
|
||||
RUN curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/giflib/giflib-${VERSION_GIF}.tar.gz | tar xzC ${DEPS}/gif --strip-components=1
|
||||
WORKDIR ${DEPS}/gif
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip
|
||||
|
||||
RUN mkdir ${DEPS}/vips
|
||||
RUN curl -Ls http://www.vips.ecs.soton.ac.uk/supported/8.3/vips-${VERSION_VIPS}.tar.gz | tar xzC ${DEPS}/vips --strip-components=1
|
||||
#RUN apt-get install -y swig gobject-introspection gettext glib2.0-dev
|
||||
#RUN curl -Ls https://github.com/jcupitt/libvips/archive/master.tar.gz | tar xzC ${DEPS}/vips --strip-components=1
|
||||
WORKDIR ${DEPS}/vips
|
||||
#RUN ./bootstrap.sh
|
||||
RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
||||
--disable-debug --disable-introspection --without-python --without-fftw \
|
||||
--without-magick --without-pangoft2 --without-ppm --without-analyze --without-radiance \
|
||||
--with-zip-includes=${TARGET}/include --with-zip-libraries=${TARGET}/lib \
|
||||
--with-jpeg-includes=${TARGET}/include --with-jpeg-libraries=${TARGET}/lib \
|
||||
&& make install-strip
|
||||
|
||||
# Remove the old C++ bindings
|
||||
WORKDIR ${TARGET}/include
|
||||
RUN rm -rf vips/vipsc++.h vips/vipscpp.h
|
||||
WORKDIR ${TARGET}/lib
|
||||
RUN rm -rf pkgconfig .libs *.la libvipsCC*
|
||||
|
||||
# Create JSON file of version numbers
|
||||
WORKDIR ${TARGET}
|
||||
RUN echo "{\n\
|
||||
\"cairo\": \"${VERSION_CAIRO}\",\n\
|
||||
\"croco\": \"${VERSION_CROCO}\",\n\
|
||||
\"exif\": \"${VERSION_EXIF}\",\n\
|
||||
\"ffi\": \"${VERSION_FFI}\",\n\
|
||||
\"fontconfig\": \"${VERSION_FONTCONFIG}\",\n\
|
||||
\"freetype\": \"${VERSION_FREETYPE}\",\n\
|
||||
\"gdkpixbuf\": \"${VERSION_GDKPIXBUF}\",\n\
|
||||
\"gif\": \"${VERSION_GIF}\",\n\
|
||||
\"glib\": \"${VERSION_GLIB}\",\n\
|
||||
\"gsf\": \"${VERSION_GSF}\",\n\
|
||||
\"harfbuzz\": \"${VERSION_HARFBUZZ}\",\n\
|
||||
\"jpeg\": \"${VERSION_JPEG}\",\n\
|
||||
\"lcms\": \"${VERSION_LCMS2}\",\n\
|
||||
\"orc\": \"${VERSION_ORC}\",\n\
|
||||
\"pango\": \"${VERSION_PANGO}\",\n\
|
||||
\"pixman\": \"${VERSION_PIXMAN}\",\n\
|
||||
\"png\": \"${VERSION_PNG16}\",\n\
|
||||
\"svg\": \"${VERSION_SVG}\",\n\
|
||||
\"tiff\": \"${VERSION_TIFF}\",\n\
|
||||
\"vips\": \"${VERSION_VIPS}\",\n\
|
||||
\"webp\": \"${VERSION_WEBP}\",\n\
|
||||
\"xml\": \"${VERSION_XML2}\",\n\
|
||||
\"zlib\": \"${VERSION_ZLIB}\"\n\
|
||||
}" >lib/versions.json
|
||||
|
||||
# Create .tar.gz
|
||||
WORKDIR ${TARGET}
|
||||
RUN GZIP=-9 tar czf /libvips-${VERSION_VIPS}-lin.tar.gz include lib
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Verify docker is available
|
||||
if ! type docker >/dev/null; then
|
||||
echo "Please install docker"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version_node=4.4.2
|
||||
|
||||
test="npm run clean; npm install --unsafe-perm; npm test"
|
||||
|
||||
# Debian 7, 8
|
||||
# Ubuntu 14.04
|
||||
for dist in wheezy jessie trusty; do
|
||||
echo "Testing $dist..."
|
||||
if docker run -i -t --rm -v $PWD:/v -e "NODE_ENV=development" nodesource/$dist:$version_node >packaging/$dist.log 2>&1 sh -c "cd /v; ./packaging/test/debian.sh; $test";
|
||||
then echo "$dist OK"
|
||||
else echo "$dist fail" && cat packaging/$dist.log
|
||||
fi
|
||||
done
|
||||
|
||||
# Centos 7
|
||||
echo "Testing centos7..."
|
||||
if docker run -i -t --rm -v $PWD:/v -e "NODE_ENV=development" nodesource/centos7:$version_node >packaging/$dist.log 2>&1 sh -c "cd /v; $test";
|
||||
then echo "$dist OK"
|
||||
else echo "$dist fail" && cat packaging/$dist.log
|
||||
fi
|
||||
|
||||
# Fedora 22
|
||||
echo "Testing fedora22..."
|
||||
if docker run -i -t --rm -v $PWD:/v -e "NODE_ENV=development" nodesource/fedora22:$version_node >packaging/$dist.log 2>&1 sh -c "cd /v; $test";
|
||||
then echo "$dist OK"
|
||||
else echo "$dist fail" && cat packaging/$dist.log
|
||||
fi
|
||||
|
||||
# openSUSE 13.2
|
||||
echo "Testing opensuse..."
|
||||
if docker run -i -t --rm -v $PWD:/v opensuse:13.2 >packaging/opensuse.log 2>&1 /bin/sh -c "cd /v; ./packaging/test/opensuse.sh; $test";
|
||||
then echo "opensuse OK"
|
||||
else echo "opensuse fail" && cat packaging/opensuse.log
|
||||
fi
|
||||
|
||||
# Archlinux 2015.06.01
|
||||
echo "Testing archlinux..."
|
||||
if docker run -i -t --rm -v $PWD:/v base/archlinux:2015.06.01 >packaging/archlinux.log 2>&1 sh -c "cd /v; ./packaging/test/archlinux.sh; $test";
|
||||
then echo "archlinux OK"
|
||||
else echo "archlinux fail" && cat packaging/archlinux.log
|
||||
fi
|
||||
|
||||
# Alpine
|
||||
echo "Testing alpine..."
|
||||
if docker run -i -t --rm -v $PWD:/v -e "SHARP_TEST_WITHOUT_CACHE=0" alpine:edge >packaging/alpine.log 2>&1 sh -c "cd /v; ./packaging/test/alpine.sh; $test";
|
||||
then echo "alpine OK"
|
||||
else echo "alpine fail" && cat packaging/alpine.log
|
||||
fi
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Install build dependencies
|
||||
apk add --update make gcc g++ python nodejs
|
||||
|
||||
# Install libvips with build headers and dependencies
|
||||
apk add libvips-dev --update --repository https://s3.amazonaws.com/wjordan-apk --allow-untrusted
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Install Node.js on Archlinux
|
||||
pacman -Sy --noconfirm gcc make python2 nodejs npm | cat
|
||||
ln -s /usr/bin/python2 /usr/bin/python
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Install pkg-config on Debian/Ubuntu
|
||||
apt-get update
|
||||
apt-get install -y pkg-config
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Install Node.js on openSUSE 13.2
|
||||
zypper addrepo http://download.opensuse.org/repositories/devel:languages:nodejs/openSUSE_13.2/devel:languages:nodejs.repo
|
||||
zypper --gpg-auto-import-keys refresh
|
||||
zypper --non-interactive install gcc-c++ make nodejs-devel npm
|
||||
npm install -g npm
|
||||
@@ -1,20 +0,0 @@
|
||||
FROM debian:wheezy
|
||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
||||
|
||||
RUN apt-get update && apt-get install -y curl zip
|
||||
|
||||
ENV VERSION_VIPS=8.3.1
|
||||
|
||||
# Fetch and unzip
|
||||
RUN mkdir /vips
|
||||
WORKDIR /vips
|
||||
RUN curl -L -O https://github.com/lovell/build-win64/releases/download/v${VERSION_VIPS}/vips-dev-w64-web-${VERSION_VIPS}.zip
|
||||
RUN unzip vips-dev-w64-web-${VERSION_VIPS}.zip
|
||||
|
||||
# Clean and zip
|
||||
WORKDIR /vips/vips-dev-8.3
|
||||
RUN rm bin/libvipsCC-42.dll bin/libvips-cpp-42.dll bin/libgsf-win32-1-114.dll
|
||||
RUN cp bin/*.dll lib/
|
||||
RUN cp -r lib64/* lib/
|
||||
|
||||
RUN GZIP=-9 tar czf /libvips-${VERSION_VIPS}-win.tar.gz include lib/glib-2.0 lib/libvips.lib lib/libglib-2.0.lib lib/libgobject-2.0.lib lib/*.dll
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user