Skip to content

Commit f709f30

Browse files
committed
Round canvas values
1 parent ef37fc9 commit f709f30

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

slice.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,23 @@ const options = yargs
4444
alias: 'canvasWidth',
4545
describe: 'Width of canvas for final output',
4646
type: 'number',
47+
coerce: (value) => {
48+
if (value !== undefined && value < 1) {
49+
throw new Error('canvasWidth should not be lower than 1');
50+
}
51+
return Math.round(value);
52+
},
4753
})
4854
.option('g', {
4955
alias: 'canvasHeight',
5056
describe: 'Height of canvas for final output',
5157
type: 'number',
58+
coerce: (value) => {
59+
if (value !== undefined && value < 1) {
60+
throw new Error('canvasHeight should not be lower than 1');
61+
}
62+
return Math.round(value);
63+
},
5264
}).argv;
5365
if (options.filename) {
5466
// Process a single image

src/slice.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,23 @@ const options = yargs
4545
alias: 'canvasWidth',
4646
describe: 'Width of canvas for final output',
4747
type: 'number',
48+
coerce: (value) => {
49+
if (value !== undefined && value < 1) {
50+
throw new Error('canvasWidth should not be lower than 1');
51+
}
52+
return Math.round(value);
53+
},
4854
})
4955
.option('g', {
5056
alias: 'canvasHeight',
5157
describe: 'Height of canvas for final output',
5258
type: 'number',
59+
coerce: (value) => {
60+
if (value !== undefined && value < 1) {
61+
throw new Error('canvasHeight should not be lower than 1');
62+
}
63+
return Math.round(value);
64+
},
5365
}).argv as unknown as Options;
5466

5567
if (options.filename) {

0 commit comments

Comments
 (0)