Merge pull request '保留 98K 生图的自动比例和清晰度' (#117) from codex/fix-98k-auto-image-size-20261123 into main
This commit is contained in:
commit
3c8f2174c5
@ -1796,16 +1796,25 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
||||
Array.isArray(configuredSizes) &&
|
||||
configuredSizes.length === 1 &&
|
||||
configuredSizes[0] === "1K";
|
||||
if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) {
|
||||
const acceptsResolutionAsSize = sizes?.includes(resolution);
|
||||
const acceptsAutomaticSize =
|
||||
sizes?.includes("auto") &&
|
||||
[body.resolution, body.imageSize, body.image_size].includes(resolution);
|
||||
if (
|
||||
!aspectRatio &&
|
||||
automaticRatioField &&
|
||||
hasNativeResolution &&
|
||||
(acceptsResolutionAsSize || acceptsAutomaticSize)
|
||||
) {
|
||||
body[automaticRatioField] = "auto";
|
||||
body.size = resolution;
|
||||
body.size = acceptsResolutionAsSize ? resolution : "auto";
|
||||
} else if (hasSeparateAspectRatio && fixedOneK && sizes?.includes("auto") && ratios.includes(selectedRatio)) {
|
||||
// A fixed-tier route can use its explicit ratio without a second geometry
|
||||
// constraint. Its published pixel presets may round the nominal ratio.
|
||||
body.size = "auto";
|
||||
} else if (ratios.includes(selectedRatio)) {
|
||||
body.size = selectedRatio;
|
||||
} else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution;
|
||||
} else if (acceptsResolutionAsSize && hasNativeAspectRatio) body.size = resolution;
|
||||
else if (pixels.length && (resolution || aspectRatio)) {
|
||||
const [rw, rh] = selectedRatio.split(":").map(Number);
|
||||
const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025);
|
||||
|
||||
@ -131,6 +131,29 @@ test("automatic proportions stay automatic at every published resolution with re
|
||||
}
|
||||
});
|
||||
|
||||
test("async image contracts keep automatic size when resolution is a separate field", () => {
|
||||
const contract = {
|
||||
...invocation({
|
||||
size: { enum: ["auto", "1024x1024", "2048x2048", "4096x4096"] },
|
||||
resolution: { enum: ["1K", "2K", "4K"] },
|
||||
aspect_ratio: { enum: ["auto", "1:1", "3:4", "16:9"] },
|
||||
file_urls: { type: "array", items: { type: "string" } },
|
||||
}, { size: "auto", resolution: "1K", aspect_ratio: "auto" }),
|
||||
path: "/extensions/v1/tasks",
|
||||
};
|
||||
const imageUrls = ["https://example.com/reference.png"];
|
||||
for (const imageSize of ["1K", "2K", "4K"]) {
|
||||
const { body } = buildTaskBody({
|
||||
...params, modelId: "nano-banana-2.1", imageUrls, imageParams: { imageSize, aspectRatio: "auto" },
|
||||
}, contract);
|
||||
expect(body).toMatchObject({ size: "auto", resolution: imageSize, aspect_ratio: "auto", file_urls: imageUrls });
|
||||
}
|
||||
const { body } = buildTaskBody({
|
||||
...params, modelId: "nano-banana-2.1", imageUrls, imageParams: { imageSize: "4K", aspectRatio: "1:1" },
|
||||
}, contract);
|
||||
expect(body).toMatchObject({ size: "4096x4096", resolution: "4K", aspect_ratio: "1:1" });
|
||||
});
|
||||
|
||||
test("4K uses the largest published square size for area-based image contracts", () => {
|
||||
const result=buildTaskBody({...params,imageParams:{imageSize:"4K",aspectRatio:"1:1"}},invocation({size:{enum:["1024x1024","2048x2048","2880x2880"]},resolution:{enum:["1K","2K","4K"]}}));
|
||||
expect(result.body).toMatchObject({size:"2880x2880",resolution:"4K"});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user