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

tito10047 / progressive-image-bundle / 21092461285

17 Jan 2026 09:56AM UTC coverage: 90.889% (+0.5%) from 90.395%
21092461285

push

github

web-flow
Merge pull request #3 from tito10047/modifiers

add modifiers capability

42 of 55 new or added lines in 10 files covered. (76.36%)

1 existing line in 1 file now uncovered.

838 of 922 relevant lines covered (90.89%)

308.03 hits per line

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

100.0
/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

21
        /**
22
         * @param array<string, mixed> $imageConfigs
23
         */
24
    public function __construct(
25
        private readonly FilterConfiguration $filterConfiguration,
26
                private readonly array $imageConfigs = [],
27
    ) {
28
    }
616✔
29

30
    /**
31
     * @return array{filterName: string, config: array<string, mixed>}
32
     */
33
        public function generate(int $width, int $height, ?string $filter = null, ?string $pointInterest = null, ?int $origWidth = null, ?int $origHeight = null, array $context = []): array
34
    {
35
        $filterName = $filter ? sprintf('%s_%dx%d', $filter, $width, $height) : sprintf('%dx%d', $width, $height);
462✔
36

37
        if ($pointInterest) {
462✔
38
            $filterName .= '_'.$pointInterest;
56✔
39
        }
40

NEW
41
                if ($context) {
462✔
NEW
42
                        $filterName .= '_' . substr(md5(serialize($context)), 0, 5);
56✔
43
                }
44

45
                if ($this->imageConfigs) {
462✔
46
                        $filterName .= '_' . substr(md5(serialize($this->imageConfigs)), 0, 5);
28✔
47
                }
48

49
        $config = [];
462✔
50
        if (null !== $filter) {
462✔
51
            try {
52
                $config = $this->filterConfiguration->get($filter);
84✔
53
            } catch (NonExistingFilterException) {
28✔
54
            }
55
        }
56

NEW
57
                $config = array_replace_recursive($config, $this->imageConfigs, $context);
462✔
58

59
        if (!isset($config['filters'])) {
462✔
60
            $config['filters'] = [];
406✔
61
        }
62

63
        if ($pointInterest && $origWidth && $origHeight) {
462✔
64
            [$poiX, $poiY] = explode('x', $pointInterest);
56✔
65
            $config['filters']['crop'] = [
56✔
66
                'start' => $this->calculateCropStart((int) $poiX, (int) $poiY, $width, $height, $origWidth, $origHeight),
56✔
67
                'size' => [$width, $height],
56✔
68
            ];
56✔
69
        }
70

71
        $config['filters']['thumbnail'] = [
462✔
72
            'size' => [$width, $height],
462✔
73
            'mode' => 'outbound',
462✔
74
        ];
462✔
75

76
        return [
462✔
77
            'filterName' => $filterName,
462✔
78
            'config' => $config,
462✔
79
        ];
462✔
80
    }
81

82
    /**
83
     * @return array{int, int}
84
     */
85
    private function calculateCropStart(int $poiX, int $poiY, int $targetWidth, int $targetHeight, int $origWidth, int $origHeight): array
86
    {
87
                // 1. Calculate the center of the crop on the original image based on the percentage point of interest
88
        $centerX = (int) ($poiX / 100 * $origWidth);
56✔
89
        $centerY = (int) ($poiY / 100 * $origHeight);
56✔
90

91
                // 2. Calculate the start of the crop so that the center is at the point of interest
92
        $startX = $centerX - (int) ($targetWidth / 2);
56✔
93
        $startY = $centerY - (int) ($targetHeight / 2);
56✔
94

95
                // 3. Ensure that the crop does not go outside the original image
96
        $startX = max(0, min($startX, $origWidth - $targetWidth));
56✔
97
        $startY = max(0, min($startY, $origHeight - $targetHeight));
56✔
98

99
        return [$startX, $startY];
56✔
100
    }
101
}
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