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();
파일 보기 프로젝트 열기: contao/core-bundle 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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