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 May 5, 2018
1 parent 3e35fc1 commit 5c02a79
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 430 deletions.
5 changes: 5 additions & 0 deletions application/PageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ private function initialize()
if ($this->linkDB !== null) {
$this->tpl->assign('tags', $this->linkDB->linksCountPerTag());
}

$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
49 changes: 49 additions & 0 deletions application/Thumbnailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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)
->debug($this->conf->get('dev.debug', false));
}

/**
* 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 @@ -319,6 +319,10 @@ protected function setDefaultValues()
$this->setEmpty('general.enabled_plugins', self::$DEFAULT_PLUGINS);
$this->setEmpty('general.default_note_title', 'Note: ');

$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
8 changes: 4 additions & 4 deletions assets/vintage/css/shaarli.css
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ a.bigbutton, #pageheader a.bigbutton {
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 @@ -739,9 +739,9 @@ a.bigbutton, #pageheader a.bigbutton {
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"shaarli/netscape-bookmark-parser": "^2.0",
"erusev/parsedown": "^1.6",
"slim/slim": "^3.0",
"arthurhoaro/web-thumbnailer": "dev-master",
"pubsubhubbub/publisher": "dev-master",
"gettext/gettext": "^4.4"
},
Expand Down
9 changes: 9 additions & 0 deletions inc/web-thumbnailer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"settings": {
"default": {
"_comment": "infinite cache",
"cache_duration": -1,
"timeout": 60
}
}
}
Loading

0 comments on commit 5c02a79

Please sign in to comment.