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();
ファイルを表示
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
setImageSize()
public method
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
Property Details
$image protected_oe property
The Image instance of the source image
protected Image,contao $image |
return |
Image |
|
$imageSize protected_oe property
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 |
|