Skip to content

Instantly share code, notes, and snippets.

@Steffo99
Created January 8, 2016 20:20
Show Gist options
  • Save Steffo99/df6897c448ed3059c886 to your computer and use it in GitHub Desktop.
Save Steffo99/df6897c448ed3059c886 to your computer and use it in GitHub Desktop.
from PIL import Image
from PIL import ImageFilter
import os
filelist = list()
for root, dirs, files in os.walk("backgrounds"):
filelist = files
print(filelist)
for filename in filelist:
background = Image.open("backgrounds/" + filename)
print("Sfondo importato: " + filename)
foreground = Image.open("foregrounds/" + filename)
print("Logo importato: " + filename)
im = background.resize((460, 215))
print("Sfondo ridimensionato!")
im = im.filter(ImageFilter.GaussianBlur(radius=35))
print("Sfondo sfocato!")
x, y = foreground.size
logo = foreground.resize((int(215 * x / y), 215), Image.BICUBIC)
print("Logo ridimensionato a: " + repr(logo.size))
x, y = logo.size
logo = logo.crop((0, 0, 460, 215))
print("Logo tagliato a: " + repr(logo.size))
try:
im.paste(logo, (int((460 - x) / 2), 0), logo)
except ValueError:
print("ERRORE nella trasparenza del logo!")
else:
print("Logo incollato!")
im.save("output/" + filename)
print("Salvata come: " + filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment