Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created July 24, 2011 03:23
Show Gist options
  • Save arthurnn/1102182 to your computer and use it in GitHub Desktop.
Save arthurnn/1102182 to your computer and use it in GitHub Desktop.
threadless wallpaper
from PIL import Image
import urllib
import cStringIO
import re
import sys
URL = sys.argv[1]
ratio = 1
size = (1440,900)
reg = 'm|^http://.*threadless.*/(\d+)/([^/]+)|'
m = re.search(reg, URL)
pid = m.group(1)
URL = "http://media.threadless.com/product/%s/zoom.gif" % pid
file = urllib.urlopen(URL)
im = cStringIO.StringIO(file.read())
img = Image.open(im)
img = img.resize( [int(ratio * s) for s in img.size],Image.ANTIALIAS )
place = (((size[0] - img.size[0])/2,(size[1] - img.size[1])/2))
bg = img.crop((0,0,1,1))
bg = bg.resize(size)
bg.paste(img,place)
bg.save('background.png','png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment