Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cStringIO import StringIO
- import Image
- import urllib
- def to_png(path, mime="png"):
- if path.startswith("http:"):
- url = urllib.quote(url)
- input = StringIO()
- input.write(urllib.urlopen(url).read())
- input.seek(0)
- else:
- input = open(path).read()
- if input:
- out = StringIO()
- image = Image.open(input)
- image.save(out, mime.upper())
- return out.getvalue()
- else:
- return None
Add Comment
Please, Sign In to add comment