It is currently Sun Aug 09, 2026 8:47 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: gimp cards or any cards really plug-in
PostPosted: Wed Nov 06, 2024 5:12 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
This spawned from this topic about pattern emerges across many clients
I shouldn't be sharing this if I want more client work but I think it's basic enough and shared across many clients who have similar needs
that I want to share so if they can use it without my involvement then great, if it's more complex with more details then they come for my gig.
www.youtube.com Video from : www.youtube.com

#!/usr/bin/env python

from gimpfu import *
import re
import os
def readcsv(csvfile):
    """
    Lists all presets saved in the preset file.
    Returns a dictionary with preset names as keys and their properties as values.
    """
    values = []
   
    with open(csvfile, 'r') as file:
        lines = file.readlines()
        for line in lines:
            # Remove any leading/trailing whitespace
            line = line.strip()
            if line:
                # Split the line into components
                #parts = line.split(',')
                parts = line
                if len(parts) > 0:
                    # filename,righttext,middletext,lefttext = parts
                    noun = parts
                    values.append ({
                        'noun':noun
                        # 'filename':filename,
                        # 'righttext':righttext,
                        # 'middletext': middletext,
                        # 'lefttext': lefttext,
                    })
    return values
def gimpcard(xcffile,csvfile,outputdir):
    dummy = 0
    #loads xcf
    image = pdb.gimp_xcf_load(dummy,xcffile,xcffile)
    pdb.gimp_display_new(image)

    for layer in image.layers:
        if pdb.gimp_item_is_text_layer(layer) == TRUE:
            textlayer = layer
            break

    values = readcsv(csvfile)
    filename = os.path.splitext(os.path.basename(xcffile))[0]
    for i in range(1,len(values)): #skip first row since it's just header saying "noun"
        current_noun = values[i]['noun']
        pdb.gimp_text_layer_set_text(textlayer,current_noun);
        export_layer = pdb.gimp_layer_new_from_visible(image,image,"export png")
        pngfilename = filename+current_noun+".png"
        pngexport = os.path.join(outputdir,pngfilename)
        pdb.file_png_save_defaults(image,export_layer,pngexport,pngexport)

register(
    "python_fu_tt_gimpcard",
    "Populates Text from csv",
    "Populates Text from csv",
    "author name",
    "copyright name",
    "2024.11.05",
    "GIMP Cards",
    "",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    (PF_FILE, "xcffile", ".xcf template file:", 0),
    (PF_FILE, "csvfile", ".csv file:", 0),
    # (PF_FONT, "leftrightfont", "Left Right Font:", 'Sans-serif'),
    # (PF_INT, "lefrightsize", "Left and Right Font Size:", 62),
    # (PF_FONT, "middlefont", "Middle Font:", 'Sans-serif Bold'),
    # (PF_INT, "middlesize", "Middle Font Size:", 249),
    # (PF_COLOR, "fontcolor", "Font Color:", (0, 0, 0)),
    (PF_DIRNAME, "outputdir", "Output Directory:", 0),
    #INPUT ENDS
    ],
    [],
    gimpcard,
    menu="<Image>/Python-Fu")
main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste (found online years back that I didn't want to constantly look up)
# Since GIMP is free anyways, I thought it would be handy here for me to CUT and PASTE, CHANGE, USE.
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.


Attachments:
File comment: gimpcard.py and example files
gimpcard-and-files.zip [449.59 KiB]
Downloaded 55 times

_________________
TinT
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: gimp cards or any cards really plug-in
PostPosted: Wed Nov 06, 2024 5:39 pm  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
If more clients can use existing plug-in publicly shared then GIMP's professional use base will grow quicker.
Hopefully that creates more opportunities for more advanced plug-in automation or GIMP automation in general.

_________________
TinT


Top
 Post subject: Re: gimp cards or any cards really plug-in
PostPosted: Thu Nov 07, 2024 3:15 am  (#3) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16153
Thx Tran! :)

_________________
Image


Top
 Post subject: Re: gimp cards or any cards really plug-in
PostPosted: Thu Nov 07, 2024 6:58 am  (#4) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
you're welcome

_________________
TinT


Top
 Post subject: Re: gimp cards or any cards really plug-in
PostPosted: Thu Nov 07, 2024 9:13 pm  (#5) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
waiting to hear about add_path_argument to convert this plug-in to GIMP 3.0

_________________
TinT


Top
 Post subject: Re: gimp cards or any cards really plug-in
PostPosted: Fri Nov 08, 2024 1:55 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 859
Location: SEA - South East Asia
Wow... Changing the hundreds names on an invitation card template, or student names on hundreds of certificates, will become easy,
thanks a lot Tran :tyspin

_________________
Patrice


Top
 Post subject: Re: gimp cards or any cards really plug-in
PostPosted: Fri Nov 08, 2024 11:32 am  (#7) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
PixLab wrote:
Wow... Changing the hundreds names on an invitation card template, or student names on hundreds of certificates, will become easy,
thanks a lot Tran :tyspin

Didn't even think of that user-case, I just got request for like playing cards but yeah invitation cards would be good too
for certicates, you could even alter script to read multiple values one line so that it could do student name and major or other values at the same time so long as the values are on the same line....we could do a bunch of different attributes.

_________________
TinT


Top
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group