Skip to content

Instantly share code, notes, and snippets.

@dogancankilment
Last active April 10, 2016 17:39
Show Gist options
  • Save dogancankilment/18e9bc2c908a38106059b63232378fd6 to your computer and use it in GitHub Desktop.
Save dogancankilment/18e9bc2c908a38106059b63232378fd6 to your computer and use it in GitHub Desktop.
import os
import PIL
from PIL import Image
def image_resizer(path):
img = Image.open(path)
basewidth = 700
wpercent = (basewidth / float(img.size[0]))
# hsize = int((float(img.size[1]) * float(wpercent)))
hsize = 300
img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
img.save(path)
if __name__ == '__main__':
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
image_path = os.path.join(BASE_DIR, 'your-image.jpeg')
image_resizer(image_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment