Soshot/app/Utils/ConvertIco.php

29 lines
685 B
PHP
Raw Normal View History

2023-06-21 11:42:36 +02:00
<?php
namespace App\Utils;
use Imagick;
class ConvertIco {
static function convert($demande, $size) {
rename($demande->requestImg, $demande->requestImg . '.ico');
$icoFile = $demande->requestImg . '.ico';
if (empty(Imagick::queryFormats("ICO"))) {
throw new \Exception('Unsupported format');
}
$im = new Imagick($icoFile);
$targetWidth = $targetHeight = $size;
if ($im->getImageWidth() <> $targetWidth || $im->getImageHeight() <> $targetHeight) {
$im->cropThumbnailImage($targetWidth, $targetHeight);
}
$im->writeImage($demande->requestImg);
unlink($icoFile);
}
}