Preserve auto aspect ratio for image generation
This commit is contained in:
parent
c2a0568148
commit
232f634cc6
@ -25,7 +25,7 @@ function toGenerateImagePayload(body: GenerateImageRequest): CanvasGenerateImage
|
||||
aspectRatio:
|
||||
typeof body.aspectRatio === "string" && body.aspectRatio.trim()
|
||||
? body.aspectRatio.trim()
|
||||
: "1:1",
|
||||
: "auto",
|
||||
imageSize:
|
||||
typeof body.imageSize === "string" && body.imageSize.trim()
|
||||
? body.imageSize.trim()
|
||||
|
||||
@ -150,7 +150,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
// 生成配置
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [negativePrompt, setNegativePrompt] = useState("");
|
||||
const [aspectRatio, setAspectRatio] = useState("1:1");
|
||||
const [aspectRatio, setAspectRatio] = useState("auto");
|
||||
const [imageCount, setImageCount] = useState(1);
|
||||
const previousNodeIdsRef = useRef<Set<string>>(new Set());
|
||||
const selectedAgentPresetId = searchParams.get("agentPresetId");
|
||||
@ -505,9 +505,6 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
|
||||
setGenerating(true);
|
||||
|
||||
// 获取尺寸预设
|
||||
const sizePreset = SIZE_PRESETS.find(s => s.value === aspectRatio) || SIZE_PRESETS[0];
|
||||
|
||||
// 先创建占位节点(显示生成中状态)
|
||||
const placeholderNodeIds: string[] = [];
|
||||
for (let i = 0; i < imageCount; i++) {
|
||||
|
||||
@ -503,12 +503,16 @@ export function createAlibabaImage({ apiKey, baseURL }: AlibabaImageConfig) {
|
||||
// 这里改为根据参考图比例计算 size,确保 1K/2K/4K 档位真正生效。
|
||||
const referenceImageUrl = imageUrls[imageUrls.length - 1];
|
||||
const inferredAspectRatio = await inferAspectRatioFromImageUrl(referenceImageUrl);
|
||||
params.size = inferredAspectRatio
|
||||
? calculateAlibabaSizeByAspect(inferredAspectRatio, baseSize)
|
||||
: `${baseSize}*${baseSize}`;
|
||||
console.log(
|
||||
`[Alibaba Image] Auto mode resolved size: imageSize=${imageSize}, inferredAspect=${inferredAspectRatio || "fallback-square"} => size=${params.size}`
|
||||
);
|
||||
if (inferredAspectRatio) {
|
||||
params.size = calculateAlibabaSizeByAspect(inferredAspectRatio, baseSize);
|
||||
console.log(
|
||||
`[Alibaba Image] Auto mode resolved size: imageSize=${imageSize}, inferredAspect=${inferredAspectRatio} => size=${params.size}`
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
`[Alibaba Image] Auto mode keeps provider default size: imageSize=${imageSize}, inferredAspect=unavailable`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const calculatedSize = calculateSize(aspectRatio, baseSize);
|
||||
if (calculatedSize) {
|
||||
|
||||
@ -85,7 +85,7 @@ export async function generateCanvasImage(
|
||||
const aspectRatio =
|
||||
typeof request.aspectRatio === "string" && request.aspectRatio.trim()
|
||||
? request.aspectRatio.trim()
|
||||
: "1:1";
|
||||
: "auto";
|
||||
const imageSize =
|
||||
typeof request.imageSize === "string" && request.imageSize.trim()
|
||||
? request.imageSize.trim()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user