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();
Показать файл
Открыть проект
Примеры использования класса
Защищенные свойства (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
setImageSize()
публичный Метод
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
Описание свойств
$image защищенное свойство
The Image instance of the source image
protected Image,contao $image |
Результат |
Image |
|
$imageSize защищенное свойство
protected ImageSizeModel,contao|object $imageSize |
Результат |
ImageSizeModel | object |
|
$imageSizeItems защищенное свойство
The image size items collection
protected ImageSizeItemModel[],contao|Collection,Contao\Model $imageSizeItems |
Результат |
ImageSizeItemModel[] | Collection |
|