64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
import svgwrite
|
|
from svgwrite import cm, mm, px
|
|
|
|
# Configuration des chemins vers les icônes
|
|
icons = {
|
|
'degats': 'path/to/damage_icon.svg',
|
|
'or': 'path/to/gold_icon.svg',
|
|
'soin': 'path/to/heal_icon.svg'
|
|
}
|
|
|
|
# Configuration des couleurs de fond
|
|
background_colors = {
|
|
'bleue': 'lightblue',
|
|
'rouge': 'lightcoral',
|
|
'jaune': 'lightyellow',
|
|
'verte': 'lightgreen',
|
|
'sans': 'white'
|
|
}
|
|
|
|
def generate_card_svg(name, description, color, effects, output_path):
|
|
# Créer un dessin SVG
|
|
dwg = svgwrite.Drawing(output_path, profile='tiny', size=(8*cm, 12*cm))
|
|
|
|
# Ajouter un rectangle de fond
|
|
dwg.add(dwg.rect(insert=(0, 0), size=('100%', '100%'), fill=background_colors[color]))
|
|
|
|
# Ajouter le titre de la carte
|
|
dwg.add(dwg.text(name, insert=(0.5*cm, 1*cm), font_size="20px", fill='black'))
|
|
|
|
# Ajouter la description
|
|
dwg.add(dwg.text(description, insert=(0.5*cm, 2*cm), font_size="12px", fill='black'))
|
|
|
|
# Ajouter les effets
|
|
y_offset = 3*cm
|
|
for effect in effects:
|
|
if effect['type'] in icons:
|
|
# Ajouter l'icône
|
|
dwg.add(dwg.image(href=icons[effect['type']], insert=(0.5*cm, y_offset), size=(1*cm, 1*cm)))
|
|
# Ajouter le texte de l'effet
|
|
dwg.add(dwg.text(effect['text'], insert=(2*cm, y_offset + 0.75*cm), font_size="15px", fill='black'))
|
|
else:
|
|
# Ajouter le texte de l'effet sans icône
|
|
dwg.add(dwg.text(effect['text'], insert=(0.5*cm, y_offset + 0.75*cm), font_size="15px", fill='black'))
|
|
y_offset += 2*cm
|
|
|
|
# Sauvegarder le fichier SVG
|
|
dwg.save()
|
|
|
|
# Exemple d'utilisation
|
|
card_info = {
|
|
'name': 'Niko Incendiaire',
|
|
'description': 'Action, ghdj;spftgljh.-',
|
|
'color': 'bleue',
|
|
'effects': [
|
|
{'type': 'degats', 'text': '8 Dégâts'},
|
|
{'type': 'or', 'text': '5 Or'}
|
|
]
|
|
}
|
|
|
|
output_path = 'niko_incendiaire.svg'
|
|
generate_card_svg(**card_info, output_path=output_path)
|
|
|
|
print('Carte SVG générée avec succès!')
|