mirror of
https://github.com/smogon/sprites.git
synced 2026-08-26 11:45:16 -05:00
ts trim
This commit is contained in:
5
pnpm-lock.yaml
generated
5
pnpm-lock.yaml
generated
@@ -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
|
||||
|
||||
@@ -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),
|
||||
@@ -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
7
tools/trim/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig-base",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"allowJs": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user