Skip to content

Commit

Permalink
Use web-thumbnailer to retrieve thumbnails
Browse files Browse the repository at this point in the history
  * requires PHP 5.6
  * use blazy on linklist since a lot more thumbs are retrieved
  * thumbnails can be disabled
  * thumbs size is now 120x120
  * thumbs are now cropped to fit the expected size

Fixes shaarli#345 shaarli#425 shaarli#487 shaarli#543 shaarli#588 shaarli#590
  • Loading branch information
ArthurHoaro committed Nov 9, 2016
1 parent f5f6a4b commit 9950053
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 434 deletions.
3 changes: 3 additions & 0 deletions application/PageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ private function initialize()
$this->tpl->assign('showatom', $this->conf->get('feed.show_atom', false));
$this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
$this->tpl->assign('token', getToken($this->conf));
$this->tpl->assign('thumbnails_enabled', $this->conf->get('thumbnails.enabled'));
$this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width'));
$this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height'));
// To be removed with a proper theme configuration.
$this->tpl->assign('conf', $this->conf);
}
Expand Down
48 changes: 48 additions & 0 deletions application/Thumbnailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use WebThumbnailer\WebThumbnailer;

/**
* Class Thumbnailer
*
* Utility class used to retrieve thumbnails using web-thumbnailer dependency.
*/
class Thumbnailer
{
/**
* @var WebThumbnailer instance.
*/
protected $wt;

/**
* @var ConfigManager instance.
*/
protected $conf;

/**
* Thumbnailer constructor.
*
* @param ConfigManager $conf instance.
*/
public function __construct($conf)
{
$this->conf = $conf;
$this->wt = new WebThumbnailer();
\WebThumbnailer\Application\ConfigManager::addFile('inc/web-thumbnailer.json');
$this->wt->maxWidth($this->conf->get('thumbnails.width'))
->maxHeight($this->conf->get('thumbnails.height'))
->crop(true);
}

/**
* Retrieve a thumbnail for given URL
*
* @param string $url where to look for a thumbnail.
*
* @return bool|string The thumbnail relative cache file path, or false if none has been found.
*/
public function get($url)
{
return $this->wt->thumbnail($url);
}
}
4 changes: 4 additions & 0 deletions application/config/ConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ protected function setDefaultValues()
$this->setEmpty('general.links_per_page', 20);
$this->setEmpty('general.enabled_plugins', array('qrcode'));

$this->setEmpty('thumbnails.enabled', true);
$this->setEmpty('thumbnails.width', 120);
$this->setEmpty('thumbnails.height', 120);

$this->setEmpty('updates.check_updates', false);
$this->setEmpty('updates.check_updates_branch', 'stable');
$this->setEmpty('updates.check_updates_interval', 86400);
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
},
"keywords": ["bookmark", "link", "share", "web"],
"require": {
"php": ">=5.3.4",
"php": ">=5.6",
"shaarli/netscape-bookmark-parser": "1.*",
"erusev/parsedown": "1.6"
"erusev/parsedown": "1.6",
"arthurhoaro/web-thumbnailer": "dev-master"
},
"require-dev": {
"phpmd/phpmd" : "@stable",
Expand Down
8 changes: 4 additions & 4 deletions inc/shaarli.css
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,8 @@ em {
position: relative;
display: table-cell;
vertical-align: middle;
width: 90px;
height: 90px;
width: 120px;
height: 120px;
overflow: hidden;
text-align: center;
float: left;
Expand Down Expand Up @@ -725,9 +725,9 @@ em {
position: absolute;
top: 0;
left: 0;
width: 90px;
width: 120px;
font-weight: bold;
font-size: 8pt;
font-size: 9pt;
color: #fff;
text-align: left;
background-color: transparent;
Expand Down
8 changes: 8 additions & 0 deletions inc/web-thumbnailer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"settings": {
"default": {
"_comment": "infinite cache",
"cache_duration": -1
}
}
}
Loading

0 comments on commit 9950053

Please sign in to comment.