-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtension.php
More file actions
executable file
·60 lines (35 loc) · 1.48 KB
/
Extension.php
File metadata and controls
executable file
·60 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
// Disqus comment thread Extension for Bolt
namespace Bolt\Extension\blockmurder\pdfPreview;
use Bolt\Application;
class Extension extends \Bolt\BaseExtension
{
public function getName()
{
return "pdfPreview";
}
function initialize()
{
$this->addTwigFunction('pdfpre', 'pdfpre');
if (empty($this->config['thumbnail_folder'])) { $this->config['thumbnail_folder'] = "pdf_temp/"; }
}
function pdfpre($file="", $width=100, $height=0)
{
$thumb_path = $this->app['paths']['filespath'].'/'.$this->config['thumbnail_folder'];
if(!is_dir($thumb_path)) {
mkdir($thumb_path , 0777);
}
$path_parts = pathinfo($this->app['paths']['filespath'].$file);
$filename = $path_parts['filename'];
$filepath = $path_parts['dirname'];
if (!file_exists($thumb_path.$filename.'.jpg')) {
exec('convert "'.$this->app['paths']['filespath'].'/'.$file.'[0]" -colorspace RGB -density 300 -quality 95 -background white -alpha remove -geometry '.$width.' -border 2x2 -bordercolor "#efefef" '.$thumb_path.$filename.'.jpg');
}
$html = <<< EOM
<img src="%src%" alt="%alt%">
EOM;
$html = str_replace("%src%", $this->app['paths']['files'].$this->config['thumbnail_folder'].$filename.'.jpg', $html);
$html = str_replace("%alt%", $filename, $html);
return new \Twig_Markup($html, 'UTF-8');
}
}