Contao\Image::get PHP Method

get() public static method

Resize an image and store the resized version in the image target folder
Deprecation: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static get ( string $image, integer $width, integer $height, string $mode = '', string $target = null, boolean $force = false ) : string | null
$image string The image path
$width integer The target width
$height integer The target height
$mode string The resize mode
$target string An optional target path
$force boolean Override existing target images
return string | null The path of the resized image or null
    public static function get($image, $width, $height, $mode = '', $target = null, $force = false)
    {
        @trigger_error('Using Image::get() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED);
        if ($image == '') {
            return null;
        }
        try {
            $imageObj = static::create($image, array($width, $height, $mode));
            $imageObj->setTargetPath($target);
            $imageObj->setForceOverride($force);
            if (($path = $imageObj->executeResize()->getResizedPath()) != '') {
                return $path;
            }
        } catch (\Exception $e) {
            \System::log('Image "' . $image . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
        }
        return null;
    }

Usage Example

Example #1
0
 public function generateLabel($row, $label)
 {
     $sReturn = '';
     $objFile = \FilesModel::findByPk(deserialize($row['logo']));
     if ($objFile->path != '') {
         $sReturn = '<figure style="float: left; margin-right: 1em;"><img src="' . Image::get($objFile->path, 80, 50, 'center_center') . '"></figure>';
     }
     $sReturn .= '<div>' . $label . '</div>';
     return $sReturn;
 }
All Usage Examples Of Contao\Image::get