Paste an Image Into a Predefined Area with Python Pillow

from PIL import Image

image = Image.open("image.png")
canvas_image = Image.open("canvas.png")
image.png — Random Bitcoin logo I found on my PC
canvas.png — Yeah it’s just a plain background. What did you expect?
image_position = (269, 233, 467, 431)
image = image.resize(
(
crypto_logo_position[2] - crypto_logo_position[0],
crypto_logo_position[3] - crypto_logo_position[1],
)
)
canvas.paste(image, image_position, image)
canvas.save("output.png")

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Quoorex

Quoorex

Developer and full-time learner. Aspiring entrepreneur.