PHP Class Contao\Picture

The class resizes images and prepares data for the element. Usage: $picture = new Picture(new File('example.jpg')); $data = $picture ->setImportantPart(array('x'=>10, 'y'=>10, 'width'=>100, 'height'=>100)) ->setImageSize(ImageSizeModel::findByPk(1)) ->setImageSizeItems(ImageSizeItemModel::findVisibleByPid(1, array('order'=>'sorting ASC'))) ->getTemplateData() ; Shortcut $data = Picture::create('example.jpg', 1)->getTemplateData(); $data = Picture::create('example.jpg', array(100, 100, 'crop'))->getTemplateData();
Deprecation: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.picture_factory service instead.
ファイルを表示 Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$image Image The Image instance of the source image
$imageSize ImageSizeModel | object The image size
$imageSizeItems ImageSizeItemModel[] | Collection The image size items collection

Public Methods

Method Description
__construct ( contao\File $file ) Create a new object to handle a picture element
create ( string | contao\File $file, array | integer $size = null ) : static Create a picture instance from the given image path and size
getTemplateData ( ) : array Get the picture element definition array
setImageSize ( ImageSizeModel | object $imageSize ) Set the image size
setImageSizeItems ( ImageSizeItemModel[] | Collection $imageSizeItems ) Set the image size items collection
setImportantPart ( array $importantPart = null ) Set the important part settings

Protected Methods

Method Description
getConfigurationItem ( Model | object $imageSize ) : Contao\Image\PictureConfigurationItem Get the config for one picture source element

Method Details

__construct() public method

Create a new object to handle a picture element
public __construct ( contao\File $file )
$file contao\File A file instance of the source image

create() public static method

Create a picture instance from the given image path and size
public static create ( string | contao\File $file, array | integer $size = null ) : static
$file string | contao\File The image path or File instance
$size array | integer The image size as array (width, height, resize mode) or an tl_image_size ID
return static The created picture instance

getConfigurationItem() protected method

Get the config for one picture source element
protected getConfigurationItem ( Model | object $imageSize ) : Contao\Image\PictureConfigurationItem
$imageSize Model | object The image size or image size item model
return Contao\Image\PictureConfigurationItem

getTemplateData() public method

Get the picture element definition array
public getTemplateData ( ) : array
return array The picture element definition

setImageSize() public method

Set the image size
public setImageSize ( ImageSizeModel | object $imageSize )
$imageSize ImageSizeModel | object The image size

setImageSizeItems() public method

Set the image size items collection
public setImageSizeItems ( ImageSizeItemModel[] | Collection $imageSizeItems )
$imageSizeItems ImageSizeItemModel[] | Collection The image size items collection

setImportantPart() public method

Set the important part settings
public setImportantPart ( array $importantPart = null )
$importantPart array The settings array

Property Details

$image protected_oe property

The Image instance of the source image
protected Image,contao $image
return Image

$imageSize protected_oe property

The image size
protected ImageSizeModel,contao|object $imageSize
return ImageSizeModel | object

$imageSizeItems protected_oe property

The image size items collection
protected ImageSizeItemModel[],contao|Collection,Contao\Model $imageSizeItems
return ImageSizeItemModel[] | Collection