Skip to content

Instantly share code, notes, and snippets.

@rsignell-usgs
Created October 17, 2012 18:46
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 rsignell-usgs/3907322 to your computer and use it in GitHub Desktop.
Save rsignell-usgs/3907322 to your computer and use it in GitHub Desktop.
import urllib
import urllib2
import matplotlib.pyplot as plt
# 1. imread can load a PNG URL thusly...
url = 'http://optipng.sourceforge.net/pngtech/img/lena.png'
im = plt.imread(urllib2.urlopen(url),format='png')
plt.imshow(im)
# 2. same thing for JPG URL bombs...
url = 'http://www.kitware.com/blog/files/128_1232259669.jpg'
im = plt.imread(urllib2.urlopen(url),format='jpg')
plt.imshow(im)
# 3. yet imread can read JPG if downloaded first
urllib.urlretrieve(url,'lena.jpg')
im = plt.imread('lena.jpg')
plt.imshow(im,origin='lower')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment