| Conditions | 5 |
| Paths | 3 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | 2 | public function apply($absolutePath) |
|
| 23 | { |
||
| 24 | 2 | $info = pathinfo($absolutePath); |
|
| 25 | |||
| 26 | 2 | if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf') && file_exists($absolutePath)) { |
|
| 27 | // If it doesn't exist yet, extract the first page of the PDF |
||
| 28 | 2 | $previewFilename = $this->getPreviewFilename($absolutePath); |
|
| 29 | 2 | if (!file_exists($previewFilename)) { |
|
| 30 | 1 | $this->imagick->readImage($absolutePath . '[0]'); |
|
| 31 | 1 | $this->imagick->setImageFormat('jpg'); |
|
| 32 | 1 | $this->imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); |
|
| 33 | 1 | $this->imagick->writeImage($previewFilename); |
|
| 34 | 1 | $this->imagick->clear(); |
|
| 35 | } |
||
| 36 | |||
| 37 | 2 | $absolutePath = $previewFilename; |
|
| 38 | } |
||
| 39 | |||
| 40 | 2 | return $absolutePath; |
|
| 41 | } |
||
| 42 | |||
| 53 |