1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Divergence package. |
4
|
|
|
* |
5
|
|
|
* (c) Henry Paradiz <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Divergence\Models\Media; |
12
|
|
|
|
13
|
|
|
use Exception; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* PDF Media Model |
17
|
|
|
* |
18
|
|
|
* @author Henry Paradiz <[email protected]> |
19
|
|
|
* @author Chris Alfano <[email protected]> |
20
|
|
|
* |
21
|
|
|
* {@inheritDoc} |
22
|
|
|
*/ |
23
|
|
|
class PDF extends Media |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
// configurables |
26
|
|
|
public static $extractPageCommand = 'convert \'%1$s[%2$u]\' JPEG:- 2>/dev/null'; // 1=pdf path, 2=page |
27
|
|
|
public static $extractPageIndex = 0; |
28
|
|
|
|
29
|
|
|
public function getValue($name) |
30
|
|
|
{ |
31
|
|
|
switch ($name) { |
32
|
|
|
case 'ThumbnailMIMEType': |
33
|
|
|
return 'image/png'; |
34
|
|
|
|
35
|
|
|
case 'Extension': |
36
|
|
|
|
37
|
|
|
switch ($this->getValue('MIMEType')) { |
38
|
|
|
case 'application/pdf': |
39
|
|
|
return 'pdf'; |
40
|
|
|
case 'application/postscript': |
41
|
|
|
return 'eps'; |
42
|
|
|
case 'image/svg+xml': |
43
|
|
|
return 'svg'; |
44
|
|
|
default: |
45
|
|
|
throw new Exception('Unable to find document extension for mime-type: '.$this->getValue('MIMEType')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// no break |
49
|
|
|
default: |
50
|
|
|
return parent::getValue($name); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
// public methods |
56
|
|
|
public function getImage($sourceFile = null): false|\GdImage |
57
|
|
|
{ |
58
|
|
|
if (!isset($sourceFile)) { |
59
|
|
|
$sourceFile = $this->FilesystemPath ? $this->FilesystemPath : $this->BlankPath; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$cmd = sprintf(static::$extractPageCommand, $sourceFile, static::$extractPageIndex); |
63
|
|
|
$fileImage = imagecreatefromstring(shell_exec($cmd)); |
64
|
|
|
|
65
|
|
|
return $fileImage; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// static methods |
69
|
|
|
public static function analyzeFile($filename, $mediaInfo = []) |
70
|
|
|
{ |
71
|
|
|
$cmd = sprintf(static::$extractPageCommand, $filename, static::$extractPageIndex); |
72
|
|
|
$pageIm = @imagecreatefromstring(shell_exec($cmd)); |
73
|
|
|
|
74
|
|
|
if (!$pageIm) { |
75
|
|
|
throw new Exception('Unable to convert PDF, ensure that imagemagick is installed on the server'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$mediaInfo['width'] = imagesx($pageIm); |
79
|
|
|
$mediaInfo['height'] = imagesy($pageIm); |
80
|
|
|
|
81
|
|
|
return $mediaInfo; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths