5 use Shaarli\Config\ConfigManager
;
6 use WebThumbnailer\Exception\WebThumbnailerException
;
7 use WebThumbnailer\WebThumbnailer
;
8 use WebThumbnailer\Application\ConfigManager
as WTConfigManager
;
13 * Utility class used to retrieve thumbnails using web-thumbnailer dependency.
18 * @var WebThumbnailer instance.
23 * @var ConfigManager instance.
28 * Thumbnailer constructor.
30 * @param ConfigManager $conf instance.
32 public function __construct($conf)
36 if (! $this->checkRequirements()) {
37 $this->conf
->set('thumbnails.enabled', false);
38 $this->conf
->write(true);
39 // TODO: create a proper error handling system able to catch exceptions...
40 die(t('php-gd extension must be loaded to use thumbnails. Thumbnails are now disabled. Please reload the page.'));
43 $this->wt
= new WebThumbnailer();
44 WTConfigManager
::addFile('inc/web-thumbnailer.json');
45 $this->wt
->maxWidth($this->conf
->get('thumbnails.width'))
46 ->maxHeight($this->conf
->get('thumbnails.height'))
48 ->debug($this->conf
->get('dev.debug', false));
52 * Retrieve a thumbnail for given URL
54 * @param string $url where to look for a thumbnail.
56 * @return bool|string The thumbnail relative cache file path, or false if none has been found.
58 public function get($url)
61 return $this->wt
->thumbnail($url);
62 } catch (WebThumbnailerException
$e) {
63 // Exceptions are only thrown in debug mode.
64 error_log(get_class($e) .': '. $e->getMessage());
70 * Make sure that requirements are match to use thumbnails:
73 protected function checkRequirements()
75 return extension_loaded('gd');