fix: joker images stretch to fill body area equally for big/small

This commit is contained in:
Poker Design Developer
2026-06-04 22:09:08 +08:00
parent 194e42a026
commit aed831fc8c
2 changed files with 3 additions and 11 deletions

View File

@@ -331,7 +331,7 @@ def draw_joker(canvas, design, which, project, card_key, asset):
offset_y = int(body_h * image_dy)
img_copy = asset.copy()
img_copy.thumbnail((body_w, half_h), Image.LANCZOS)
img_copy = img_copy.resize((body_w, half_h), Image.LANCZOS)
if image_scale != 1:
sw = max(1, int(img_copy.width * image_scale))
sh = max(1, int(img_copy.height * image_scale))

View File

@@ -280,19 +280,11 @@ async function drawJokerBody(ctx, w, h, which, design, project) {
if (img && img.complete && img.naturalWidth) {
const halfH = bodyH / 2
const imgRatio = img.naturalWidth / img.naturalHeight
const target = bodyW / halfH
let drawW, drawH
if (imgRatio > target) {
drawW = bodyW; drawH = bodyW / imgRatio
} else {
drawH = halfH; drawW = halfH * imgRatio
}
const imageDx = Number(design.image_dx) || 0
const imageDy = Number(design.image_dy) || 0
const imageScale = Number(design.image_scale) || 1
const finalW = Math.max(1, drawW * imageScale)
const finalH = Math.max(1, drawH * imageScale)
const finalW = Math.max(1, bodyW * imageScale)
const finalH = Math.max(1, halfH * imageScale)
const offsetX = bodyW * imageDx
const offsetY = bodyH * imageDy
const topX = padX + offsetX + (bodyW - finalW) / 2