Svg::convert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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