[ create a new paste ] login | about

Link: http://codepad.org/tV01oz79    [ raw code | fork ]

Python, pasted on Sep 18:
import struct
import urllib2

class wallpaper:
    def __init__(self, url):
        self.url = url
        self.content_type = ''
        self.height = 0
        self.width = 0
        image = urllib2.urlopen(self.url)
        data = str(image.read(2))
        if  data.startswith('\377\330'):
            self.content_type = 'image/jpeg'
            image = urllib2.urlopen(url)
            data = str(image.read(2))
            b = image.read(1)
            try:
                while (b and ord(b) != 0xDA):
                    while (ord(b) != 0xFF): b = image.read(1)
                    while (ord(b) == 0xFF): b = image.read(1)
                    if (ord(b) >= 0xC0 and ord(b) <= 0xC3):
                        image.read(3)
                        h, w = struct.unpack(">HH", image.read(4))
                        break
                    else:
                        image.read(int(struct.unpack(">H", image.read(2))[0])-2)
                    b = image.read(1)
                self.width = int(w)
                self.height = int(h)
            except struct.error:
                print "Struct error"
            except ValueError:
                print "Value error"

x = wallpaper('http://i.imgur.com/rapwX.jpg')

print x.url, "\t", x.content_type,"\t", x.height,"\t", x.width


Create a new paste based on this one


Comments: