Warning: Undefined array key "orderhash" in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 177
Список полезных функций
(☞ຈل͜ຈ)☞ Главная  Статьи  Загрузчик Домой


Warning: Undefined variable $name in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 209

Warning: Undefined array key "orderhash" in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 224

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 224

Warning: Undefined variable $name in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 224

Warning: Undefined variable $name in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 294
Ok!
Ok!
96
function resizeAndConvertImageWebP(
    $width,
    $height,
    $density,
    $originalFilepath,
    $resizedFilepath) {
  $newWidth = $width * $density;
  $newHeight = $height * $density;

  $image = new Imagick($originalFilepath);
  $origImageDimens = $image->getImageGeometry();
  $origImgWidth = $origImageDimens['width'];
  $origImgHeight = $origImageDimens['height'];

  if($newWidth == 0) {
    $ratioOfHeight = $newHeight / $origImgHeight;
    $newWidth = $origImgWidth * $ratioOfHeight;
  }

  if($newHeight == 0) {
    $ratioOfWidth = $newWidth / $origImgWidth;
    $newHeight = $origImgHeight * $ratioOfWidth;
  }

  $widthRatios = $origImgWidth / $newWidth;
  $heightRatios = $origImgHeight / $newHeight;

  if($widthRatios <= $heightRatios) {
    $cropWidth = $origImgWidth;
    $cropHeight = $newWidth * $widthRatios;
  } else {
    $cropWidth = $newHeight * $heightRatios;
    $cropHeight = $origImgHeight;
  }

  $cropX = ($origImgWidth - $cropWidth) / 2;
  $cropY = ($origImgHeight - $cropHeight) / 2;

  $image->stripImage();
  $image->cropImage($cropWidth, $cropHeight, $cropX, $cropY);
  $image->resizeImage($newWidth, $newHeight, imagick::FILTER_LANCZOS, 0.9);
  $image->setImageFormat('webp');
  $image->setImageAlphaChannel(imagick::ALPHACHANNEL_ACTIVATE);
  $image->setBackgroundColor(new ImagickPixel('transparent'));
  $image->writeImage($resizedFilepath);
}
webp,support,imagemagic140Конвертация картинки в webp в случае, если imageMagic поддрживает