@@ -1 +1,3 @@
|
|||||||
drawsvg==2.4.0
|
drawsvg==2.4.0
|
||||||
|
pillow==10.4.0
|
||||||
|
--extra-index-url=https://packagecloud.io/github/git-lfs/pypi/simple
|
||||||
@@ -8,6 +8,7 @@ from draw_functions import create_gold_icon, create_effects, draw_champion_shiel
|
|||||||
from card_types import Card, SkinData, SkinFile, Translation
|
from card_types import Card, SkinData, SkinFile, Translation
|
||||||
|
|
||||||
from drawsvg.drawing import Drawing
|
from drawsvg.drawing import Drawing
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from edit_card import finish_card
|
from edit_card import finish_card
|
||||||
|
|
||||||
@@ -212,16 +213,45 @@ for card_data in cards:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Draw image
|
# Draw image
|
||||||
d.append(dw.Rectangle(x=1, y=65, width=x_width - 2, height=200))
|
image_area_width = x_width - (2 * border_width_x)
|
||||||
d.append(
|
image_area_height = 200
|
||||||
dw.Image(
|
d.append(dw.Rectangle(x=1, y=65, width=x_width - 2, height=image_area_height))
|
||||||
x=border_width_x,
|
image = Image.open(card_skin_data['image_path'].replace('../../', ''))
|
||||||
y=65,
|
image_natural_width, image_natural_height = image.size
|
||||||
width=x_width - (border_width_x * 2),
|
image_ratio = image_natural_width / image_natural_height
|
||||||
height=200,
|
area_ratio = image_area_width / image_area_height
|
||||||
path=card_skin_data["image_path"],
|
print(image_natural_width)
|
||||||
)
|
print(image_area_width)
|
||||||
|
print(image_ratio)
|
||||||
|
print(area_ratio)
|
||||||
|
if image_ratio > area_ratio:
|
||||||
|
# Wider image
|
||||||
|
scale = image_area_height / image_natural_height
|
||||||
|
new_width = image_natural_width * scale
|
||||||
|
translate_x = (image_area_width - new_width) / 2
|
||||||
|
transform = f"translate({translate_x}, 0) scale ({scale})"
|
||||||
|
print(transform)
|
||||||
|
else:
|
||||||
|
# Taller image
|
||||||
|
scale = image_area_width / image_natural_width
|
||||||
|
new_height = image_natural_height * scale
|
||||||
|
translate_y = (image_area_height - new_height) / 2
|
||||||
|
transform = f"translate(0, {translate_y}) scale({scale})"
|
||||||
|
|
||||||
|
card_image = dw.Image(
|
||||||
|
x=border_width_x,
|
||||||
|
y=65,
|
||||||
|
width=x_width - (border_width_x * 2),
|
||||||
|
height=200,
|
||||||
|
path=card_skin_data["image_path"],
|
||||||
|
**{
|
||||||
|
"object-fit": "cover",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
card_image.args['transform'] = transform
|
||||||
|
|
||||||
|
d.append(card_image)
|
||||||
d.append(dw.Rectangle(x=2, y=65 - 1, width=border_width_x - 2, height=200 + 2))
|
d.append(dw.Rectangle(x=2, y=65 - 1, width=border_width_x - 2, height=200 + 2))
|
||||||
# d.append(dw.Rectangle(x=0, y=65+1, width=1, height=200+2, fill='white'))
|
# d.append(dw.Rectangle(x=0, y=65+1, width=1, height=200+2, fill='white'))
|
||||||
d.append(
|
d.append(
|
||||||
|
|||||||
Reference in New Issue
Block a user