PHP Класс 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();
Устаревший: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.picture_factory service instead.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$image Image The Image instance of the source image
$imageSize ImageSizeModel | object The image size
$imageSizeItems ImageSizeItemModel[] | Collection The image size items collection

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
getConfigurationItem ( Model | object $imageSize ) : Contao\Image\PictureConfigurationItem Get the config for one picture source element

Описание методов

__construct() публичный Метод

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() публичный статический Метод

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
Результат static The created picture instance

getConfigurationItem() защищенный Метод

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
Результат Contao\Image\PictureConfigurationItem

getTemplateData() публичный Метод

Get the picture element definition array
public getTemplateData ( ) : array
Результат array The picture element definition

setImageSize() публичный Метод

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

setImageSizeItems() публичный Метод

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

setImportantPart() публичный Метод

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

Описание свойств

$image защищенное свойство

The Image instance of the source image
protected Image,contao $image
Результат Image

$imageSize защищенное свойство

The image size
protected ImageSizeModel,contao|object $imageSize
Результат ImageSizeModel | object

$imageSizeItems защищенное свойство

The image size items collection
protected ImageSizeItemModel[],contao|Collection,Contao\Model $imageSizeItems
Результат ImageSizeItemModel[] | Collection