Contao\FileUpload::resizeUploadedImage PHP Method

resizeUploadedImage() protected method

Resize an uploaded image if neccessary
protected resizeUploadedImage ( string $strImage ) : boolean
$strImage string
return boolean
    protected function resizeUploadedImage($strImage)
    {
        // The feature is disabled
        if (\Config::get('imageWidth') < 1 && \Config::get('imageHeight') < 1) {
            return false;
        }
        $objFile = new \File($strImage);
        // Not an image
        if (!$objFile->isSvgImage && !$objFile->isGdImage) {
            return false;
        }
        $arrImageSize = $objFile->imageSize;
        // The image is too big to be handled by the GD library
        if ($objFile->isGdImage && ($arrImageSize[0] > \Config::get('gdMaxImgWidth') || $arrImageSize[1] > \Config::get('gdMaxImgHeight'))) {
            \Message::addInfo(sprintf($GLOBALS['TL_LANG']['MSC']['fileExceeds'], $objFile->basename));
            $this->log('File "' . $strImage . '" is too big to be resized automatically', __METHOD__, TL_FILES);
            return false;
        }
        $blnResize = false;
        // The image exceeds the maximum image width
        if ($arrImageSize[0] > \Config::get('imageWidth')) {
            $blnResize = true;
            $intWidth = \Config::get('imageWidth');
            $intHeight = round(\Config::get('imageWidth') * $arrImageSize[1] / $arrImageSize[0]);
            $arrImageSize = array($intWidth, $intHeight);
        }
        // The image exceeds the maximum image height
        if ($arrImageSize[1] > \Config::get('imageHeight')) {
            $blnResize = true;
            $intWidth = round(\Config::get('imageHeight') * $arrImageSize[0] / $arrImageSize[1]);
            $intHeight = \Config::get('imageHeight');
            $arrImageSize = array($intWidth, $intHeight);
        }
        // Resized successfully
        if ($blnResize) {
            \System::getContainer()->get('contao.image.image_factory')->create(TL_ROOT . '/' . $strImage, array($arrImageSize[0], $arrImageSize[1]), TL_ROOT . '/' . $strImage);
            \Message::addInfo(sprintf($GLOBALS['TL_LANG']['MSC']['fileResized'], $objFile->basename));
            $this->log('File "' . $strImage . '" was scaled down to the maximum dimensions', __METHOD__, TL_FILES);
            $this->blnHasResized = true;
            return true;
        }
        return false;
    }