For the last few days, I’been trying to make a dungeons and dragons spellcard making program.
What I’m trying to do is:
- make a card template in GIMP containing all my layers (graphical and text layers)
- take a .csv file with card info to fill into the text layers
- transform the .csv file into a dataframe with pandas
- iter through each row of the dataframe and edit the text layers with the corresponding data
- save each iteration as a .png file
I’m working with VSCode IDE, Python 3.12.2 and GIMP 2.10
PD: It’s my first post and I’m not totally fluent with English so I apologize for anything that might be wrong with both my writing and my post formatting!
I’ve managed to get the code apparently working but when I try to open it on GIMP (by saving the script in the plugins folder) it doesn’t even show in the Filter>Custom section. So far I’ve would say it’s something related to GIMP not working with pandas library, but have no clue in how to fix it. Any idea on how to debug it or another approach to try?
The code:
from gimpfu import *
def modify_xcf(spell_file_name, class_name):
import pandas as pd
#Carga de DF
df = pd.read_csv(spell_file_name, index_col=0)
# Abre el archivo .xcf
image = pdb.gimp_file_load('[my_path]/plantilla_gimp.xcf', '[my_path]/plantilla_gimp.xcf')
spell_list = df.index.to_list()
for spell in spell_list:
image = pdb.gimp_file_load('[my_path]/plantilla_gimp.xcf', '[my_path]/plantilla_gimp.xcf')
# Activa/desactiva capas según los datos del spell
for layer in image.layers:
match layer.name:
case "Concentration":
layer.visible = df["Concentration"][spell]
#Si tiene o no casteo a mayor nivel
case "WithHigherLevel":
layer.visible = df["Has Higher Levels"][spell]
case "WithoutHigherLevel":
layer.visible = not df["Has Higher Levels"][spell]
# Reemplaza los textos
case "Text":
for sublayer in layer:
match sublayer.name:
case "Source, Page":
pdb.gimp_text_layer_set_text(sublayer, f"{df["Source"][spell]}, p.{df["Page"][spell]}")
case "Class":
pdb.gimp_text_layer_set_text(sublayer, class_name)
case "Duration":
pdb.gimp_text_layer_set_text(sublayer, df["Duration"][spell])
case "Materials":
pdb.gimp_text_layer_set_text(sublayer, df["Materials"][spell])
case "Components":
pdb.gimp_text_layer_set_text(sublayer, df["Components"][spell])
case "Range":
pdb.gimp_text_layer_set_text(sublayer, df["Range"][spell])
case "Casting time":
pdb.gimp_text_layer_set_text(sublayer, df["Casting Time"][spell])
case "Level - School":
pdb.gimp_text_layer_set_text(sublayer, f"{df["Level"][spell]} lvl - {df["School"][spell]}")
case "Name":
pdb.gimp_text_layer_set_text(sublayer, spell)
# Guarda la imagen modificada
output_filepath = f"{class_name} Spellcards/Paladin Spellcards/{spell}.png"
output_filename = f"{spell}.png"
pdb.gimp_file_save(image, image.active_layer, output_filepath, output_filename)
def process_spells():
modify_xcf("[my_path]/PaladinSpellsCleaned.csv", "Paladin")
register(
"python_fu_process_spells",
"Procesa los hechizos desde un CSV",
"Activa capas y reemplaza textos en una plantilla .xcf según un CSV",
"Tu Nombre",
"Tu Nombre",
"2024",
"<Image>/Filters/Custom/Process Spells from CSV",
"",
[],
[],
process_spells)
main()
capymate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.