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