Chaitanya
Chaitanya

Reputation: 132

Python PIL image transparent issue

I am trying to make an image transparent. This is my imageLook at the image

from PIL import Image
   img = Image.open('Frame 0001.png')
img = img.convert("RGBA")
datas = img.getdata()

newData = []
for item in datas:
    if item[0] == 255 and item[1] == 255 and item[2] == 255:
        newData.append((255, 255, 255, 0))
    else:
        newData.append(item)

img.putdata(newData)
img.save("img2.png", "PNG")

My output image is this:
Output image

Upvotes: 0

Views: 540

Answers (1)

Chaitanya
Chaitanya

Reputation: 132

Well Googled a bit and found a package called cv2. Had a tough time installing that package, but the thing I was trying to do was possible

import cv2
img1=cv2.imread('m1.jpg')
img2=cv2.imread('logo.jpg')

dst=cv2.addWeighted(img1,0.7,img2,0.3,0)
cv2.imshow('dst',dst)

cv2.waitKey(0)
cv2.destroyAllWindows()

Upvotes: 1

Related Questions