Skip to content

Commit 80b6b81

Browse files
author
Alexandru Badiu
committed
feat(code): Updated sharp and examples
Updated to latest sharp library. Updated examples.
1 parent 99c9f82 commit 80b6b81

4 files changed

Lines changed: 226 additions & 55 deletions

File tree

examples/example.js

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,101 @@ import ImageCache from '../dist/index';
33

44
const imagecache = new ImageCache(presets);
55

6-
imagecache.render('./in.png', 's_crop_tiny', (err, image) => {
6+
imagecache.render('./in.png', 'canvas_scale_with_blur', (err, image) => {
77
if (err) {
8-
console.log('Failed to process image out_s_crop_tiny.png.');
8+
console.log('Failed to process image in.png with preset canvas_scale_with_blur.');
99
console.log(err);
1010

1111
return;
1212
}
1313

14-
image.toFile('out_s_crop_tiny.png', (saveErr, info) => {
14+
image.toFile('out_canvas_scale_with_blur.png', (saveErr, info) => {
1515
if (saveErr) {
16-
console.log('Failed to save image out_s_crop_tiny.png.');
16+
console.log('Failed to save image out_canvas_scale_with_blur.png.');
1717
console.log(err);
1818

1919
return;
2020
}
2121

22-
console.log(`Saved image out_s_crop_tiny.png with width ${info.width} and height ${info.height}.`);
22+
console.log(`Saved image out_canvas_scale_with_blur.png with width ${info.width} and height ${info.height}.`);
2323
});
2424
});
2525

26-
imagecache.render('./in.png', 's_crop_small', (err, image) => {
26+
imagecache.render('./in.png', 'scale_crop_tiny', (err, image) => {
2727
if (err) {
28-
console.log('Failed to process image out_s_crop_small.png.');
28+
console.log('Failed to process image in.png with preset scale_crop_tiny.');
2929
console.log(err);
3030

3131
return;
3232
}
3333

34-
image.toFile('out_s_crop_small.png', (saveErr, info) => {
34+
image.toFile('out_scale_crop_tiny.png', (saveErr, info) => {
3535
if (saveErr) {
36-
console.log('Failed to save image out_s_crop_small.png.');
36+
console.log('Failed to save image out_scale_crop_tiny.png.');
3737
console.log(err);
3838

3939
return;
4040
}
41-
console.log(`Saved image out_s_crop_small.png with width ${info.width} and height ${info.height}.`);
41+
42+
console.log(`Saved image out_scale_crop_tiny.png with width ${info.width} and height ${info.height}.`);
43+
});
44+
});
45+
46+
imagecache.render('./in.png', 'scale_crop_small', (err, image) => {
47+
if (err) {
48+
console.log('Failed to process image in.png with preset scale_crop_small.');
49+
console.log(err);
50+
51+
return;
52+
}
53+
54+
image.toFile('out_scale_crop_small.png', (saveErr, info) => {
55+
if (saveErr) {
56+
console.log('Failed to save image out_scale_crop_small.png.');
57+
console.log(err);
58+
59+
return;
60+
}
61+
console.log(`Saved image out_scale_crop_small.png with width ${info.width} and height ${info.height}.`);
4262
});
4363
});
4464

45-
imagecache.render('./in.png', 's_crop_teaser', (err, image) => {
65+
imagecache.render('./in.png', 'scale_crop_teaser', (err, image) => {
4666
if (err) {
47-
console.log('Failed to process image out_s_crop_teaser.png.');
67+
console.log('Failed to process image in.png with preset scale_crop_teaser.');
4868
console.log(err);
4969

5070
return;
5171
}
5272

53-
image.toFile('out_s_crop_teaser.png', (saveErr, info) => {
73+
image.toFile('out_scale_crop_teaser.png', (saveErr, info) => {
5474
if (saveErr) {
55-
console.log('Failed to save image out_s_crop_teaser.png.');
75+
console.log('Failed to save image out_scale_crop_teaser.png.');
5676
console.log(err);
5777

5878
return;
5979
}
6080

61-
console.log(`Saved image out_s_crop_teaser.png with width ${info.width} and height ${info.height}.`);
81+
console.log(`Saved image out_scale_crop_teaser.png with width ${info.width} and height ${info.height}.`);
6282
});
6383
});
6484

65-
imagecache.render('./in.png', 's_scale_teaser', (err, image) => {
85+
imagecache.render('./in.png', 'scale_with_watermark', (err, image) => {
6686
if (err) {
67-
console.log('Failed to process image out_s_scale_teaser.png.');
87+
console.log('Failed to process image in.png with preset scale_with_watermark.');
6888
console.log(err);
6989

7090
return;
7191
}
7292

73-
image.toFile('out_s_scale_teaser.png', (saveErr, info) => {
93+
image.toFile('out_scale_with_watermark.png', (saveErr, info) => {
7494
if (saveErr) {
75-
console.log('Failed to save image out_s_scale_teaser.png.');
95+
console.log('Failed to save image out_scale_with_watermark.png.');
7696
console.log(err);
7797

7898
return;
7999
}
80100

81-
console.log(`Saved image out_s_scale_teaser.png with width ${info.width} and height ${info.height}.`);
101+
console.log(`Saved image out_scale_with_watermark.png with width ${info.width} and height ${info.height}.`);
82102
});
83103
});

examples/presets.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
module.exports = {
2-
s_crop_tiny: {
3-
presetname: 's_crop_tiny',
2+
canvas_scale_with_blur: {
3+
presetname: 'canvas_scale_with_blur',
4+
actions: [
5+
{
6+
action: 'scale_and_crop',
7+
config: {
8+
width: 152,
9+
height: 152,
10+
},
11+
},
12+
{
13+
action: 'define_canvas',
14+
config: {
15+
color: '#333333',
16+
width: 400,
17+
height: 400,
18+
},
19+
},
20+
{
21+
action: 'blur',
22+
},
23+
],
24+
},
25+
scale_crop_tiny: {
26+
presetname: 'scale_crop_tiny',
427
actions: [
528
{
629
action: 'scale_and_crop',
@@ -11,8 +34,8 @@ module.exports = {
1134
},
1235
],
1336
},
14-
s_crop_small: {
15-
presetname: 's_crop_small',
37+
scale_crop_small: {
38+
presetname: 'scale_crop_small',
1639
actions: [
1740
{
1841
action: 'scale_and_crop',
@@ -23,8 +46,8 @@ module.exports = {
2346
},
2447
],
2548
},
26-
s_crop_teaser: {
27-
presetname: 's_crop_teaser',
49+
scale_crop_teaser: {
50+
presetname: 'scale_crop_teaser',
2851
actions: [
2952
{
3053
action: 'scale_and_crop',
@@ -35,8 +58,8 @@ module.exports = {
3558
},
3659
],
3760
},
38-
s_scale_teaser: {
39-
presetname: 's_scale_teaser',
61+
scale_with_watermark: {
62+
presetname: 'scale_with_watermark',
4063
actions: [
4164
{
4265
action: 'file',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"dependencies": {
4949
"async": "2.4.1",
50-
"sharp": "0.16.2",
50+
"sharp": "0.18.1",
5151
"string": "3.3.3"
5252
},
5353
"devDependencies": {

0 commit comments

Comments
 (0)