This commit is contained in:
Christopher Monsanto
2020-07-17 08:09:07 -04:00
parent 6f27c6689a
commit ad51a0464b
5 changed files with 24 additions and 4 deletions

5
pnpm-lock.yaml generated
View File

@@ -40,9 +40,14 @@ importers:
spritesmith: ^3.4.0
tools/trim:
dependencies:
'@types/node': 14.0.23
commander: 5.1.0
devDependencies:
typescript: 3.9.7
specifiers:
'@types/node': ^14.0.23
commander: ^5.1.0
typescript: ^3.9.7
tools/tupctime:
dependencies:
better-sqlite3: 7.0.1

View File

@@ -1,7 +1,7 @@
import cp from 'child_process';
export function getDims(input) {
export function getDims(input : string) {
const info = cp.execFileSync('convert', [input, '-format', "%w+%h+%@", 'info:'],
{encoding:'utf8'});
@@ -21,13 +21,13 @@ export function getDims(input) {
}
}
export function crop(input, {width, height, left, top}, output) {
export function crop(input : string, {width, height, left, top} : {width : number, height: number, left: number, top: number}, output : string) {
cp.execFileSync('convert', [input, '+repage', '-crop', `${width}x${height}+${left}+${top}`, output]);
}
// Trim, preserving displacement from center
// Returns crop coords
export function losslessTrim(dims) {
export function losslessTrim(dims : {width : number, height: number, left: number, top: number, bottom: number, right: number}) {
return {
left: Math.min(dims.left, dims.right),
width: dims.width + Math.abs(dims.left - dims.right),

View File

@@ -1,6 +1,14 @@
{
"dependencies": {
"@types/node": "^14.0.23",
"commander": "^5.1.0"
},
"type": "module"
"type": "module",
"main": "./dist/index.js",
"scripts": {
"prepare": "tsc"
},
"devDependencies": {
"typescript": "^3.9.7"
}
}

7
tools/trim/tsconfig.json Normal file
View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig-base",
"compilerOptions": {
"outDir": "dist",
"allowJs": true
}
}