Python Forum

Full Version: merge drawings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm writing a program that makes a png file by combining two other png files.

It's joining them together but not quite the way I want it to. It joins drawing 'A' (which is a transperancy) and places it on drawing 'B'. The end result is drawing 'C' which is not what I want. I want it to look like drawing 'D'. Cry

http://content.screencast.com/users/dchr...70/bug.png

Which drawings to merge together are specified on bres config bargraph.csv lines 5 and 16. The x and y coordinates of where to place image A onto image B is specified on lines 18 and 19

The filename of what to call this new drawing is specified on line 6


Bres data.csv is for future use. Ignore it





My code

import csv
import sys

from PIL import Image, ImageDraw, ImageFont # COMMNAD FOR INSTALL PIL sudo apt-get install python-dev libjpeg-dev libfreetype6-dev zlib1g-dev
# $ sudo pip install pil

data =
#read data file.
dataf = None
configf = None

try:
dataf = open('bres data.csv', 'rt')
configf = open('bres config bargraph.csv', 'rt')

data = [d for d in csv.reader(dataf)]
all_config = [c for c in csv.reader(configf)]

image = Image.open(all_config[5][0])
width, height = image.size


image.paste(Image.open(all_config[16][0]), (int(all_config[18][0]),int(all_config[19][0])))



image.save(all_config[6][0])
print "%s file ready"%all_config[6][0]

except Exception, e:
print "Error Encountered: ",e
finally:
if dataf:
dataf.close()
if configf:
configf.close()
You should use pillow instead as that is the new pil.

I usually dont post links to SO but it would depend on a few factors. And this thread already contains each solution depending on which of your images has an alpha channel, and im on a tablet now...
https://stackoverflow.com/questions/5324...-using-pil
I have temporarily changed this line. It still does the same thing only it is easier to follow

image.paste(Image.open('bres sc4.png'), (int(300),int(400)))
i think that I have to change this to:

image.paste(Image.open('bres sc4.png'), (int(300),int(400), mask='bres sc4.png')))

Is this correct? I tried it and get an error

BTW I'm not ignoring this request, I just don't know how

Please, use proper tags when post code, traceback, output, etc.

Sorry what I meant to say is, Am I on the right track? Will you help me with this line?
This program makes a drawing by merging two drawings together but not quite the way I want it to. It joins drawing 'A' (which is a transparency) and places it on drawing 'B'. The end result is drawing 'C' which is not what I want. I want it to look like drawing 'D'.

http://content.screencast.com/users/dchr...70/bug.png

This is my line of code


image.paste(Image.open('bres sc4.png'), (int(300),int(400)))
I searched the web and think that I found the problem. I need to specify the 3rd parameter. However, I don't know how.

I think it needs to be something like this but this gives me an error


image.paste(Image.open('bres sc4.png'), (int(300),int(400)), mask='bres sc4.png'))