Source of file ImageCrop.php

Size: 2,051 Bytes - Last Modified: 2016-05-18T03:08:27+02:00

buildproject/core/module_system/system/imageplugins/ImageCrop.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
<?php
/*"******************************************************************************************************
*   (c) 2013-2016 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$	                                            *
********************************************************************************************************/

namespace Kajona\System\System\Imageplugins;


/**
 * Implements an image scaling operation.
 * The scaling retains the aspect ration.
 */
class ImageCrop extends ImageAbstractOperation {
    private $intX;
    private $intY;
    private $intWidth;
    private $intHeight;

    /**
     * @param int $intX
     * @param int $intY
     * @param int $intWidth
     * @param int $intHeight
     */
    public function __construct($intX, $intY, $intWidth, $intHeight) {
        $this->intX = $intX < 0 ? 0 : (int)$intX;
        $this->intY = $intY < 0 ? 0 : (int)$intY;
        $this->intWidth = (int)$intWidth;
        $this->intHeight = (int)$intHeight;
    }

    /**
     * @param resource &$objResource
     *
     * @return bool
     */
    public function render(&$objResource) {
        // Crop the image
        $objCroppedResource = $this->createImageResource($this->intWidth, $this->intHeight);
        $bitSuccess = imagecopy($objCroppedResource, $objResource,
            0, 0, // Destination X, Y
            $this->intX, $this->intY, // Source X, Y
            $this->intWidth, $this->intHeight);

        if (!$bitSuccess) {
            imagedestroy($objCroppedResource);
            return false;
        }

        $objResource = $objCroppedResource;
        return true;
    }

    /**
     * @return array
     */
    public function getCacheIdValues() {
        return array($this->intX, $this->intY, $this->intWidth, $this->intHeight);
    }
}