forked from codebuds33/webp-conversion-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebPConversion.php
More file actions
34 lines (27 loc) · 896 Bytes
/
Copy pathWebPConversion.php
File metadata and controls
34 lines (27 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace CodeBuds\WebPConversionBundle;
use CodeBuds\WebPConversionBundle\Model\Image;
use CodeBuds\WebPConversionBundle\Model\WebPInformation;
use CodeBuds\WebPConversionBundle\Service\ImageConverter;
use Exception;
use Symfony\Component\HttpFoundation\File\File;
class WebPConversion
{
public function __construct(private int $quality, private ImageConverter $imageConverter)
{
}
/**
* @throws Exception
*/
public function convert(File $imageFile, bool $force = false): WebPInformation
{
$image = new Image($imageFile);
if ($image->getQuality() === null) {
$image->setQuality($this->quality);
}
if ($force && $this->imageConverter->convertedImageExists($image)) {
return $this->imageConverter->convert($image, true);
}
return $this->imageConverter->convert($image);
}
}