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

tito10047 / progressive-image-bundle / 20693128959

04 Jan 2026 12:47PM UTC coverage: 89.651%. Remained the same
20693128959

push

github

tito10047
fix: adjust indentation and spacing across multiple files for consistent styling and alignment

1 of 1 new or added line in 1 file covered. (100.0%)

121 existing lines in 9 files now uncovered.

693 of 773 relevant lines covered (89.65%)

249.82 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
    ) {
UNCOV
23
    }
462✔
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
    {
UNCOV
30
        $filterName = $filter ? sprintf('%s_%dx%d', $filter, $width, $height) : sprintf('%dx%d', $width, $height);
308✔
31

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

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

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

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

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

UNCOV
61
        return [
308✔
UNCOV
62
            'filterName' => $filterName,
308✔
UNCOV
63
            'config' => $config,
308✔
UNCOV
64
        ];
308✔
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. Calculate the center of the crop on the original image based on the percentage point of interest
UNCOV
73
        $centerX = (int) ($poiX / 100 * $origWidth);
56✔
UNCOV
74
        $centerY = (int) ($poiY / 100 * $origHeight);
56✔
75

76
                // 2. Calculate the start of the crop so that the center is at the point of interest
UNCOV
77
        $startX = $centerX - (int) ($targetWidth / 2);
56✔
UNCOV
78
        $startY = $centerY - (int) ($targetHeight / 2);
56✔
79

80
                // 3. Ensure that the crop does not go outside the original image
UNCOV
81
        $startX = max(0, min($startX, $origWidth - $targetWidth));
56✔
UNCOV
82
        $startY = max(0, min($startY, $origHeight - $targetHeight));
56✔
83

UNCOV
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