TinyThumbnailExtractor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 44
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A extract() 0 9 1
1
<?php
2
3
namespace Toothless\TinyImage\Extractor;
4
5
use Imagick;
6
7
/**
8
 * Class TinyThumbnailExtractor
9
 */
10
class TinyThumbnailExtractor implements ExtractorInterface
11
{
12
    /**
13
     * @var Imagick
14
     */
15
    private $imagick;
16
17
    /**
18
     * @var int
19
     */
20
    private $sampleWidth;
21
22
    /**
23
     * @var int
24
     */
25
    private $sampleHeight;
26
27
    /**
28
     * TinyThumbnailExtractor constructor.
29
     *
30
     * @param Imagick $imagick
31
     * @param int     $sampleWidth
32
     * @param int     $sampleHeight
33
     */
34 4
    public function __construct(Imagick $imagick, $sampleWidth = 5, $sampleHeight = 5)
35
    {
36 4
        $this->imagick = $imagick;
37 4
        $this->sampleWidth = $sampleWidth;
38 4
        $this->sampleHeight = $sampleHeight;
39 4
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function extract($content)
45
    {
46 2
        $this->imagick->readImageBlob($content);
47 2
        $this->imagick->stripImage();
48 2
        $this->imagick->resizeImage($this->sampleWidth, $this->sampleHeight, Imagick::FILTER_QUADRATIC, 1);
49 2
        $this->imagick->setFormat('GIF');
50
51 2
        return $this->imagick->getImageBlob();
52
    }
53
}
54