Cut a screenshot with a variable bottom PIL

Viewed 77

I used apiflash site api to write a code that takes a screenshot of a web page (from a tweet on Twitter) and then cuts around the image using the PIL module, but the problem is that I can not determine how much to cut below the tweet . From the top, left and right are fixed values, but the size below the tweets varies

any other idea how to get picture of only one tweet?

this is my code:

def screenshot(url, cond):
    params = urlencode(dict(access_key="api", url=url))
    urlretrieve("https://api.apiflash.com/v1/urltoimage?" + params, "screenshot.jpg")

    image = Image.open(r'screenshot.jpg')
    image = image.convert("RGB")
    left = 605
    top = 60
    right = 1200
    bottom = 285 # this is the variable that i should change everytime
    image = image.crop((left, top, right, bottom))
    image.save('screenshot.jpg')

this is the full screenshot: click

this is what i need: click

this is what i get(with this code): click

0 Answers
Related