Skip to content

Commit

Permalink
Get image information before closing the browser to avoid URLError (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Jan 30, 2017
1 parent 1a05f22 commit 773991f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/collective/behavior/featuredimage/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
def _get_screenshot(page):
"""Get screenshot of Fetured Image"""
browser = webdriver.PhantomJS()
browser.implicitly_wait(1) # seconds

# Use minimun image size while don't break image proportion
browser.set_window_size(1300, 1300)
browser.get(page)
data = browser.get_screenshot_as_png()
# crop image
el = browser.find_element_by_id('featuredimage')
location, size = el.location, el.size

# XXX: quit() does not terminate PhantomJS process
# https://github.com/SeleniumHQ/selenium/issues/767
browser.service.process.send_signal(signal.SIGTERM)
browser.quit()
location = el.location
size = el.size

# crop image
im = Image.open(StringIO(data))
im = im.crop((
location['x'], location['y'],
Expand Down

0 comments on commit 773991f

Please sign in to comment.