Skip to content

Instantly share code, notes, and snippets.

@alfianokt
Created August 28, 2019 00:29
Show Gist options
  • Save alfianokt/6ae16ebe79400775de4494b7d78b4277 to your computer and use it in GitHub Desktop.
Save alfianokt/6ae16ebe79400775de4494b7d78b4277 to your computer and use it in GitHub Desktop.
Batch minimize image
# author : alfian oktafireza | alfianokt
# desc : minimize masal gambar
import glob, os
from PIL import Image
# read all files with format .jpg
listImg = glob.glob("*.jpg")
for i in listImg:
# show file name
print(i)
foo = Image.open(i)
# show file size
print(foo.size)
# resize file, u can customize the size of image
foo = foo.resize((400,300),Image.ANTIALIAS)
# try to add dir
try:
os.mkdir('Mini')
except:
pass
# finnaly save the file
foo.save("Mini/" + i,quality=95)
@alfianokt
Copy link
Author

Image.open("A21A0033.jpg").resize((int(i.width/6), int(i.height/6)), Image.ANTIALIAS).save("resized/A21A0033.jpg", quality=95)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment