Skip to content

Commit 55e4f20

Browse files
authored
Merge pull request #35 from voidberg/beta
2.0.0 beta
2 parents 9f022e2 + 33f4e93 commit 55e4f20

File tree

182 files changed

+12252
-3886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+12252
-3886
lines changed

.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
plugins: [
5+
'@typescript-eslint',
6+
],
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:@typescript-eslint/recommended',
10+
],
11+
};

.github/workflows/njsscan.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow integrates njsscan with GitHub's Code Scanning feature
7+
# nodejsscan is a static security code scanner that finds insecure code patterns in your Node.js applications
8+
9+
name: njsscan sarif
10+
11+
on:
12+
push:
13+
branches: [ "master" ]
14+
pull_request:
15+
# The branches below must be a subset of the branches above
16+
branches: [ "master" ]
17+
schedule:
18+
- cron: '38 17 * * 3'
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
njsscan:
25+
permissions:
26+
contents: read # for actions/checkout to fetch code
27+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
28+
runs-on: ubuntu-latest
29+
name: njsscan code scanning
30+
steps:
31+
- name: Checkout the code
32+
uses: actions/checkout@v3
33+
- name: nodejsscan scan
34+
id: njsscan
35+
uses: ajinabraham/njsscan-action@7237412fdd36af517e2745077cedbf9d6900d711
36+
with:
37+
args: '. --sarif --output results.sarif || true'
38+
- name: Upload njsscan report
39+
uses: github/codeql-action/upload-sarif@v2
40+
with:
41+
sarif_file: results.sarif

.github/workflows/node.js.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: ['master', 'v2.0.0']
9+
pull_request:
10+
branches: ['master']
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: '14.x'
22+
cache: 'npm'
23+
- name: Install dependencies
24+
run: yarn install --frozen-lockfile
25+
- name: Build package
26+
run: npm run build --if-present
27+
- name: Run tests
28+
run: npm test

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Release
5+
6+
on:
7+
push:
8+
branches: ['master', 'main', 'next', 'next-major', 'beta', 'alpha']
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: '14.x'
23+
- name: Install dependencies
24+
run: yarn install --frozen-lockfile
25+
- name: Build package
26+
run: npm run build --if-present
27+
- name: Build documentation
28+
run: yarn docs
29+
- name: Run tests
30+
run: npm test
31+
- name: Release
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
35+
run: yarn semantic-release

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true
6+
}

README.md

Lines changed: 95 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,105 @@
1-
[ ![Codeship Status for voidberg/imagecache-sharp](https://app.codeship.com/projects/2adcc0e0-31b3-0135-88a3-36beedd22907/status?branch=master)](https://app.codeship.com/projects/225818)[![Latest release on NPM](https://img.shields.io/npm/v/imagecache-sharp.svg)](https://www.npmjs.com/package/imagecache-sharp)
1+
[![Latest release on NPM](https://img.shields.io/npm/v/imagecache-sharp.svg)](https://www.npmjs.com/package/imagecache-sharp)
2+
[![Build states](https://github.com/voidberg/imagecache-sharp/workflows/Node.js%20CI/badge.svg)](https://github.com/voidberg/imagecache-sharp/actions?query=workflow%3A%22Node.js+CI%22+branch%3Amaster++)
3+
[![Semantic release](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release/)
24
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
3-
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
4-
[![David-dm.org](https://david-dm.org/voidberg/imagecache-sharp.svg)](https://david-dm.org/voidberg/imagecache-sharp#info=dependencies&view=table)
5-
[![David-dm.org](https://david-dm.org/voidberg/imagecache-sharp/dev-status.svg)](https://david-dm.org/voidberg/imagecache-sharp#info=devDependencies&view=table)
65
[![Apache 2.0 License](https://img.shields.io/npm/l/imagecache-sharp.svg)](https://opensource.org/licenses/Apache-2.0)
76

87
## What is it?
98

109
Node image generation module based on [sharp](https://github.com/lovell/sharp) and inspired by Drupal's image styles.
1110

11+
**NOTE:** This is a beta of the 2.0 version, a full rewrite using TypeScript and the latest version of Sharp.
12+
1213
## Installation
1314

14-
* `npm install imagecache-sharp`
15+
- `npm install imagecache-sharp`
1516

1617
**Note:** please use the beta version that adds TypeScript support and works with the latest version of Sharp:
1718

1819
* `npm install imagecache-sharp@beta`
1920

2021
## Usage
2122

22-
```
23-
import presets from './presets';
24-
import ImageCache from 'imagecache-sharp';
25-
26-
const imagecache = new ImageCache(presets);
27-
28-
imagecache.render('./in.png', 'preset_one', (err, sharpInstance) => {
29-
if (err) {
30-
throw err;
31-
}
32-
33-
// Save the image
34-
sharpInstance.toFile('out.png', (err, info) => {
35-
// ...
36-
});
37-
38-
// Get a buffer, stream it etc
39-
sharpInstance.toBuffer((err, data, info) => {
40-
// ...
41-
});
42-
})
23+
```typescript
24+
import { ImageCache, Image } from "../src/imagecache";
25+
import presets from "./presets";
26+
27+
const imagecache: ImageCache = new ImageCache(presets);
28+
29+
const image: Image = await imagecache.render(
30+
"./in.png",
31+
"canvas_scale_with_blur"
32+
);
33+
34+
// Save the image
35+
await image.toFile("out_canvas_scale_with_blur.png");
36+
37+
// Get a buffer, stream it etc
38+
image.toBuffer(...)
4339
```
4440

45-
The render callback returns a `sharp` instance which can be used in various ways for outputting the final image. For a list of options see [sharp's documentation](http://sharp.dimens.io/en/stable/api-output/).
41+
The render function returns a `sharp.Sharp` instance (`Image` is just an alias for it) which can be used in various ways for outputting the final image. For a list of options see [sharp's documentation](https://sharp.pixelplumbing.com/api-constructor).
4642

4743
## Presets structure
4844

45+
A preset is defined like this:
46+
47+
```typescript
48+
type Preset = {
49+
presetName: string;
50+
actions: Action[];
51+
};
4952
```
50-
{
51-
preset_one: {
52-
presetname: 'preset_one',
53+
54+
An action contains an operation (which is defined by the plugins) and an optional config.
55+
56+
```typescript
57+
type Action = {
58+
action: string;
59+
config?: any;
60+
};
61+
```
62+
63+
Here are two example presets. The first one resizes and crops the image, puts it on a bigger canvas, then blurs it. The second one resizes and crops the image.
64+
65+
```typescript
66+
export default [
67+
{
68+
presetName: 'canvas_scale_with_blur',
5369
actions: [
5470
{
5571
action: 'scale_and_crop',
5672
config: {
57-
width: 100,
58-
height: 300
59-
}
73+
width: 152,
74+
height: 152,
75+
},
6076
},
6177
{
6278
action: 'define_canvas',
6379
config: {
6480
color: '#333333',
65-
width: 400,
66-
height: 400,
67-
xpos: 'center',
68-
ypos: 'center'
69-
}
70-
}
71-
]
81+
width: 400,
82+
height: 400,
83+
},
84+
},
85+
{
86+
action: 'blur',
87+
},
88+
],
7289
},
73-
preset_two: {
74-
presetname: 'preset_two',
90+
{
91+
presetName: 'scale_crop_tiny',
7592
actions: [
7693
{
7794
action: 'scale_and_crop',
7895
config: {
79-
width: 70,
80-
height: 70,
81-
}
82-
}
83-
]
84-
}
85-
}
96+
width: 32,
97+
height: 32,
98+
},
99+
},
100+
],
101+
},
102+
];
86103
```
87104

88105
## Imagecache actions:
@@ -94,7 +111,8 @@ Blurs the image.
94111
Action name: `blur`.
95112

96113
Configuration:
97-
* blur: A value between 0.3 and 1000 representing the sigma of the Gaussian mask. Defaults to `1`.
114+
115+
- `sigma`: A value between 0.3 and 1000 representing the sigma of the Gaussian mask. Defaults to `50`.
98116

99117
### Define canvas
100118

@@ -103,10 +121,11 @@ Defines a new canvas and overlays the current image.
103121
Action name: `define_canvas`.
104122

105123
Configuration:
106-
* width: The width of the canvas.
107-
* height: The height of the canvas.
108-
* channels: Number of channels. Defaults to `4`.
109-
* background: The background color of the canvas in hex format.
124+
125+
- `width`: The width of the canvas.
126+
- `height`: The height of the canvas.
127+
- `channels`: Number of channels. Defaults to `4`.
128+
- `background`: The background colour of the canvas in hex format.
110129

111130
### File
112131

@@ -115,10 +134,10 @@ Loads an image and overlays it on the current image.
115134
Action name: `file`.
116135

117136
Configuration:
118-
* path: The path of the file.
119-
* gravity: Gravity at which to place the overlay. Possible values are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Defaults to `center`.
120-
* tile: Set to true to repeat the overlay image across the entire image with the given `gravity`. Defaults to `false`.
121-
* cutout: Set to true to apply only the alpha channel of the overlay image to the input image, giving the appearance of one image being cut out of another. Defaults to `false`.
137+
138+
- `path`: The path of the file.
139+
- `gravity`: Gravity at which to place the overlay. Possible values are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Defaults to `center`.
140+
- `tile`: Set to true to repeat the overlay image across the entire image with the given `gravity`. Defaults to `false`.
122141

123142
### Flip
124143

@@ -127,7 +146,8 @@ Flips the image on a given axis.
127146
Action name: `flip`.
128147

129148
Configuration:
130-
* axis: The axis to flip on. Defaults to `y`.
149+
150+
- `axis`: The axis to flip on. Defaults to `y`.
131151

132152
### Gamma
133153

@@ -136,7 +156,8 @@ Apply a gamma correction to the image.
136156
Action name: `gamma`.
137157

138158
Configuration:
139-
* gamma: Value between 1.0 and 3.0. Defaults to `2.2`.
159+
160+
- `gamma`: Value between 1.0 and 3.0. Defaults to `2.2`.
140161

141162
### Greyscale
142163

@@ -163,7 +184,8 @@ Rotates the image based on the EXIF data or at a specified angle.
163184
Action name: `rotate`.
164185

165186
Configuration:
166-
* angle: Angle, multiple of 90. Defaults to `auto` which uses EXIF.
187+
188+
- `angle`: Angle, multiple of 90. Defaults to `auto` which uses EXIF.
167189

168190
### Scale
169191

@@ -172,19 +194,22 @@ Scales the image ignoring the aspect ratio.
172194
Action name: `scale`.
173195

174196
Configuration:
175-
* width: The width of the new image. Can be a number or a percent value.
176-
* height: The height of the new image. Can be a number or a percent value.
197+
198+
- `width`: The width of the new image. Can be a number or a percent value.
199+
- `height`: The height of the new image. Can be a number or a percent value.
200+
- `upscale`: Whether to upscale the image. Defaults to true.
177201

178202
### Scale and crop
179203

180-
Scales and crops the image mantaining the aspect ratio.
204+
Scales and crops the image maintaining the aspect ratio.
181205

182206
Action name: `scale_and_crop`.
183207

184208
Configuration:
185-
* width: The width of the new image. Can be a number or a percent value.
186-
* height: The height of the new image. Can be a number or a percent value.
187-
* gravity: Where to crop from. Possible values are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Defaults to `center`.
209+
210+
- `width`: The width of the new image. Can be a number or a percent value.
211+
- `height`: The height of the new image. Can be a number or a percent value.
212+
- `gravity`: Where to crop from. Possible values are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Defaults to `center`.
188213

189214
### Sharpen
190215

@@ -193,7 +218,7 @@ Sharpen the image.
193218
Action name: `sharpen`.
194219

195220
Configuration:
196-
* sigma: The sigma of the Gaussian mask. Defaults to `1`.
197-
* flat: The level of sharpening to apply to "flat" areas. Defaults to `1.0`.
198-
* jagged: The level of sharpening to apply to "jagged" areas. Defaults to `2.0`.
199221

222+
- `sigma`: The sigma of the Gaussian mask. Defaults to `1`.
223+
- `flat`: The level of sharpening to apply to "flat" areas. Defaults to `1.0`.
224+
- `jagged`: The level of sharpening to apply to "jagged" areas. Defaults to `2.0`.

0 commit comments

Comments
 (0)