Last active
December 15, 2015 22:00
-
-
Save CnrLwlss/5330170 to your computer and use it in GitHub Desktop.
Find all images in the current directory and generate resized versions, together with a single preview file displaying all patched versions pasted together.
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
import PIL, os, math | |
from PIL import Image | |
resizeWidth=500 | |
allfiles=os.listdir(os.getcwd()) | |
filelist=[f for f in allfiles if f[-4:] in ['.jpg','.JPG','.jpeg','.JPEG','.png','.PNG']] | |
Nimages=len(filelist) | |
im0=Image.open(filelist[0]) | |
w,h=im0.size | |
neww=resizeWidth | |
newh=int(round((float(neww)/float(w))*h)) | |
bigim=Image.new("RGB",(2*neww,int(math.ceil(float(Nimages)/2.0))*newh)) | |
row,col=0,0 | |
for imname in filelist: | |
im=Image.open(imname) | |
small=im.resize((neww,newh),Image.ANTIALIAS) | |
small.save("small_"+imname[0:-4]+".png") | |
bigim.paste(small,(col*neww,row*newh,(col+1)*neww,(row+1)*newh)) | |
print row,col | |
col=col+1 | |
if col>1: | |
col=0 | |
row=row+1 | |
bigim.save("Preview.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment