1 parent
1fe3ce367f
commit
2bf047b8ad
2 files changed
+40
-1
No files matched your search
@@ -2267,9 +2267,28 @@ func normalizeImageQuality(value string) string {
|
|||||||
|
|
||||||
func normalizePixelSize(value string) string {
|
func normalizePixelSize(value string) string {
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
if value == "" || value == "auto" || strings.Contains(value, ":") {
|
if value == "" || value == "auto" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
// 画布按比例保存常用预设;图片接口只接受像素尺寸,必须在请求边界完成转换。
|
||||||
|
switch value {
|
||||||
|
case "1:1":
|
||||||
|
return "1024x1024"
|
||||||
|
case "3:2":
|
||||||
|
return "1536x1024"
|
||||||
|
case "2:3":
|
||||||
|
return "1024x1536"
|
||||||
|
case "4:3":
|
||||||
|
return "1360x1024"
|
||||||
|
case "3:4":
|
||||||
|
return "1024x1360"
|
||||||
|
case "16:9":
|
||||||
|
return "1824x1024"
|
||||||
|
case "9:16":
|
||||||
|
return "1024x1824"
|
||||||
|
case "21:9":
|
||||||
|
return "2352x1008"
|
||||||
|
}
|
||||||
if strings.Contains(value, "x") {
|
if strings.Contains(value, "x") {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,26 @@ func TestVolcengineArkImageRejectsMaskBeforeRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNormalizePixelSizeConvertsCanvasAspectRatios(t *testing.T) {
|
||||||
|
tests := map[string]string{
|
||||||
|
"1:1": "1024x1024",
|
||||||
|
"3:2": "1536x1024",
|
||||||
|
"2:3": "1024x1536",
|
||||||
|
"4:3": "1360x1024",
|
||||||
|
"3:4": "1024x1360",
|
||||||
|
"16:9": "1824x1024",
|
||||||
|
"9:16": "1024x1824",
|
||||||
|
"21:9": "2352x1008",
|
||||||
|
}
|
||||||
|
for input, want := range tests {
|
||||||
|
t.Run(input, func(t *testing.T) {
|
||||||
|
if got := normalizePixelSize(input); got != want {
|
||||||
|
t.Fatalf("normalizePixelSize(%q) = %q, want %q", input, got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDoBinaryRejectsOversizedProviderResponse(t *testing.T) {
|
func TestDoBinaryRejectsOversizedProviderResponse(t *testing.T) {
|
||||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
|||||||
Reference in new issue
Block a user