This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
gtkbin = r'C:\Program Files\GTK3-Runtime Win64\bin'
|
||||||
|
add_dll_dir = getattr(os, 'add_dll_directory', None)
|
||||||
|
if callable(add_dll_dir):
|
||||||
|
add_dll_dir(gtkbin)
|
||||||
|
else:
|
||||||
|
os.environ['PATH'] = os.pathsep.join((gtkbin, os.environ['PATH']))
|
||||||
|
import cairosvg
|
||||||
|
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
folder = Path(r"C:\Users\Luka\Documents\dev\cards-gen\output\heron")
|
||||||
|
|
||||||
|
for svg_file in folder.glob("*.svg"):
|
||||||
|
print(str(svg_file))
|
||||||
|
cairosvg.svg2png(
|
||||||
|
url=str(svg_file),
|
||||||
|
scale=3,
|
||||||
|
write_to=f'output/{str(svg_file.name).replace(".svg", ".png")}'
|
||||||
|
)
|
||||||
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import base64
|
||||||
|
|
||||||
import drawsvg as dw
|
import drawsvg as dw
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@@ -25,6 +27,8 @@ for p in Path("src/data/cards-json").glob("*.json"):
|
|||||||
cards.extend(temp)
|
cards.extend(temp)
|
||||||
|
|
||||||
# Params
|
# Params
|
||||||
|
embedded_images = False
|
||||||
|
|
||||||
x_width = 298
|
x_width = 298
|
||||||
y_height = 417
|
y_height = 417
|
||||||
border_width_x = 12
|
border_width_x = 12
|
||||||
@@ -75,7 +79,13 @@ for card_data in cards:
|
|||||||
# Get card skin data
|
# Get card skin data
|
||||||
try:
|
try:
|
||||||
card_skin_data = all_skin_data["cards"][str(card_data["id"])]
|
card_skin_data = all_skin_data["cards"][str(card_data["id"])]
|
||||||
except KeyError:
|
|
||||||
|
if embedded_images:
|
||||||
|
with open(card_skin_data["image_path"].replace("../../", ""), "rb") as img:
|
||||||
|
b64 = base64.b64encode(img.read()).decode()
|
||||||
|
data_uri = f"data:image/png;base64,{b64}"
|
||||||
|
card_skin_data["image_path"] = data_uri
|
||||||
|
except KeyError as e:
|
||||||
print(
|
print(
|
||||||
"Missing skin data for card id:", card_data["id"], "using default skin data"
|
"Missing skin data for card id:", card_data["id"], "using default skin data"
|
||||||
)
|
)
|
||||||
@@ -85,9 +95,9 @@ for card_data in cards:
|
|||||||
flavor_text_type=None,
|
flavor_text_type=None,
|
||||||
)
|
)
|
||||||
# Check if card image really exists
|
# Check if card image really exists
|
||||||
if not Path(card_skin_data["image_path"].replace("../../", "")).absolute().exists():
|
# if not Path(card_skin_data["image_path"].replace("../../", "")).absolute().exists():
|
||||||
print("Missing image for card id: ", card_data["id"], " , using default image")
|
# print("Missing image for card id: ", card_data["id"], " , using default image")
|
||||||
card_skin_data["image_path"] = "../../img/missing.png"
|
# card_skin_data["image_path"] = "../../img/missing.png"
|
||||||
# Create a new SVG drawing
|
# Create a new SVG drawing
|
||||||
output_dir = "output/" + all_skin_data["skin_name"]
|
output_dir = "output/" + all_skin_data["skin_name"]
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user