Turnrp
Turnrp

Reputation: 17

Blend an image into another with Python

I am trying to blend an image into another with python to set as your wallpaper for every frame of the fading animation.

I've look on several fourms and haven't found anyone trying to do the same thing and I have never messed with photo editing in python just game stuff and what im doing is completely different.

Upvotes: 0

Views: 162

Answers (1)

Hermann12
Hermann12

Reputation: 3581

I have two png pictures a smily and a green triangle. Than you can do e.g. with openCV something like:

import cv2
import numpy as np 

image1 = cv2.imread('Face1.png') 
image2 = cv2.imread('Nose1.png')

print(f"Size image 1 and image 2 is {image1.shape} and {image2.shape}")
image2_resized = cv2.resize(image2, (image1.shape[1],image1.shape[0])) 
print(f"After reshape image 1 and image 2 (after resizing) is {image1.shape} and {image2_resized.shape}")

blended_image = cv2.addWeighted(src1=image1,alpha=0.5,src2=image2_resized,beta=0.5,gamma=0)

#cv2.imshow('Im1',image2) 
#cv2.imshow('Im2',image2)
cv2.imshow('Blended',blended_image) 

cv2.waitKey(0)

Output:

enter image description here

Upvotes: 0

Related Questions