Pdf::requirementsAreInstalled()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Spatie\MediaLibrary\ImageGenerators\FileTypes;
4
5
use Illuminate\Support\Collection;
6
use Spatie\MediaLibrary\Conversion\Conversion;
7
use Spatie\MediaLibrary\ImageGenerators\BaseGenerator;
8
9
class Pdf extends BaseGenerator
10
{
11
    public function convert(string $file, Conversion $conversion = null): string
12
    {
13
        $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg';
14
15
        (new \Spatie\PdfToImage\Pdf($file))->saveImage($imageFile);
16
17
        return $imageFile;
18
    }
19
20
    public function requirementsAreInstalled(): bool
21
    {
22
        if (! class_exists('Imagick')) {
23
            return false;
24
        }
25
26
        if (! class_exists('\\Spatie\\PdfToImage\\Pdf')) {
27
            return false;
28
        }
29
30
        return true;
31
    }
32
33
    public function supportedExtensions(): Collection
34
    {
35
        return collect('pdf');
36
    }
37
38
    public function supportedMimeTypes(): Collection
39
    {
40
        return collect(['application/pdf']);
41
    }
42
}
43