@koda-sl/baker-cli 0.35.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -7
- package/dist/cli.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/commands/ads/google/error-parser.js +1 -1
- package/dist/commands/ads/google/error-parser.js.map +1 -1
- package/dist/commands/ads/google/preflight.d.ts.map +1 -1
- package/dist/commands/ads/google/preflight.js +20 -0
- package/dist/commands/ads/google/preflight.js.map +1 -1
- package/dist/commands/ads/google/preflight.test.js +6 -0
- package/dist/commands/ads/google/preflight.test.js.map +1 -1
- package/dist/commands/images/crop.d.ts +33 -0
- package/dist/commands/images/crop.d.ts.map +1 -0
- package/dist/commands/images/crop.js +90 -0
- package/dist/commands/images/crop.js.map +1 -0
- package/dist/commands/images/dimensions.d.ts +8 -0
- package/dist/commands/images/dimensions.d.ts.map +1 -0
- package/dist/commands/images/dimensions.js +56 -0
- package/dist/commands/images/dimensions.js.map +1 -0
- package/dist/commands/images/index.d.ts.map +1 -1
- package/dist/commands/images/index.js +20 -2
- package/dist/commands/images/index.js.map +1 -1
- package/dist/commands/images/normalize.d.ts +54 -0
- package/dist/commands/images/normalize.d.ts.map +1 -0
- package/dist/commands/images/normalize.js +252 -0
- package/dist/commands/images/normalize.js.map +1 -0
- package/dist/commands/images/upscale.d.ts +13 -0
- package/dist/commands/images/upscale.d.ts.map +1 -0
- package/dist/commands/images/upscale.js +73 -0
- package/dist/commands/images/upscale.js.map +1 -0
- package/dist/lib/image/color-changer.d.ts +16 -0
- package/dist/lib/image/color-changer.d.ts.map +1 -0
- package/dist/lib/image/color-changer.js +366 -0
- package/dist/lib/image/color-changer.js.map +1 -0
- package/dist/lib/image/color-changer.test.d.ts +2 -0
- package/dist/lib/image/color-changer.test.d.ts.map +1 -0
- package/dist/lib/image/color-changer.test.js +131 -0
- package/dist/lib/image/color-changer.test.js.map +1 -0
- package/dist/lib/image/crop-sprite.d.ts +9 -0
- package/dist/lib/image/crop-sprite.d.ts.map +1 -0
- package/dist/lib/image/crop-sprite.js +13 -0
- package/dist/lib/image/crop-sprite.js.map +1 -0
- package/dist/lib/image/dimensions.d.ts +9 -0
- package/dist/lib/image/dimensions.d.ts.map +1 -0
- package/dist/lib/image/dimensions.js +13 -0
- package/dist/lib/image/dimensions.js.map +1 -0
- package/dist/lib/image/image-processor.d.ts +26 -0
- package/dist/lib/image/image-processor.d.ts.map +1 -0
- package/dist/lib/image/image-processor.js +185 -0
- package/dist/lib/image/image-processor.js.map +1 -0
- package/dist/lib/image/io.d.ts +29 -0
- package/dist/lib/image/io.d.ts.map +1 -0
- package/dist/lib/image/io.js +90 -0
- package/dist/lib/image/io.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const normalizeCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly files: {
|
|
3
|
+
readonly type: "positional";
|
|
4
|
+
readonly description: "Single path, glob (quote it), or comma-separated list";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly color: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "Recolor target as hex";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly "remove-bg": {
|
|
13
|
+
readonly type: "boolean";
|
|
14
|
+
readonly description: "Two-pass background removal";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
};
|
|
17
|
+
readonly "shrink-to-content": {
|
|
18
|
+
readonly type: "boolean";
|
|
19
|
+
readonly description: "Trim transparent borders";
|
|
20
|
+
readonly required: false;
|
|
21
|
+
};
|
|
22
|
+
readonly height: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly description: "Resize to N px tall, width auto";
|
|
25
|
+
readonly required: false;
|
|
26
|
+
};
|
|
27
|
+
readonly width: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly description: "Resize to N px wide, height auto";
|
|
30
|
+
readonly required: false;
|
|
31
|
+
};
|
|
32
|
+
readonly size: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly description: "Fit into a WxH box (e.g. 200x200)";
|
|
35
|
+
readonly required: false;
|
|
36
|
+
};
|
|
37
|
+
readonly fit: {
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
readonly description: "contain (default) or cover (with --size)";
|
|
40
|
+
readonly required: false;
|
|
41
|
+
};
|
|
42
|
+
readonly output: {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
readonly description: "Output path or directory";
|
|
45
|
+
readonly required: false;
|
|
46
|
+
};
|
|
47
|
+
readonly "dry-run": {
|
|
48
|
+
readonly type: "boolean";
|
|
49
|
+
readonly description: "Preview without writing";
|
|
50
|
+
readonly required: false;
|
|
51
|
+
readonly default: false;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/commands/images/normalize.ts"],"names":[],"mappings":"AAsQA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmD3B,CAAC"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { parseHex } from "../../lib/image/color-changer.js";
|
|
3
|
+
import { processImage } from "../../lib/image/image-processor.js";
|
|
4
|
+
import { atomicWrite, expandInputs, isDirectory, isRemoteUrl, readImageBuffer, resolveOutputPath, } from "../../lib/image/io.js";
|
|
5
|
+
import { writeJson } from "../../output.js";
|
|
6
|
+
import { registerSchema } from "../../schemas.js";
|
|
7
|
+
registerSchema({
|
|
8
|
+
command: "images.normalize",
|
|
9
|
+
description: "Normalize one or more local images: alpha-preserving recolor, two-pass background removal, trim, and resize. Declarative — describe the desired final state via flags; the pipeline runs the needed stages in order. Writes in-place by default. For upscaling, use 'baker images upscale <imageId>' after uploading.",
|
|
10
|
+
args: {
|
|
11
|
+
files: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Single path, glob (quote it), or comma-separated list. Commas are treated as separators — paths containing commas are not supported. Use 'logos/*.png', 'a.png,b.png', or 'logo.png'.",
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
color: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Recolor target as hex (e.g. '#FFFFFF', '#fff'). Omit to keep original colors.",
|
|
19
|
+
required: false,
|
|
20
|
+
},
|
|
21
|
+
"remove-bg": {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
description: "Two-pass background removal. Default true when --color is set, false otherwise. Idempotent on already-transparent input.",
|
|
24
|
+
required: false,
|
|
25
|
+
},
|
|
26
|
+
"shrink-to-content": {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
description: "Trim transparent borders after bg removal. Default true when --remove-bg is on.",
|
|
29
|
+
required: false,
|
|
30
|
+
},
|
|
31
|
+
height: {
|
|
32
|
+
type: "number",
|
|
33
|
+
description: "Resize to N pixels tall, width auto (preserves aspect). Mutex with --size.",
|
|
34
|
+
required: false,
|
|
35
|
+
},
|
|
36
|
+
width: {
|
|
37
|
+
type: "number",
|
|
38
|
+
description: "Resize to N pixels wide, height auto (preserves aspect). Mutex with --size.",
|
|
39
|
+
required: false,
|
|
40
|
+
},
|
|
41
|
+
size: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Fit into a W×H box. Format 'WxH' (e.g. '200x200'). Mutex with --height/--width.",
|
|
44
|
+
required: false,
|
|
45
|
+
},
|
|
46
|
+
fit: {
|
|
47
|
+
type: "string",
|
|
48
|
+
description: "Used with --size: 'contain' (default, letterbox transparent) or 'cover' (crop to fill).",
|
|
49
|
+
required: false,
|
|
50
|
+
enum: ["contain", "cover"],
|
|
51
|
+
},
|
|
52
|
+
output: {
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "Output path. Default: in-place. With multiple inputs, must be a directory.",
|
|
55
|
+
required: false,
|
|
56
|
+
},
|
|
57
|
+
"dry-run": {
|
|
58
|
+
type: "boolean",
|
|
59
|
+
description: "Resolve inputs + pipeline without writing any files.",
|
|
60
|
+
required: false,
|
|
61
|
+
default: false,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
class ValidationError extends Error {
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = "ValidationError";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function parseSize(raw) {
|
|
72
|
+
const match = /^(\d+)x(\d+)$/i.exec(raw.trim());
|
|
73
|
+
if (!match || match.length < 3) {
|
|
74
|
+
throw new ValidationError(`Invalid --size value "${raw}". Expected WxH (e.g. 200x200).`);
|
|
75
|
+
}
|
|
76
|
+
const [, w, h] = match;
|
|
77
|
+
return { width: Number.parseInt(w ?? "", 10), height: Number.parseInt(h ?? "", 10) };
|
|
78
|
+
}
|
|
79
|
+
function parseResize(args) {
|
|
80
|
+
const hasSize = typeof args.size === "string" && args.size.length > 0;
|
|
81
|
+
const hasHeight = typeof args.height === "number";
|
|
82
|
+
const hasWidth = typeof args.width === "number";
|
|
83
|
+
if (hasSize && (hasHeight || hasWidth)) {
|
|
84
|
+
throw new ValidationError("--height/--width and --size are mutually exclusive");
|
|
85
|
+
}
|
|
86
|
+
if (args.fit !== undefined && !hasSize) {
|
|
87
|
+
throw new ValidationError("--fit requires --size");
|
|
88
|
+
}
|
|
89
|
+
if (hasSize && typeof args.size === "string") {
|
|
90
|
+
return {
|
|
91
|
+
size: parseSize(args.size),
|
|
92
|
+
fit: (args.fit ?? "contain"),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (hasHeight || hasWidth) {
|
|
96
|
+
return { width: args.width, height: args.height };
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
function parseColor(raw) {
|
|
101
|
+
if (typeof raw !== "string" || raw.length === 0)
|
|
102
|
+
return undefined;
|
|
103
|
+
try {
|
|
104
|
+
return parseHex(raw);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
throw new ValidationError(err instanceof Error ? err.message : "Invalid --color");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function buildOptions(args) {
|
|
111
|
+
const resize = parseResize(args);
|
|
112
|
+
const color = parseColor(args.color);
|
|
113
|
+
const removeBackground = typeof args["remove-bg"] === "boolean" ? args["remove-bg"] : color !== undefined;
|
|
114
|
+
const shrinkToContent = typeof args["shrink-to-content"] === "boolean" ? args["shrink-to-content"] : removeBackground;
|
|
115
|
+
return {
|
|
116
|
+
options: { color, removeBackground, shrinkToContent, resize },
|
|
117
|
+
outputArg: typeof args.output === "string" && args.output.length > 0 ? args.output : undefined,
|
|
118
|
+
dryRun: args["dry-run"] === true,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function colorToHex(color) {
|
|
122
|
+
if (!color)
|
|
123
|
+
return null;
|
|
124
|
+
return `#${[color.r, color.g, color.b].map((n) => n.toString(16).padStart(2, "0")).join("")}`;
|
|
125
|
+
}
|
|
126
|
+
async function processFile(inputPath, options, outputArg, multipleInputs) {
|
|
127
|
+
const inputBuffer = await readImageBuffer(inputPath);
|
|
128
|
+
const result = await processImage(inputBuffer, options);
|
|
129
|
+
const newExt = result.format === "png" ? ".png" : ".svg";
|
|
130
|
+
const outputPath = await resolveOutputPath(inputPath, outputArg, { multipleInputs, newExtension: newExt });
|
|
131
|
+
await atomicWrite(outputPath, result.buffer);
|
|
132
|
+
return {
|
|
133
|
+
input: inputPath,
|
|
134
|
+
output: outputPath,
|
|
135
|
+
format: result.format,
|
|
136
|
+
width: result.width,
|
|
137
|
+
height: result.height,
|
|
138
|
+
sizeBytes: result.buffer.length,
|
|
139
|
+
stages: result.stages,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
async function resolveInputs(spec) {
|
|
143
|
+
const all = await expandInputs(spec);
|
|
144
|
+
if (all.length === 0) {
|
|
145
|
+
throw new ValidationError(`No files matched "${spec}"`);
|
|
146
|
+
}
|
|
147
|
+
const remote = all.filter(isRemoteUrl);
|
|
148
|
+
if (remote.length > 0) {
|
|
149
|
+
throw new ValidationError("Remote URLs are not supported by 'normalize'. Download the file first or use a local path.");
|
|
150
|
+
}
|
|
151
|
+
return all;
|
|
152
|
+
}
|
|
153
|
+
function emitDryRun(inputs, normalized) {
|
|
154
|
+
writeJson({
|
|
155
|
+
ok: true,
|
|
156
|
+
dryRun: true,
|
|
157
|
+
operation: "images.normalize",
|
|
158
|
+
params: {
|
|
159
|
+
inputs,
|
|
160
|
+
options: {
|
|
161
|
+
color: colorToHex(normalized.options.color),
|
|
162
|
+
removeBackground: normalized.options.removeBackground ?? false,
|
|
163
|
+
shrinkToContent: normalized.options.shrinkToContent ?? false,
|
|
164
|
+
resize: normalized.options.resize ?? null,
|
|
165
|
+
},
|
|
166
|
+
outputArg: normalized.outputArg ?? null,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function emitError(err) {
|
|
171
|
+
if (err instanceof ValidationError) {
|
|
172
|
+
writeJson({ ok: false, error: { code: "VALIDATION_ERROR", message: err.message } });
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const message = err instanceof Error ? err.message : "Unexpected error";
|
|
176
|
+
writeJson({ ok: false, error: { code: "IMAGE_PROCESSING_ERROR", message } });
|
|
177
|
+
}
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
function coerceRawArgs(args) {
|
|
181
|
+
const num = (v) => {
|
|
182
|
+
if (typeof v === "number")
|
|
183
|
+
return v;
|
|
184
|
+
if (typeof v === "string" && v.length > 0) {
|
|
185
|
+
const n = Number(v);
|
|
186
|
+
return Number.isFinite(n) ? n : undefined;
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
};
|
|
190
|
+
const str = (v) => (typeof v === "string" ? v : undefined);
|
|
191
|
+
const bool = (v) => (typeof v === "boolean" ? v : undefined);
|
|
192
|
+
return {
|
|
193
|
+
files: str(args.files),
|
|
194
|
+
color: str(args.color),
|
|
195
|
+
"remove-bg": bool(args["remove-bg"]),
|
|
196
|
+
"shrink-to-content": bool(args["shrink-to-content"]),
|
|
197
|
+
height: num(args.height),
|
|
198
|
+
width: num(args.width),
|
|
199
|
+
size: str(args.size),
|
|
200
|
+
fit: str(args.fit),
|
|
201
|
+
output: str(args.output),
|
|
202
|
+
"dry-run": bool(args["dry-run"]),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export const normalizeCommand = defineCommand({
|
|
206
|
+
meta: {
|
|
207
|
+
name: "normalize",
|
|
208
|
+
description: 'Normalize logos / images: declarative recolor + bg removal + trim + resize. Operates on local files; writes in-place by default.\n\nExamples:\n baker images normalize "logos/*.png" --color \'#FFFFFF\' --height 200\n baker images normalize logo.png --remove-bg --shrink-to-content\n baker images normalize "a.png,b.png" --size 200x200 --fit cover --output ./out',
|
|
209
|
+
},
|
|
210
|
+
args: {
|
|
211
|
+
files: {
|
|
212
|
+
type: "positional",
|
|
213
|
+
description: "Single path, glob (quote it), or comma-separated list",
|
|
214
|
+
required: false,
|
|
215
|
+
},
|
|
216
|
+
color: { type: "string", description: "Recolor target as hex", required: false },
|
|
217
|
+
"remove-bg": { type: "boolean", description: "Two-pass background removal", required: false },
|
|
218
|
+
"shrink-to-content": { type: "boolean", description: "Trim transparent borders", required: false },
|
|
219
|
+
height: { type: "string", description: "Resize to N px tall, width auto", required: false },
|
|
220
|
+
width: { type: "string", description: "Resize to N px wide, height auto", required: false },
|
|
221
|
+
size: { type: "string", description: "Fit into a WxH box (e.g. 200x200)", required: false },
|
|
222
|
+
fit: { type: "string", description: "contain (default) or cover (with --size)", required: false },
|
|
223
|
+
output: { type: "string", description: "Output path or directory", required: false },
|
|
224
|
+
"dry-run": { type: "boolean", description: "Preview without writing", required: false, default: false },
|
|
225
|
+
},
|
|
226
|
+
run: async ({ args }) => {
|
|
227
|
+
try {
|
|
228
|
+
const raw = coerceRawArgs(args);
|
|
229
|
+
if (!raw.files) {
|
|
230
|
+
throw new ValidationError("files argument is required");
|
|
231
|
+
}
|
|
232
|
+
const inputs = await resolveInputs(raw.files);
|
|
233
|
+
const normalized = buildOptions(raw);
|
|
234
|
+
if (inputs.length > 1 && normalized.outputArg && !(await isDirectory(normalized.outputArg))) {
|
|
235
|
+
throw new ValidationError(`--output must be an existing directory when processing multiple files (got "${normalized.outputArg}")`);
|
|
236
|
+
}
|
|
237
|
+
if (normalized.dryRun) {
|
|
238
|
+
emitDryRun(inputs, normalized);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const processed = [];
|
|
242
|
+
for (const inputPath of inputs) {
|
|
243
|
+
processed.push(await processFile(inputPath, normalized.options, normalized.outputArg, inputs.length > 1));
|
|
244
|
+
}
|
|
245
|
+
writeJson({ ok: true, data: { processed } });
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
emitError(err);
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/commands/images/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAc,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAA0B,YAAY,EAAsB,MAAM,oCAAoC,CAAC;AAC9G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,eAAe,EACf,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,cAA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AAoB,EAAE,CAAC;YACtC,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;gBAC/B,SAAS,CAAC,IAAI,CAAC,MAAM,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YAC5G,CAAC;YACD,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,SAAS,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const upscaleCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "image-id": {
|
|
3
|
+
readonly type: "positional";
|
|
4
|
+
readonly description: "Library image ID";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly "max-wait": {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "Max wait ms (default 120000, 0 = no wait)";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=upscale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upscale.d.ts","sourceRoot":"","sources":["../../../src/commands/images/upscale.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,cAAc;;;;;;;;;;;EAwDzB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { ApiError, apiGet, apiPost } from "../../client.js";
|
|
3
|
+
import { writeJson } from "../../output.js";
|
|
4
|
+
import { registerSchema } from "../../schemas.js";
|
|
5
|
+
registerSchema({
|
|
6
|
+
command: "images.upscale",
|
|
7
|
+
description: "Upscale a library image via the backend (Replicate, cost-tracked). Waits for completion by default. The image must be status 'ready' and raster (not SVG/AVIF).",
|
|
8
|
+
args: {
|
|
9
|
+
"image-id": { type: "string", description: "Library image ID to upscale", required: true },
|
|
10
|
+
"max-wait": {
|
|
11
|
+
type: "number",
|
|
12
|
+
description: "Max wait ms (default 120000 = 2 min). Set 0 to fire-and-forget.",
|
|
13
|
+
required: false,
|
|
14
|
+
default: 120000,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const POLL_INTERVAL_MS = 1500;
|
|
19
|
+
export const upscaleCommand = defineCommand({
|
|
20
|
+
meta: {
|
|
21
|
+
name: "upscale",
|
|
22
|
+
description: "Upscale a library image via the Convex backend (Replicate, cost-tracked at $0.05/image). Waits for completion by default.\n\nExample: baker images upscale j571abc123def\nExample: baker images upscale j571abc123def --max-wait 0 # fire-and-forget",
|
|
23
|
+
},
|
|
24
|
+
args: {
|
|
25
|
+
"image-id": { type: "positional", description: "Library image ID", required: false },
|
|
26
|
+
"max-wait": { type: "string", description: "Max wait ms (default 120000, 0 = no wait)", required: false },
|
|
27
|
+
},
|
|
28
|
+
run: async ({ args }) => {
|
|
29
|
+
try {
|
|
30
|
+
const imageId = args["image-id"];
|
|
31
|
+
if (!imageId) {
|
|
32
|
+
writeJson({ ok: false, error: { code: "VALIDATION_ERROR", message: "image-id is required" } });
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const maxWait = args["max-wait"] ? Number(args["max-wait"]) : 120000;
|
|
36
|
+
await apiPost("/api/images/upscale", { imageId });
|
|
37
|
+
if (maxWait === 0) {
|
|
38
|
+
writeJson({ ok: true, data: { imageId, status: "processing" } });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
while (Date.now() - start < maxWait) {
|
|
43
|
+
const doc = await apiGet("/api/images/get", { id: imageId });
|
|
44
|
+
if (doc.upscaleConfig?.status === "completed") {
|
|
45
|
+
writeJson({ ok: true, data: { imageId, status: "completed", image: doc } });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (doc.upscaleConfig?.status === "error") {
|
|
49
|
+
writeJson({
|
|
50
|
+
ok: false,
|
|
51
|
+
error: { code: "IMAGE_PROCESSING_ERROR", message: doc.upscaleConfig.error ?? "Upscale failed" },
|
|
52
|
+
});
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
56
|
+
}
|
|
57
|
+
writeJson({ ok: false, error: { code: "TIMEOUT", message: `Image not ready within ${maxWait}ms` } });
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err instanceof ApiError) {
|
|
62
|
+
writeJson({ ok: false, error: { code: err.code, message: err.message } });
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
writeJson({
|
|
66
|
+
ok: false,
|
|
67
|
+
error: { code: "INTERNAL_ERROR", message: err instanceof Error ? err.message : "Unexpected error" },
|
|
68
|
+
});
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=upscale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upscale.js","sourceRoot":"","sources":["../../../src/commands/images/upscale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,cAAc,CAAC;IACb,OAAO,EAAE,gBAAgB;IACzB,WAAW,EACT,iKAAiK;IACnK,IAAI,EAAE;QACJ,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,E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G,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBAC5B,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,SAAS,CAAC;gBACR,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,EAAE;aACpG,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Color {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const COLOR_RANGE_THRESHOLD = 15;
|
|
7
|
+
export declare function parseHex(hex: string): Color;
|
|
8
|
+
export declare function colorDistance(color1: Color, color2: Color): number;
|
|
9
|
+
export declare function getDominantEdgeColor(data: Buffer, width: number, height: number): Color;
|
|
10
|
+
export declare function hasTransparency(data: Buffer, threshold?: number): boolean;
|
|
11
|
+
export declare function removeBackground(data: Buffer, width: number, height: number, colorRangeThreshold?: number): Buffer;
|
|
12
|
+
export declare function applyQuantization(data: Buffer, numColors: number): Buffer;
|
|
13
|
+
export declare function findColorRange(data: Buffer, ignoredColor?: Color | null): Color[];
|
|
14
|
+
export declare function findColorRangeWithThreshold(data: Buffer, threshold: number, ignoredColor?: Color | null): Color[];
|
|
15
|
+
export declare function solidifyEdges(data: Buffer, saturationBoost?: number): Buffer;
|
|
16
|
+
//# sourceMappingURL=color-changer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-changer.d.ts","sourceRoot":"","sources":["../../../src/lib/image/color-changer.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAIxC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAiB3C;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,CAKlE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CA6BvF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,OAAO,CAWvE;AAsDD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,mBAAmB,SAAwB,GAC1C,MAAM,CAkDR;AAeD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA2CzE;AAyED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,GAAE,KAAK,GAAG,IAAW,GAAG,KAAK,EAAE,CAEvF;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,YAAY,GAAE,KAAK,GAAG,IAAW,GAChC,KAAK,EAAE,CAET;AAyDD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,SAAO,GAAG,MAAM,CAiB1E"}
|