Issue
I create the object using the following code:
if size == 'L':
W, H = (240,60)
elif size == 'M':
W, H = (160,60)
elif size == 'S':
W, H, = (80,60)
myFont = ImageFont.truetype("arial.ttf", 16)
cabinet = Image.new("RGBA",(W,H),"yellow")
draw = ImageDraw.Draw(cabinet)
w, h = draw.textsize(name, font=myFont)
draw.text(((W-w)/2,(H-h)/2), name, fill="black", font=myFont)
cabinet.save('image.png','PNG')
I get the following image:
Then when I paste this image onto another image using the following code:
map = Image.open('PATH/TO/IMAGE.png')
back_im = map.copy()
back_im.paste(cabinet, (x, y))
draw = ImageDraw.Draw(back_im)
back_im.save('PATH/TO/NEW.png', quality=100)
I get this image:
I am wondering how to eliminate this issue of losing my color upon pasting and saving.
Solution
Try to do this:
imgNew = Image.new('RGB', (x,y), <>)
maps = Image.open('PATH/TO/IMAGE.png').convert("RGB")
imgNew.paste(maps, (x, y))
Answered By - Xitiz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.