Skip to content

Instantly share code, notes, and snippets.

@leonardopinho
Last active August 21, 2018 18:18
Show Gist options
  • Save leonardopinho/a1fdc5a8846c2c94edc49796386732d5 to your computer and use it in GitHub Desktop.
Save leonardopinho/a1fdc5a8846c2c94edc49796386732d5 to your computer and use it in GitHub Desktop.
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