Created
April 26, 2012 13:47
-
-
Save kyl191/2499730 to your computer and use it in GitHub Desktop.
Image Blender
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
# Swap red & blue channels for extra interestingness | |
from PIL import Image | |
import os, math, sys, random | |
os.chdir(sys.argv[1]) | |
fileList = os.listdir(".") | |
random.shuffle(fileList) | |
(width, height) = Image.open(fileList[0]).size | |
nPhotos = len(fileList) | |
offset = width/float(nPhotos) | |
dst = Image.new("RGB", (width, height)) | |
for index, file in enumerate(fileList): | |
src = Image.open(file) | |
b, g, r = src.split() | |
src = Image.merge("RGB", (r, g, b)) | |
box = (int(math.floor(offset*index)), 0, int(math.ceil(offset*(index+1))), height) | |
print "Cropping " + file + " coords: " | |
print box | |
dst.paste(src.crop(box), box) | |
dst.save("testbgr.jpg", "JPEG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment