Skip to content

Commit b7daf02

Browse files
committed
fix(image): accept OpenAI-style WxH for --size
Normalize 1024x1024 / 1024×1024 to width*height before the API call, and reject unknown ratios locally with USAGE instead of a server 400.
1 parent 179f9ea commit b7daf02

4 files changed

Lines changed: 45 additions & 26 deletions

File tree

packages/commands/src/commands/image/edit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const EDIT_FLAGS = {
6363
},
6464
size: {
6565
type: "string",
66-
valueHint: "<W*H>",
67-
description: "Output image size: ratio (3:4, 16:9) or pixels (2048*2048)",
66+
valueHint: "<W*H|WxH>",
67+
description: "Output image size: ratio (3:4, 16:9) or pixels (2048*2048 or 1024x1024)",
6868
},
6969
n: {
7070
type: "number",

packages/commands/src/commands/image/generate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const GENERATE_FLAGS = {
5252
},
5353
size: {
5454
type: "string",
55-
valueHint: "<W*H>",
56-
description: "Image size: ratio (3:4, 16:9, 1:1) or pixels (2048*2048)",
55+
valueHint: "<W*H|WxH>",
56+
description: "Image size: ratio (3:4, 16:9, 1:1) or pixels (2048*2048 or 1024x1024)",
5757
},
5858
n: {
5959
type: "number",

packages/runtime/src/utils/image-size.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { UsageError } from "bailian-cli-core";
2+
13
/**
24
* Resolve image `size` flag for image generate/edit.
35
*
46
* Users may pass either a ratio (e.g. "1:1", "3:4", "16:9") or a pixel size
5-
* (e.g. "2048*2048"). The DashScope API only accepts the pixel format, so we
7+
* (e.g. "2048*2048" / 1024×1024). The DashScope API only accepts the pixel format, so we
68
* map known ratios to the recommended pixel size for each model family.
79
*
810
* Sync models (qwen-image-2.0 / qwen-image-max / qwen-image-edit-2.0):
@@ -29,11 +31,28 @@ export const ASYNC_RATIO_MAP: Record<string, string> = {
2931
"9:16": "928*1664",
3032
};
3133

32-
/** Resolve `--size` value: accept ratio (3:4) or pixel (W*H) format. */
34+
/** Match pixel sizes: 1024*1024 / 1024x1024 / 1024×1024. */
35+
const PIXEL_SIZE_PATTERN = /^(\d+)\s*[x×*]\s*(\d+)$/i;
36+
37+
/** Resolve `--size`: map known ratios, or normalize pixels to W*H. */
3338
export function resolveImageSize(input: string, useSync: boolean): string;
3439
export function resolveImageSize(input: string | undefined, useSync: boolean): string | undefined;
3540
export function resolveImageSize(input: string | undefined, useSync: boolean): string | undefined {
3641
if (!input) return undefined;
42+
43+
const trimmed = input.trim();
3744
const map = useSync ? SYNC_RATIO_MAP : ASYNC_RATIO_MAP;
38-
return map[input] ?? input;
45+
46+
const mappedRatio = map[trimmed];
47+
if (mappedRatio) return mappedRatio;
48+
49+
const pixelMatch = trimmed.match(PIXEL_SIZE_PATTERN);
50+
if (pixelMatch) {
51+
return `${pixelMatch[1]}*${pixelMatch[2]}`;
52+
}
53+
54+
const knownRatios = Object.keys(map).join(", ");
55+
throw new UsageError(
56+
`Invalid --size "${input}". Use pixels (1024*1024 or 1024x1024) or a known ratio (${knownRatios}).`,
57+
);
3958
}

skills/bailian-cli/reference/image.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ Index: [index.md](index.md)
2424

2525
#### Flags
2626

27-
| Flag | Type | Required | Description |
28-
| --------------------------- | ------- | -------- | ----------------------------------------------------------------------- |
29-
| `--image <url>` | array | yes | Source image URL or local file path (repeatable for multi-image merge) |
30-
| `--prompt <text>` | string | yes | Edit instruction text |
31-
| `--model <model>` | string | no | Model ID (default: qwen-image-2.0) |
32-
| `--size <W*H>` | string | no | Output image size: ratio (3:4, 16:9) or pixels (2048\*2048) |
33-
| `--n <count>` | number | no | Number of images (default: 1, max: 6) |
34-
| `--seed <n>` | number | no | Random seed for reproducible results |
35-
| `--negative-prompt <text>` | string | no | Negative prompt to exclude unwanted content |
36-
| `--prompt-extend <bool>` | boolean | no | Enable prompt extend (true/false). Omit flag to use CLI default (true). |
37-
| `--watermark <bool>` | boolean | no | Enable watermark (true/false). Omit flag to use CLI default (true). |
38-
| `--out-dir <dir>` | string | no | Download images to directory |
39-
| `--out-prefix <prefix>` | string | no | Filename prefix (default: edited) |
40-
| `--async` | switch | no | Return async task id without waiting |
41-
| `--concurrent <n>` | number | no | Run N parallel requests (default: 1) |
42-
| `--poll-interval <seconds>` | number | no | Polling interval when waiting (default: 3) |
43-
| `--api-key <key>` | string | no | API key |
44-
| `--base-url <url>` | string | no | API base URL |
27+
| Flag | Type | Required | Description |
28+
| --------------------------- | ------- | -------- | ------------------------------------------------------------------------ |
29+
| `--image <url>` | array | yes | Source image URL or local file path (repeatable for multi-image merge) |
30+
| `--prompt <text>` | string | yes | Edit instruction text |
31+
| `--model <model>` | string | no | Model ID (default: qwen-image-2.0) |
32+
| `--size <W*H\|WxH>` | string | no | Output image size: ratio (3:4, 16:9) or pixels (2048\*2048 or 1024x1024) |
33+
| `--n <count>` | number | no | Number of images (default: 1, max: 6) |
34+
| `--seed <n>` | number | no | Random seed for reproducible results |
35+
| `--negative-prompt <text>` | string | no | Negative prompt to exclude unwanted content |
36+
| `--prompt-extend <bool>` | boolean | no | Enable prompt extend (true/false). Omit flag to use CLI default (true). |
37+
| `--watermark <bool>` | boolean | no | Enable watermark (true/false). Omit flag to use CLI default (true). |
38+
| `--out-dir <dir>` | string | no | Download images to directory |
39+
| `--out-prefix <prefix>` | string | no | Filename prefix (default: edited) |
40+
| `--async` | switch | no | Return async task id without waiting |
41+
| `--concurrent <n>` | number | no | Run N parallel requests (default: 1) |
42+
| `--poll-interval <seconds>` | number | no | Polling interval when waiting (default: 3) |
43+
| `--api-key <key>` | string | no | API key |
44+
| `--base-url <url>` | string | no | API base URL |
4545

4646
#### Examples
4747

@@ -83,7 +83,7 @@ bl image edit --image ./photo.png --prompt "Replace the background with a beach"
8383
| --------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
8484
| `--prompt <text>` | string | yes | Image description |
8585
| `--model <model>` | string | no | Model ID (default: qwen-image-2.0) |
86-
| `--size <W*H>` | string | no | Image size: ratio (3:4, 16:9, 1:1) or pixels (2048\*2048) |
86+
| `--size <W*H\|WxH>` | string | no | Image size: ratio (3:4, 16:9, 1:1) or pixels (2048\*2048 or 1024x1024) |
8787
| `--n <count>` | number | no | Number of images per request (default: 1, max: 6) |
8888
| `--seed <n>` | number | no | Random seed for reproducible generation |
8989
| `--negative-prompt <text>` | string | no | Negative prompt to exclude unwanted content |

0 commit comments

Comments
 (0)