PHP Класс Contao\Image

The class resizes images and stores them in the assets/images folder. Usage: $imageObj = new Image(new File('example.jpg')); $src = $imageObj->setTargetWidth(640) ->setTargetHeight(480) ->setResizeMode('center_center') ->executeResize() ->getResizedPath();
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$fileObj contao\File The File instance of the original image
$forceOverride boolean Override an existing target
$importantPart array Important part settings
$resizeMode string The resize mode (defaults to crop for BC)
$resizedPath string The resized image path
$targetHeight integer The target height
$targetPath string The target path
$targetWidth integer The target width
$zoomLevel integer Zoom level (between 0 and 100)

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

Метод Описание
__construct ( contao\File $file ) Create a new object to handle an image
computeResize ( ) : array Calculate the resize coordinates
create ( string | contao\File $image, array | integer $size = null ) : static Create an image instance from the given image path and size
executeResize ( ) Resize the image
get ( string $image, integer $width, integer $height, string $mode = '', string $target = null, boolean $force = false ) : string | null Resize an image and store the resized version in the image target folder
getCacheName ( ) : string Get the cache name
getForceOverride ( ) : boolean Get force override setting
getHtml ( string $src, string $alt = '', string $attributes = '' ) : string Generate an image tag and return it as string
getImportantPart ( ) : array Get the important part settings
getOriginalPath ( ) : string Get the path of the original image
getPath ( string $src ) : string Get the relative path to an image
getPixelValue ( string $size ) : integer Convert sizes like 2em, 10cm or 12pt to pixels
getResizeMode ( ) : string Get the resize mode
getResizedPath ( ) : string Get the path of the resized image
getTargetHeight ( ) : integer Get the target height
getTargetPath ( ) : string Get the target path
getTargetWidth ( ) : integer Get the target width
getZoomLevel ( ) : integer Get the zoom level
resize ( string $image, integer $width, integer $height, string $mode = '' ) : boolean Resize or crop an image and replace the original with the resized version
setForceOverride ( boolean $forceOverride ) Override the target image
setImportantPart ( array $importantPart = null ) Set the important part settings
setResizeMode ( string $resizeMode ) Set the resize mode
setTargetHeight ( integer $targetHeight ) Set the target height
setTargetPath ( string $targetPath ) Set the target path
setTargetWidth ( integer $targetWidth ) Set the target width
setZoomLevel ( integer $zoomLevel ) Set the zoom level

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

Метод Описание
prepareImage ( ) : Contao\Image\Image Prepare image object.
prepareImportantPart ( ) : Contao\Image\ImportantPart Prepare important part object.
prepareResizeConfig ( ) : Contao\Image\ResizeConfiguration Prepare resize configuration object.

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

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

Create a new object to handle an image
Устаревший: 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

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

Calculate the resize coordinates
public computeResize ( ) : array
Результат array The resize coordinates (width, height, target_x, target_y, target_width, target_height)

create() публичный статический Метод

Create an image instance from the given image path and size
Устаревший: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static create ( string | contao\File $image, array | integer $size = null ) : static
$image 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 image instance

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

Resize the image
public executeResize ( )

get() публичный статический Метод

Resize an image and store the resized version in the image target folder
Устаревший: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static get ( string $image, integer $width, integer $height, string $mode = '', string $target = null, boolean $force = false ) : string | null
$image string The image path
$width integer The target width
$height integer The target height
$mode string The resize mode
$target string An optional target path
$force boolean Override existing target images
Результат string | null The path of the resized image or null

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

Get the cache name
public getCacheName ( ) : string
Результат string The cache name

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

Get force override setting
public getForceOverride ( ) : boolean
Результат boolean True if the target image will be overridden

getHtml() публичный статический Метод

Generate an image tag and return it as string
public static getHtml ( string $src, string $alt = '', string $attributes = '' ) : string
$src string The image path
$alt string An optional alt attribute
$attributes string A string of other attributes
Результат string The image HTML tag

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

Get the important part settings
public getImportantPart ( ) : array
Результат array The settings array

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

Get the path of the original image
public getOriginalPath ( ) : string
Результат string The path of the original image

getPath() публичный статический Метод

Get the relative path to an image
public static getPath ( string $src ) : string
$src string The image name or path
Результат string The relative path

getPixelValue() публичный статический Метод

Convert sizes like 2em, 10cm or 12pt to pixels
Устаревший: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static getPixelValue ( string $size ) : integer
$size string The size string
Результат integer The pixel value

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

Get the resize mode
public getResizeMode ( ) : string
Результат string The resize mode

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

Get the path of the resized image
public getResizedPath ( ) : string
Результат string The path of the resized image

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

Get the target height
public getTargetHeight ( ) : integer
Результат integer The target height

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

Get the target path
public getTargetPath ( ) : string
Результат string The target path

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

Get the target width
public getTargetWidth ( ) : integer
Результат integer The target width

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

Get the zoom level
public getZoomLevel ( ) : integer
Результат integer The zoom level

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

Prepare image object.
protected prepareImage ( ) : Contao\Image\Image
Результат Contao\Image\Image

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

Prepare important part object.
protected prepareImportantPart ( ) : Contao\Image\ImportantPart
Результат Contao\Image\ImportantPart

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

Prepare resize configuration object.
protected prepareResizeConfig ( ) : Contao\Image\ResizeConfiguration
Результат Contao\Image\ResizeConfiguration

resize() публичный статический Метод

Resize or crop an image and replace the original with the resized version
Устаревший: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static resize ( string $image, integer $width, integer $height, string $mode = '' ) : boolean
$image string The image path
$width integer The target width
$height integer The target height
$mode string The resize mode
Результат boolean True if the image could be resized successfully

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

Override the target image
public setForceOverride ( boolean $forceOverride )
$forceOverride boolean True to override the target image

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

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

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

Set the resize mode
public setResizeMode ( string $resizeMode )
$resizeMode string The resize mode

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

Set the target height
public setTargetHeight ( integer $targetHeight )
$targetHeight integer The target height

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

Set the target path
public setTargetPath ( string $targetPath )
$targetPath string The target path

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

Set the target width
public setTargetWidth ( integer $targetWidth )
$targetWidth integer The target width

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

Set the zoom level
public setZoomLevel ( integer $zoomLevel )
$zoomLevel integer The zoom level

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

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

The File instance of the original image
protected File,contao $fileObj
Результат contao\File

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

Override an existing target
protected bool $forceOverride
Результат boolean

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

Important part settings
protected array $importantPart
Результат array

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

The resize mode (defaults to crop for BC)
protected string $resizeMode
Результат string

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

The resized image path
protected string $resizedPath
Результат string

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

The target height
protected int $targetHeight
Результат integer

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

The target path
protected string $targetPath
Результат string

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

The target width
protected int $targetWidth
Результат integer

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

Zoom level (between 0 and 100)
protected int $zoomLevel
Результат integer