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

tito10047 / progressive-image-bundle / 20675022582

03 Jan 2026 08:51AM UTC coverage: 86.782%. Remained the same
20675022582

push

github

tito10047
update copyright in LICENSE.md

604 of 696 relevant lines covered (86.78%)

175.71 hits per line

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

96.77
/src/Service/LiipImagineRuntimeConfigGenerator.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
declare(strict_types=1);
12

13
namespace Tito10047\ProgressiveImageBundle\Service;
14

15
use Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException;
16
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
17

18
final class LiipImagineRuntimeConfigGenerator implements LiipImagineRuntimeConfigGeneratorInterface
19
{
20
        public function __construct(
21
                private readonly FilterConfiguration $filterConfiguration,
22
        ) {
23
        }
336✔
24

25
        /**
26
         * @return array{filterName: string, config: array<string, mixed>}
27
         */
28
        public function generate(int $width, int $height, ?string $filter = null, ?string $pointInterest = null, ?int $origWidth = null, ?int $origHeight = null): array
29
        {
30
                $filterName = $filter ? sprintf('%s_%dx%d', $filter, $width, $height) : sprintf('%dx%d', $width, $height);
210✔
31

32
                if ($pointInterest) {
210✔
33
                        $filterName .= '_' . $pointInterest;
56✔
34
                }
35

36
                $config = [];
210✔
37
                if ($filter !== null) {
210✔
38
                        try {
39
                                $config = $this->filterConfiguration->get($filter);
28✔
40
                        } catch (NonExistingFilterException) {
×
41
                        }
42
                }
43

44
                if (!isset($config['filters'])) {
210✔
45
                        $config['filters'] = [];
182✔
46
                }
47

48
                if ($pointInterest && $origWidth && $origHeight) {
210✔
49
                        [$poiX, $poiY] = explode('x', $pointInterest);
56✔
50
                        $config['filters']['crop'] = [
56✔
51
                                'start' => $this->calculateCropStart((int)$poiX, (int)$poiY, $width, $height, $origWidth, $origHeight),
56✔
52
                                'size' => [$width, $height],
56✔
53
                        ];
56✔
54
                }
55

56
                $config['filters']['thumbnail'] = [
210✔
57
                        'size' => [$width, $height],
210✔
58
                        'mode' => 'outbound',
210✔
59
                ];
210✔
60

61
                return [
210✔
62
                        'filterName' => $filterName,
210✔
63
                        'config' => $config,
210✔
64
                ];
210✔
65
        }
66

67
        /**
68
         * @return array{int, int}
69
         */
70
        private function calculateCropStart(int $poiX, int $poiY, int $targetWidth, int $targetHeight, int $origWidth, int $origHeight): array
71
        {
72
                // 1. Vypočítame stred orezu na originálnom obrázku podľa percentuálneho bodu záujmu
73
                $centerX = (int) ($poiX / 100 * $origWidth);
56✔
74
                $centerY = (int) ($poiY / 100 * $origHeight);
56✔
75

76
                // 2. Vypočítame začiatok orezu tak, aby stred bol na bode záujmu
77
                $startX = $centerX - (int) ($targetWidth / 2);
56✔
78
                $startY = $centerY - (int) ($targetHeight / 2);
56✔
79

80
                // 3. Zabezpečíme, aby orez nevychádzal mimo originálny obrázok
81
                $startX = max(0, min($startX, $origWidth - $targetWidth));
56✔
82
                $startY = max(0, min($startY, $origHeight - $targetHeight));
56✔
83

84
                return [$startX, $startY];
56✔
85
        }
86
}
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