Last active
August 21, 2018 18:18
-
-
Save leonardopinho/a1fdc5a8846c2c94edc49796386732d5 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
import wget | |
from PIL import Image | |
def download_image(filename, url, path='', resize=False, width=600): | |
""" | |
backup of the images of server | |
:param filename: | |
:param url: | |
:param path: | |
:param resize: | |
:param width: | |
:return: | |
""" | |
try: | |
url = '{0}/{1}'.format(url, filename) | |
filename = wget.download(url, out=path) | |
if resize: | |
basewidth = width | |
img = Image.open(filename) | |
wpercent = (basewidth / float(img.size[0])) | |
hsize = int((float(img.size[1]) * float(wpercent))) | |
img = img.resize((basewidth, hsize), Image.ANTIALIAS) | |
img.save(filename) | |
except Exception as e: | |
print('error: {0}'.format(e)) | |
return filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment