![]() |
merge drawings - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: merge drawings (/thread-5585.html) |
merge drawings - chris64 - Oct-12-2017 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'. ![]() http://content.screencast.com/users/dchristensen777/folders/1%20temp/media/70e0b1be-5364-4fc7-a851-0a46976a1d70/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() RE: merge drawings - metulburr - Oct-12-2017 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/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil RE: merge drawings - chris64 - Oct-13-2017 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? RE: merge drawings - chris64 - Oct-14-2017 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')) |