fix: keep 4K image dimensions consistent with resolution
This commit is contained in:
parent
5701e95bb4
commit
f980cfb036
@ -1763,7 +1763,7 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca
|
||||
const [rw, rh] = selectedRatio.split(":").map(Number);
|
||||
const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025);
|
||||
if (!matching.length) throw Error("当前模型不支持所选图片比例");
|
||||
const area = resolution === "4K" ? 2880 ** 2 : resolution === "2K" ? 2048 ** 2 : 1024 ** 2;
|
||||
const area = resolution === "4K" ? 4096 ** 2 : resolution === "2K" ? 2048 ** 2 : 1024 ** 2;
|
||||
matching.sort((a, b) => Math.abs(a.width * a.height - area) - Math.abs(b.width * b.height - area));
|
||||
body.size = matching[0].size;
|
||||
}
|
||||
|
||||
@ -51,6 +51,19 @@ test("pixel-only image contracts use a supported size in the requested tier", ()
|
||||
const result = buildTaskBody(params,invocation({size:{enum:["1024x1024","1280x720","2048x1152","3840x2160"]}},{size:"1024x1024"}));
|
||||
expect(result.body.size).toBe("2048x1152");
|
||||
});
|
||||
|
||||
test("square image dimensions agree with the requested resolution tier", () => {
|
||||
const contract=invocation({size:{enum:["auto","1024x1024","2048x2048","4096x4096"]},resolution:{enum:["1K","2K","4K"]},aspect_ratio:{enum:["1:1"]}},{size:"1024x1024",resolution:"1K"});
|
||||
for(const [imageSize,size] of [["1K","1024x1024"],["2K","2048x2048"],["4K","4096x4096"]]) {
|
||||
const result=buildTaskBody({...params,modelId:"nano-banana-2",imageParams:{imageSize,aspectRatio:"1:1"}},contract);
|
||||
expect(result.body).toMatchObject({size,resolution:imageSize,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"});
|
||||
});
|
||||
test("OpenAI image size fields receive pixel dimensions instead of a resolution label", () => {
|
||||
const result = buildTaskBody({...params,modelId:"gpt-image-2"},invocation({size:{type:["string","null"]}}));
|
||||
expect(result.body.size).toMatch(/^\d+x\d+$/);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user