28 lines
685 B
PHP
28 lines
685 B
PHP
<?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);
|
|
}
|
|
}
|