Skip to content

Commit

Permalink
Issue 36 - Add timeout to create image (#37)
Browse files Browse the repository at this point in the history
* Refactor

* Add timeout to create image

* Kill phantomjs after screnshot

* Change code to prevent exceptions

* Refactor
  • Loading branch information
rodfersou authored and hvelarde committed Jan 25, 2017
1 parent 5e9c7bd commit 2eeef92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 1 addition & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Changelog
1.0a1 (unreleased)
------------------

- Fix extra space between text and quotes (pseudo element).
[rodfersou]
- Initial release.
15 changes: 10 additions & 5 deletions src/collective/behavior/featuredimage/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
from plone.namedfile.file import NamedBlobImage
from selenium import webdriver

import signal
import transaction


def _get_screenshot(page):
"""Get screenshot of Fetured Image"""
driver = webdriver.PhantomJS()
browser = webdriver.PhantomJS()
# Use minimun image size while don't break image proportion
driver.set_window_size(1300, 1300)
driver.get(page)
data = driver.get_screenshot_as_png()
browser.set_window_size(1300, 1300)
browser.get(page)
data = browser.get_screenshot_as_png()
# crop image
el = driver.find_element_by_id('featuredimage')
el = browser.find_element_by_id('featuredimage')
# 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
im = Image.open(StringIO(data))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2eeef92

Please sign in to comment.