Hello and thanks for any assistance, I wrote this basic script to batch make test forms for a side project. In its current state it works fine and I can pass file names to it no problem. It will take the form embeded in the code and create 10 additional copies with the data in the lists (iamges,ssns...). However I'm stuck on how to pass the coordinates fo the queue types (R.Q1,Q2,Q3) to the draw.text statements.

I thought this might work but it doesn't:

qtype = raw_input("Enter queue type; R,Q1,Q2,Q3,IP,IBH:")

draw.text((qtype), prioritymark, font=fnt)
#!/usr/bin/python
import Image, ImageDraw, ImageFont, glob, re
from os import chdir, path

fname = raw_input("desired file name?")
print "I will now create 10 files starting with the name:", fname

images = [fname + '_01.jpeg', fname + '_02.jpeg', fname + '_03.jpeg', fname + '_04.jpeg', fname + '_05.jpeg', fname + '_06.jpeg', fname + '_07.jpeg', fname + '_08.jpeg', fname + '_09.jpeg', fname + '_10.jpeg']
ssns = ['111-22-3000', '111-22-3001', '111-22-3002', '111-22-3003', '111-22-3004', '111-22-3005', '111-22-3006', '111-22-3007', '111-22-3008', '111-22-3009']
bnames = ['Alfalfa', 'Darla', 'Porky', 'Buckwheat', 'Butch', 'Stymie', 'Norman', 'Pete', 'Wheezer', 'Scotty']
prioritymark = "X"
corres = "X"
address = "2019 Aerojet Rd, Rancho Cordova, CA"
R = "446,1013"
Q1 = "446,1274"
Q2 = "446,1654"
Q3 = "446,1654"
IP = "446,2195"
IBH = "446,2349"

def txt2img(text,fg="#000000",font="Verdana.TTF",FontSize=84):
    font_dir = "/home/chris/.PlayOnLinux/fonts/"
    font_size = FontSize
    fnt = ImageFont.truetype(font_dir+font, font_size)
    lineWidth = 20
    img = Image.open("civform.jpeg")
    draw = ImageDraw.Draw(img)
    draw.text((1108,2763), text, font=fnt)      # add some text to the main
    draw.text((2231,15), images[index], font=fnt)
    draw.text((2435,590), prioritymark, font=fnt)
    ###draw.text((3408,590), prioritymark, font=fnt)
    draw.text((1524,2886), bnames[index], font=fnt)
    draw.text((3071,1780), corres, font=fnt)
    draw.text((1067,2995), address, font=fnt)
    del draw 
    img.save(images[index],"JPEG",quality=55)
    
for index in range(len(ssns)):
	txt2img(ssns[index])
	
print "done"

Recommended Answers

All 3 Replies

Change those variables to dict current variable names. Other way is to change the raw_input to input in your change code, but that is unsafe as it allows arbitrary expressions. The values should also be coordinate tuples, not strings.

Thank you, would you be able to provide and example? I'm still a little confused. I tried an alternate method of just creating a new block of code, but wondering if there is a better way to do that?

The info in the code below is fake and made up. Its just random data to use when making the test forms.

#!/usr/bin/python
import Image, ImageDraw, ImageFont, glob, re
from os import chdir, path
civrr = "CIVRR"
civur = "CIVUR"

routCimg = (civrr + '_01.jpeg', civrr + '_02.jpeg', civrr + '_03.jpeg', civrr + '_04.jpeg', civrr + '_05.jpeg', civrr + '_06.jpeg', civrr + '_07.jpeg', civrr + '_08.jpeg', civrr + '_09.jpeg', civrr + '_10.jpeg')
urgCimg = (civur + '_01.jpeg', civur + '_02.jpeg', civur + '_03.jpeg', civur + '_04.jpeg', civur + '_05.jpeg', civur + '_06.jpeg', civur + '_07.jpeg', civur + '_08.jpeg', civur + '_09.jpeg', civur + '_10.jpeg')
ssns = ('111-22-3000', '111-22-3001', '111-22-3002', '111-22-3003', '111-22-3004', '111-22-3005', '111-22-3006', '111-22-3007', '111-22-3008', '111-22-3009')
bnames = ('Alfalfa', 'Darla', 'Porky', 'Buckwheat', 'Butch', 'Stymie', 'Norman', 'Pete', 'Wheezer', 'Scotty')
blnames = ('Smith','Johnson','Williams','Jones','Brown','Davis','Miller','Wilson','Moore','Taylor')
dx = ('obstructive sleep apnea','menorrhagia','cervicalgia','tonsillitis','lumbago','knee pain','otolagia','poor vision','pregnancy','headache')
dob = ('12-29-83','7-16-84','12-12-2009','8-8-1997','6-6-1966','7-7-1971','3-3-1923','7-8-1999','9-9-1999','10-10-2010')
zcode = "95628"
prioritymark = "X"
corres = "X"
address = "address"
contact = "name"
num = "555-555-5555"
lic = "898-62-8888"
rprov = "... Family Practice"
specialty = ('Pulmonary Medicine','Gynecology','Radiology','ENT','Pain Management','Orthopedics','ENT','Opthalmology','Obstetrics','Neurologist')
#Referral 446,845
#Q1 446,{1013,1145}
#Q2 446,{1274,1400,1524}
#Q3 446,{1654,1780,1905,2029}
#IP 446,2195
#IBH 446,{2349,2496}
qtype = {"referral":"446,845",\
	"Q1":"446,1274"}
routine = [(2435,590),(3408,590)]
urgent = "3408,590"

def routine(text,fg="#000000",font="Verdana.TTF",FontSize=84):
    font_dir = "/home/chris/.PlayOnLinux/fonts/"
    font_size = FontSize
    fnt = ImageFont.truetype(font_dir+font, font_size)
    lineWidth = 20
    img = Image.open("civform.jpeg")
    draw = ImageDraw.Draw(img)
    draw.text((1108,2763), text, font=fnt)      # add some text to the main
    draw.text((2231,15), routCimg[index], font=fnt) #adds name of file to top of request
    draw.text((446,850), prioritymark, font=fnt) #checks referral queue type
    draw.text((2435,590), prioritymark, font=fnt) #Urgent
    draw.text((2015,2886), bnames[index], font=fnt) #first names
    draw.text((1524,2886), blnames[index], font=fnt) #last names
    draw.text((3071,1780), corres, font=fnt) #corresp preference
    draw.text((1067,2995), address, font=fnt) #addresses
    draw.text((2946,4421), dx[index], font=fnt) #dx's
    draw.text((2543,1126), contact, font=fnt) #contact name
    draw.text((3440,880), num, font=fnt) #phone/fax
    draw.text((3440,1015), num, font=fnt) #phone/fax
    draw.text((1283,3240), num, font=fnt) #phone/fax
    draw.text((3901,2023), prioritymark, font=fnt) #requesting is performing
    draw.text((3921,2893), dob[index], font=fnt)
    draw.text((4300,3025), zcode, font=fnt)
    draw.text((2610,1646), lic, font=fnt)
    draw.text((3253,1261), rprov, font=fnt)
    draw.text((835,3529), specialty[index], font=fnt)
    
    del draw 
    img.save(routCimg[index],"jpeg",quality=35)
    
for index in range(len(ssns)):
	routine(ssns[index])
	
def urgent(text,fg="#000000",font="Verdana.TTF",FontSize=84):
    font_dir = "/home/chris/.PlayOnLinux/fonts/"
    font_size = FontSize
    fnt = ImageFont.truetype(font_dir+font, font_size)
    lineWidth = 20
    img = Image.open("civform.jpeg")
    draw = ImageDraw.Draw(img)
    draw.text((1108,2763), text, font=fnt)      # add some text to the main
    draw.text((2231,15), urgCimg[index], font=fnt) #adds name of file to top of request
    draw.text((446,850), prioritymark, font=fnt) #checks referral queue type
    draw.text((3408,590), prioritymark, font=fnt) #Routine
    draw.text((2015,2886), bnames[index], font=fnt) #first names
    draw.text((1524,2886), blnames[index], font=fnt) #last names
    draw.text((3071,1780), corres, font=fnt) #corresp preference
    draw.text((1067,2995), address, font=fnt) #addresses
    draw.text((2946,4421), dx[index], font=fnt) #dx's
    draw.text((2543,1126), contact, font=fnt) #contact name
    draw.text((3440,880), num, font=fnt) #phone/fax
    draw.text((3440,1015), num, font=fnt) #phone/fax
    draw.text((1283,3240), num, font=fnt) #phone/fax
    draw.text((3901,2023), prioritymark, font=fnt) #requesting is performing
    draw.text((3921,2893), dob[index], font=fnt)
    draw.text((4300,3025), zcode, font=fnt)
    draw.text((2610,1646), lic, font=fnt)
    draw.text((3253,1261), rprov, font=fnt)
    draw.text((835,3529), specialty[index], font=fnt)
    
    del draw 
    img.save(urgCimg[index],"jpeg",quality=35)
    
for index in range(len(ssns)):
	urgent(ssns[index])
	
print "done"

tuple not string
not

qtype = {"referral":"446,845",\
	"Q1":"446,1274"}
routine = [(2435,590),(3408,590)]
urgent = "3408,590"

but

qtype = {"referral":(446,845), ## no continuation needed inside parenthesis
	"Q1":(446,1274)}
routine = [(2435,590),(3408,590)]
urgent = (3408,590)

Why are you duplicating your code? why don't use parameters? Instead you have fg parameter which you are not using.

It is not good style to put loops between definitions without good reason.

Do function to just make the mark to given picture, put parameter urgent=False in the drawing function and call the marking routine:

if urgent: img = urgent_mark(img)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.