Skip to content

Instantly share code, notes, and snippets.

@vaclavcadek
Created July 10, 2014 15:36
Show Gist options
  • Save vaclavcadek/d52fb355a87ff78a84df to your computer and use it in GitHub Desktop.
Save vaclavcadek/d52fb355a87ff78a84df to your computer and use it in GitHub Desktop.
Download image from url, make polyline and convert it to base64
from base64 import b64encode
from PIL import Image, ImageDraw
import requests
from StringIO import StringIO
url = 'http://jssgallery.org/other_artists/andy_warhol/campbells.jpg'
response = requests.get(url)
img = Image.open(StringIO(response.content))
draw = ImageDraw.Draw(img)
draw.line([(449, 203), (447, 763), (208, 763), (215, 200), (449, 203)], fill=126, width=3)
output = StringIO()
img.save(output, 'PNG')
contents = output.getvalue()
print b64encode(contents)
img.save("img.png", "PNG")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment