def load_and_save_image(url, destination):
    """Download image from given url and saves it to destination."""
    from urllib2 import Request, urlopen, URLError, HTTPError
    # create the url and the request
    req = Request(url)

    # Open the url
    try:
        f = urlopen(req)
        print "downloading " + url

        # Open our local file for writing

        local_file = open(destination, "wb")
        # Write to our local file
        local_file.write(f.read())
        local_file.close()

        file_type = imghdr.what(destination)
        local_file = open(destination, "rb")
        data = local_file.read()
        local_file.close()

        final_file = open(destination + '.' + file_type, "wb")
        final_file.write(data)
        final_file.close()
        print('save image preview {0}'.format(destination + '.' + file_type))
        os.remove(destination)

    # handle errors
    except HTTPError, e:
        print "HTTP Error:", e.code, url
    except URLError, e:
        print "URL Error:", e.reason, url
def load_and_save_image ( url , destination ) : from urllib2 import Request , urlopen , URLError , HTTPError req = Request ( url ) try : f = urlopen ( req ) print "downloading " + url local_file = open ( destination , "wb" ) local_file . write ( f . read ( ) ) local_file . close ( ) file_type = imghdr . what ( destination ) local_file = open ( destination , "rb" ) data = local_file . read ( ) local_file . close ( ) final_file = open ( destination + '.' + file_type , "wb" ) final_file . write ( data ) final_file . close ( ) print ( 'save image preview {0}' . format ( destination + '.' + file_type ) ) os . remove ( destination ) except HTTPError , e : print "HTTP Error:" , e . code , url except URLError , e : print "URL Error:" , e . reason , url
Download image from given url and saves it to destination.