views:

83

answers:

3

Hi, This is an assignment, i have put good effort since i am new to python programming:

I am running the following function which takes in image and phrase (spaces will be removed so just text) as arguments, i have already been given all the import and preprocessing code, i just need to implement this function. I can only use getpixel, putpixel, load, and save. That is why coding this has been a hard task for me.

def InsertoImage(srcImage, phrase):  
    pix = srcImage.load()  
    for index,value in enumerate(phrase):  
        pix[10+index,15] = phrase[index]  
    srcImage.save()  
pass  

This code is giving "system error" which says that "new style getargs format but argument is not tuple"

Edit:

C:\Users\Nave\Desktop\a1>a1_template.py lolmini.jpg Hi  
Traceback (most recent call last):  
  File "C:\Users\Nave\Desktop\a1\a1_template.py", line 31, in <module>  
    doLOLImage(srcImage, phrase)  
  File "C:\Users\Nave\Desktop\a1\a1_template.py", line 23, in doLOLImage  
    pix[10+index,15] = phrase[index]  
SystemError: new style getargs format but argument is not a tuple  

Edit:

Ok Thanks, i understood and now posting code but i am getting error for the if statement not sure why the if statement is not working, here is full code sorry for not adding it entirely before:

from future import division

letters, numbers, and punctation are dictionaries mapping (uppercase)

characters to Images representing that character

NOTE: There is no space character stored!

from imageproc import letters, numbers, punctuation, preProcess

This is the function to implement

def InserttoImage(srcImage, phrase):
pix = srcImage.load()
for index,value in enumerate(phrase):
if value in letters:
pix[10+index, 15] = letters[value]
elif value in numbers:
pix[10+index, 15] = numbers[value]
elif value in punctuation: pix[10+index, 15] = punctuation[value]
srcImage.save()
pass

This code is performed when this script is called from the command line via:

'python .py'

if name == 'main':
srcImage, phrase = preProcess()
InserttoImage(srcImage, phrase)

Thanks, letter, numbers, and punctuation are dictionaries which see the key element and open the image (font). But still there is an issue with pix[10+index, 15] as it is giving error:

pix[10+index, 15]  = letters[value]  

SystemError: new style getargs format but argument is not a tuple

A: 

Actually, upon further reading, I think the problem is that you are trying to assign a character value to a pixel. You have to figure out some kind of way to actually draw the characters on the image (and within the images boundaries).

Also as a side note since you are using for index,value in enumerate(phrase):

You could use value instead of phrase[index]

GWW
Thanks i tried with both:If i use pix[(10+index,15)] i am getting this error: File "C:\Users\Nave\Desktop\a1\a1_template.py", line 23, in doLOLImage pix[(10+index,15)] = phrase[index] SystemError: new style getargs format but argument is not a tuple If i use pix[10+index][15]i am getting this error: File "C:\Users\Nave\Desktop\a1\a1_template.py", line 23, in doLOLImage pix[10+index][15] = phrase[index] TypeError: argument must be sequence of length 2
nman84
Yeah I apologize, I wasn't really thinking when I said that.I edited my response with what the problem is. I hope it helps a bit, I'm trying to be intentionally vague since it's homework :)
GWW
Can you please suggest me how to draw the characters on the image, assignment only allows me use to getpixel, putpixel, load and save from the image functions in python image lib.
nman84
+1  A: 
Andrew
A: 

My suggestion to the general problem is to create an image that contains all of the characters, at known coordinates (top, bottom, left, right) and then transfer the appropriate parts of the character image into the new output image.

rwong