| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Endroid\QrCode\Writer\Result; |
| 6 |
|
| 7 |
use Endroid\QrCode\Matrix\MatrixInterface; |
| 8 |
|
| 9 |
final class WebPResult extends GdResult |
| 10 |
{ |
| 11 |
public function __construct( |
| 12 |
MatrixInterface $matrix, |
| 13 |
\GdImage $image, |
| 14 |
private readonly int $quality = -1 |
| 15 |
) { |
| 16 |
parent::__construct($matrix, $image); |
| 17 |
} |
| 18 |
|
| 19 |
public function getString(): string |
| 20 |
{ |
| 21 |
if (!function_exists('imagewebp')) { |
| 22 |
throw new \Exception('WebP support is not available in your GD installation'); |
| 23 |
} |
| 24 |
|
| 25 |
ob_start(); |
| 26 |
imagewebp($this->image, quality: $this->quality); |
| 27 |
|
| 28 |
return strval(ob_get_clean()); |
| 29 |
} |
| 30 |
|
| 31 |
public function getMimeType(): string |
| 32 |
{ |
| 33 |
return 'image/webp'; |
| 34 |
} |
| 35 |
} |