Skip to content

Instantly share code, notes, and snippets.

@ShambhalaLogan
Created August 13, 2014 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShambhalaLogan/96d2753d00cd6e6a5018 to your computer and use it in GitHub Desktop.
Save ShambhalaLogan/96d2753d00cd6e6a5018 to your computer and use it in GitHub Desktop.
DL-IMG.py
import os,console
from urllib import urlopen
from time import sleep
from PIL import Image
console.clear()
folderPath = 'ImageFiles/Imported/'
imgPath='Insults'
urlPath='http://i.imgur.com/q4UXODX.png'
print '\nDownloading...'
def ldImg(imgPath,folderPath='Images',urlPath='Null'):
try:
if folderPath: folderPath+="/"
if not os.path.exists(folderPath[:-1]): os.mkdir(folderPath[:-1])
url = urlopen(urlPath)
with open(folderPath+imgPath+'.png', "wb") as output:
output.write(url.read())
return os.getcwd()+'/'+folderPath+imgPath
except:
console.set_color(1,0,0)
print '\nERROR: Download failed.'
def testPix(ik):
print ik
try:
lddImg = ldImg(imgPath,folderPath,urlPath)
Image.open(lddImg+'.png').show()
print folderPath+imgPath+".png has been downloaded.\n"
testPix(open(lddImg+'.png'))
except:
print "\nERROR: Download failed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment