Completed
Push — master ( 8c862e...56eee6 )
by Freek
02:32
created

Svg::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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