Created
August 28, 2019 00:29
-
-
Save fnzip/6ae16ebe79400775de4494b7d78b4277 to your computer and use it in GitHub Desktop.
Batch minimize image
This file contains hidden or 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
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Image.open("A21A0033.jpg").resize((int(i.width/6), int(i.height/6)), Image.ANTIALIAS).save("resized/A21A0033.jpg", quality=95)