HEX
Server: Apache
System: Linux sg241.singhost.net 2.6.32-896.16.1.lve1.4.51.el6.x86_64 #1 SMP Wed Jan 17 13:19:23 EST 2018 x86_64
User: honghock (909)
PHP: 8.0.30
Disabled: passthru,system,shell_exec,show_source,exec,popen,proc_open
Upload Files
File: //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/lib/SGL/ImageTransform/CropStrategy.php
<?php

/**
 * Resize image and crop.
 *
 * @package SGL
 * @author ed209
 * @author Dmitri Lakachauskis <lakiboy83@gmail.com>
 */
class SGL_ImageTransform_CropStrategy extends SGL_ImageTransformStrategy
{
    public function transform()
    {
        // both params must be specified
        if (empty($this->aParams['width']) || empty($this->aParams['height'])) {
            return false;
        }

        $newWidth  = $this->aParams['width'];
        $newHeight = $this->aParams['height'];

        // get size of current image
        list($width, $height) = $this->driver->getImageSize();

        // find sizes
        if ($width != $height) {
            $percentChange = $width > $height
                ? $newHeight / $height
                : $newWidth / $width;
            $scaleWidth  = round($width * $percentChange);
            $scaleHeight = round($height * $percentChange);

            $this->driver->scaleByXY($scaleWidth, $scaleHeight);
        } else {
            if ($newWidth > $newHeight) {
                $scaleSide = $newWidth;
                $method    = 'scaleByX';
            } else {
                $scaleSide = $newHeight;
                $method    = 'scaleByY';
            }
            $this->driver->{$method}($scaleSide);
        }

        // get size of current (transformed) image
        $width  = $this->driver->getCurrentImageWidth();
        $height = $this->driver->getCurrentImageHeight();

        // center
        $newX = round(($width - $newWidth) / 2);
        $newY = round(($height - $newHeight) / 2);

        // crop
        $ret = $this->driver->crop($newWidth, $newHeight, $newX, $newY);
        return $ret;
    }
}

?>