I am trying to insert text to image, assignment only allows me to use load, save, getpixel, and putpixel. Details about letters, numbers, punctuation is given in Imageproc code which basically are dictionaries. But I am getting this error after running:

pix[10+index, 15] = letters[value]
SystemError: new style getargs format but argument is not a tuple


Here is the code:

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()
    pix[10,15] = letters['H']
    
    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 <name of this file>.py'
if __name__ == '__main__':
    srcImage, phrase = preProcess()
    InsertToImage(srcImage, phrase)

Here is the imageproc code no errors in this one:

import sys

import Image, ImageDraw

_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
_numbers = '1234567890'
_punctuation = {'?':'quest', '.':'dot', '!':'bang'}

# Store letters, numbers, and punctuation
letters = dict((letter, Image.open('font/%s.png' % letter))
                 for letter in _letters)
numbers = dict((num, Image.open('font/%s.png' % num))
                 for num in _numbers)
punctuation = dict((punc, Image.open('font/%s.png' % _punctuation[punc]))
                 for punc in _punctuation)

def preProcess():
    # Extract the image and the phrase, capitalizing it
    imagename =  sys.argv[1]
    srcImage = Image.open(imagename)
    phrase = ' '.join(string.upper() for string in sys.argv[2:])
    return srcImage, phrase

This will not work
pix[10,15] = letters
PIL uses
pix.paste(letters, (10,15))

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.