Merge changes from prometheus/mebox-40a7378b

This commit is contained in:
truewhile
2026-11-12 22:38:54 +08:00
parent 5806839601
commit 08d521b65d
8 changed files with 118 additions and 14 deletions
+23 -3
View File
@@ -73,17 +73,17 @@ func CropAdultCoverPosterForCode(data []byte, code string) ([]byte, string, erro
}
src, format, err := image.Decode(bytes.NewReader(data))
if err != nil {
return data, format, err
return data, imageMIMEForFormat(format), err
}
bounds := src.Bounds()
width := bounds.Dx()
height := bounds.Dy()
if width <= 0 || height <= 0 {
return data, format, nil
return data, imageMIMEForFormat(format), nil
}
// If the image is already portrait or square, keep it as-is.
if float64(width) <= float64(height)*1.15 {
return data, format, nil
return data, imageMIMEForFormat(format), nil
}
position := 1.0
@@ -101,6 +101,26 @@ func CropAdultCoverPosterForCode(data []byte, code string) ([]byte, string, erro
return buf.Bytes(), "image/jpeg", nil
}
// imageMIMEForFormat maps the format name returned by image.Decode ("jpeg" / "png" / "webp" …) to a MIME
// type. The sidecar extension is derived from the MIME type, so handing back the bare format name made
// every already-portrait poster fall through to the legacy ".img" extension.
func imageMIMEForFormat(format string) string {
switch strings.ToLower(strings.TrimSpace(format)) {
case "jpeg", "jpg":
return "image/jpeg"
case "png":
return "image/png"
case "webp":
return "image/webp"
case "gif":
return "image/gif"
case "avif":
return "image/avif"
default:
return ""
}
}
// adultCoverNeedsFaceDetection reports whether the cover composition has to be probed with the face
// detector, mirroring upstream MetaTube: only "special" numbers (FC2 / HEYZO / 素人 / 无码) qualify,
// regular DVD numbers are always cropped at the right-most panel.