for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Ecodev\Felix\Service;
use Ecodev\Felix\Model\Image;
use Imagine\Image\Box;
use Imagine\Image\ImagineInterface;
/**
* Service to resize image's images.
*/
class ImageResizer
{
private const CACHE_IMAGE_PATH = 'data/cache/images/';
public function __construct(private readonly ImagineInterface $imagine)
}
* Resize image as JPG or WEBP and return the path to the resized version.
public function resize(Image $image, int $maxHeight, bool $useWebp): string
if ($image->getMime() === 'image/svg+xml') {
return $image->getPath();
$maxHeight = min($maxHeight, $image->getHeight());
$basename = pathinfo($image->getFilename(), PATHINFO_FILENAME);
$extension = $useWebp ? '.webp' : '.jpg';
$path = realpath('.') . '/' . self::CACHE_IMAGE_PATH . $basename . '-' . $maxHeight . $extension;
$basename
array|string
concatenation
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
ignore-type
$path = realpath('.') . '/' . self::CACHE_IMAGE_PATH . /** @scrutinizer ignore-type */ $basename . '-' . $maxHeight . $extension;
if (file_exists($path)) {
return $path;
$image = $this->imagine->open($image->getPath());
$image->thumbnail(new Box(1_000_000, $maxHeight))->save($path);
Ecodev\Felix\Service\1_000_000