• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tito10047 / progressive-image-bundle / 21093331125

17 Jan 2026 11:10AM UTC coverage: 90.436% (-0.5%) from 90.889%
21093331125

push

github

web-flow
Merge pull request #4 from tito10047/responsive-strategy

change rendering stratety from <img> to <picture><source><img> for better responsive strategy

268 of 332 new or added lines in 19 files covered. (80.72%)

5 existing lines in 2 files now uncovered.

851 of 941 relevant lines covered (90.44%)

318.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/Analyzer/ImagickAnalyzer.php
1
<?php
2

3
/*
4
 * This file is part of the Progressive Image Bundle.
5
 *
6
 * (c) Jozef Môstka <https://github.com/tito10047/progressive-image-bundle>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace Tito10047\ProgressiveImageBundle\Analyzer;
13

14
use kornrunner\Blurhash\Blurhash;
15
use Tito10047\ProgressiveImageBundle\DTO\ImageMetadata;
16
use Tito10047\ProgressiveImageBundle\Exception\ImageProcessingException;
17
use Tito10047\ProgressiveImageBundle\Loader\LoaderInterface;
18

19
final class ImagickAnalyzer implements ImageAnalyzerInterface
20
{
21
    public function __construct(
22
        private readonly int $componentsX = 4,
23
        private readonly int $componentsY = 3,
24
    ) {
25
    }
15✔
26

27
    public function analyze(LoaderInterface $loader, string $path): ImageMetadata
28
    {
29
        $image = new \Imagick();
15✔
30

31
        try {
32
            // 3. Loading directly from handle
33
            $image->readImageFile($loader->load($path));
15✔
34
            $orgWidth = $image->getImageWidth();
15✔
35
            $orgHeight = $image->getImageHeight();
15✔
36
            $image->thumbnailImage(64, 64, true);
15✔
37
            $width = $image->getImageWidth();
15✔
38
            $height = $image->getImageHeight();
15✔
39

40
            $pixels = $image->exportImagePixels(0, 0, $width, $height, 'RGB', \Imagick::PIXEL_CHAR);
15✔
41

42
            $formattedPixels = [];
15✔
43
            for ($y = 0; $y < $height; ++$y) {
15✔
44
                $row = [];
15✔
45
                for ($x = 0; $x < $width; ++$x) {
15✔
46
                    $offset = ($y * $width + $x) * 3;
15✔
47
                    $row[] = [
15✔
48
                        $pixels[$offset],
15✔
49
                        $pixels[$offset + 1],
15✔
50
                        $pixels[$offset + 2],
15✔
51
                    ];
15✔
52
                }
53
                $formattedPixels[] = $row;
15✔
54
            }
55
        } catch (\ImagickException $e) {
×
NEW
56
            throw new ImageProcessingException('Imagick could not load data from stream: '.$e->getMessage());
×
57
        }
58

59
        $hash = Blurhash::encode($formattedPixels, $this->componentsX, $this->componentsY);
15✔
60

61
        return new ImageMetadata(
15✔
62
            $hash,
15✔
63
            $orgWidth,
15✔
64
            $orgHeight
15✔
65
        );
15✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc