Created
January 8, 2016 20:20
-
-
Save Steffo99/df6897c448ed3059c886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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