Skip to content

Instantly share code, notes, and snippets.

@maryburford
Created November 9, 2015 14:57
Show Gist options
  • Select an option

  • Save maryburford/3d4c3b25b74ddefed18c to your computer and use it in GitHub Desktop.

Select an option

Save maryburford/3d4c3b25b74ddefed18c to your computer and use it in GitHub Desktop.
import urllib
import os
import tweepy
import csv
import time
import PIL
from PIL import Image, ImageOps
def tweet_image(url, message):
api = twitter_api()
urllib.urlretrieve(url, "image.jpg")
filename = 'image.jpg'
image = Image.open(filename)
size = (440,220)
image.thumbnail(size, Image.ANTIALIAS)
background = Image.new('RGBA', size, (255, 255, 255, 0))
background.paste(image,((size[0] - image.size[0]) / 2, (size[1] - image.size[1]) / 2))
background.save('resized_image.jpg')
filename1 = 'resized_image.jpg'
api.update_with_media(filename1, status=message)
os.remove(filename1)
os.remove(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment