]>
Commit | Line | Data |
---|---|---|
1b93137e A |
1 | <?php |
2 | ||
e85b7a05 A |
3 | namespace Shaarli; |
4 | ||
5 | use Shaarli\Config\ConfigManager; | |
6 | use WebThumbnailer\Exception\WebThumbnailerException; | |
1b93137e | 7 | use WebThumbnailer\WebThumbnailer; |
e85b7a05 | 8 | use WebThumbnailer\Application\ConfigManager as WTConfigManager; |
1b93137e A |
9 | |
10 | /** | |
11 | * Class Thumbnailer | |
12 | * | |
13 | * Utility class used to retrieve thumbnails using web-thumbnailer dependency. | |
14 | */ | |
15 | class Thumbnailer | |
16 | { | |
17 | /** | |
18 | * @var WebThumbnailer instance. | |
19 | */ | |
20 | protected $wt; | |
21 | ||
22 | /** | |
23 | * @var ConfigManager instance. | |
24 | */ | |
25 | protected $conf; | |
26 | ||
27 | /** | |
28 | * Thumbnailer constructor. | |
29 | * | |
30 | * @param ConfigManager $conf instance. | |
31 | */ | |
32 | public function __construct($conf) | |
33 | { | |
34 | $this->conf = $conf; | |
35 | $this->wt = new WebThumbnailer(); | |
e85b7a05 | 36 | WTConfigManager::addFile('inc/web-thumbnailer.json'); |
1b93137e A |
37 | $this->wt->maxWidth($this->conf->get('thumbnails.width')) |
38 | ->maxHeight($this->conf->get('thumbnails.height')) | |
39 | ->crop(true) | |
40 | ->debug($this->conf->get('dev.debug', false)); | |
41 | } | |
42 | ||
43 | /** | |
44 | * Retrieve a thumbnail for given URL | |
45 | * | |
46 | * @param string $url where to look for a thumbnail. | |
47 | * | |
48 | * @return bool|string The thumbnail relative cache file path, or false if none has been found. | |
49 | */ | |
50 | public function get($url) | |
51 | { | |
e85b7a05 A |
52 | try { |
53 | return $this->wt->thumbnail($url); | |
54 | } catch (WebThumbnailerException $e) { | |
55 | // Exceptions are only thrown in debug mode. | |
56 | error_log(get_class($e) .': '. $e->getMessage()); | |
57 | return false; | |
58 | } | |
1b93137e A |
59 | } |
60 | } |