Contao\Image::__construct PHP Method

__construct() public method

Create a new object to handle an image
Deprecation: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public __construct ( contao\File $file )
$file contao\File A file instance of the original image
    public function __construct(File $file)
    {
        @trigger_error('Using new Contao\\Image() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED);
        // Check whether the file exists
        if (!$file->exists()) {
            // Handle public bundle resources
            if (file_exists(TL_ROOT . '/web/' . $file->path)) {
                $file = new \File('web/' . $file->path);
            } else {
                throw new \InvalidArgumentException('Image "' . $file->path . '" could not be found');
            }
        }
        $this->fileObj = $file;
        $arrAllowedTypes = \StringUtil::trimsplit(',', strtolower(\Config::get('validImageTypes')));
        // Check the file type
        if (!in_array($this->fileObj->extension, $arrAllowedTypes)) {
            throw new \InvalidArgumentException('Image type "' . $this->fileObj->extension . '" was not allowed to be processed');
        }
    }