Created
June 29, 2017 12:49
-
-
Save homm/93d4b65b5a6a3d50973d061eb7d17c65 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
#!/usr/bin/python | |
import sys | |
import time | |
from PIL import Image, ImageFilter, PILLOW_VERSION | |
class Timer: | |
def __init__(self, name): | |
self.name = name | |
def __enter__(self): | |
self.start = time.clock() | |
return self | |
def __exit__(self, *args): | |
self.end = time.clock() | |
self.interval = self.end - self.start | |
print('>>> %s: %.03f sec' % (self.name, self.interval)) | |
with Timer('Load'): | |
im = Image.open(sys.argv[1]) | |
im.load() | |
with Timer('Crop'): | |
im = im.crop((100, 100, im.size[0] - 100, im.size[1] - 100)) | |
with Timer('Resize'): | |
im = im.resize((int (im.size[0] * 0.9), int (im.size[1] * 0.9)), | |
Image.BILINEAR) | |
with Timer('Filter'): | |
filter = ImageFilter.Kernel((3, 3), | |
(-1, -1, -1, | |
-1, 16, -1, | |
-1, -1, -1)) | |
im = im.filter(filter) | |
with Timer('Save'): | |
im.save(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment