PHP Класс yii\imagine\BaseImage

Do not use BaseImage. Use [[Image]] instead.
С версии: 2.0
Автор: Antonio Ramirez ([email protected])
Автор: Qiang Xue ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$driver the driver to use. This can be either a single driver name or an array of driver names. If the latter, the first available driver will be used.
$thumbnailBackgroundAlpha background alpha (transparency) to use when creating thumbnails in ImageInterface::THUMBNAIL_INSET mode with both width and height specified. Default is solid.
$thumbnailBackgroundColor background color to use when creating thumbnails in ImageInterface::THUMBNAIL_INSET mode with both width and height specified. Default is white.

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

Метод Описание
autorotate ( string | resource | Imagine\Image\ImageInterface $image, string $color = '000000' ) : Imagine\Image\ImageInterface Rotates an image automatically based on EXIF information.
crop ( string | resource | Imagine\Image\ImageInterface $image, integer $width, integer $height, array $start = [0, 0] ) : Imagine\Image\ImageInterface Crops an image.
frame ( string | resource | Imagine\Image\ImageInterface $image, integer $margin = 20, string $color = '666', integer $alpha = 100 ) : Imagine\Image\ImageInterface Adds a frame around of the image. Please note that the image size will increase by $margin x 2.
getImagine ( ) : Imagine\Image\ImagineInterface Returns the Imagine object that supports various image manipulations.
resize ( string | resource | Imagine\Image\ImageInterface $image, integer $width, integer $height, boolean $keepAspectRatio = true, boolean $allowUpscaling = false ) : Imagine\Image\ImageInterface Resizes an image.
setImagine ( Imagine\Image\ImagineInterface $imagine )
text ( string | resource | Imagine\Image\ImageInterface $image, string $text, string $fontFile, array $start = [0, 0], array $fontOptions = [] ) : Imagine\Image\ImageInterface Draws a text string on an existing image.
thumbnail ( string | resource | Imagine\Image\ImageInterface $image, integer $width, integer $height, string $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND ) : Imagine\Image\ImageInterface Creates a thumbnail image.
watermark ( string | resource | Imagine\Image\ImageInterface $image, string | resource | Imagine\Image\ImageInterface $watermarkImage, array $start = [0, 0] ) : Imagine\Image\ImageInterface Adds a watermark to an existing image.

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

Метод Описание
createImagine ( ) : Imagine\Image\ImagineInterface Creates an Imagine object based on the specified [[driver]].
ensureImageInterfaceInstance ( string | resource | Imagine\Image\ImageInterface $image ) : Imagine\Image\ImageInterface Takes either file path or ImageInterface. In case of file path, creates an instance of ImageInterface from it.
getBox ( Imagine\Image\BoxInterface $sourceBox, integer $width, integer $height, boolean $keepAspectRatio = true ) : Imagine\Image\BoxInterface Returns box for an image to be created.
getThumbnailBox ( Imagine\Image\BoxInterface $sourceBox, integer $width, integer $height ) : Imagine\Image\BoxInterface Returns box for a thumbnail to be created. If one of the dimensions is set to null, another one is calculated automatically based on width to height ratio of original image box.
isUpscaling ( Imagine\Image\BoxInterface $sourceBox, Imagine\Image\BoxInterface $destinationBox ) : boolean Checks if upscaling is going to happen

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

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

Rotates an image automatically based on EXIF information.
С версии: 2.1.0
public static autorotate ( string | resource | Imagine\Image\ImageInterface $image, string $color = '000000' ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$color string
Результат Imagine\Image\ImageInterface

createImagine() защищенный статический Метод

Creates an Imagine object based on the specified [[driver]].
protected static createImagine ( ) : Imagine\Image\ImagineInterface
Результат Imagine\Image\ImagineInterface the new `Imagine` object

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

For example, ~~~ $obj->crop('path\to\image.jpg', 200, 200, [5, 5]); $point = new \Imagine\Image\Point(5, 5); $obj->crop('path\to\image.jpg', 200, 200, $point); ~~~
public static crop ( string | resource | Imagine\Image\ImageInterface $image, integer $width, integer $height, array $start = [0, 0] ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$width integer the crop width
$height integer the crop height
$start array the starting point. This must be an array with two elements representing `x` and `y` coordinates.
Результат Imagine\Image\ImageInterface

ensureImageInterfaceInstance() защищенный статический Метод

Takes either file path or ImageInterface. In case of file path, creates an instance of ImageInterface from it.
С версии: 2.1.0
protected static ensureImageInterfaceInstance ( string | resource | Imagine\Image\ImageInterface $image ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface
Результат Imagine\Image\ImageInterface

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

Adds a frame around of the image. Please note that the image size will increase by $margin x 2.
public static frame ( string | resource | Imagine\Image\ImageInterface $image, integer $margin = 20, string $color = '666', integer $alpha = 100 ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$margin integer the frame size to add around the image
$color string the frame color
$alpha integer the alpha value of the frame.
Результат Imagine\Image\ImageInterface

getBox() защищенный статический Метод

If one of the dimensions is set to null, another one is calculated automatically based on width to height ratio of original image box. If both of the dimensions are set then new dimensions are calculated so that image keeps aspect ratio. You can set $keepAspectRatio to false if you want to force fixed width and height.
С версии: 2.1.1
protected static getBox ( Imagine\Image\BoxInterface $sourceBox, integer $width, integer $height, boolean $keepAspectRatio = true ) : Imagine\Image\BoxInterface
$sourceBox Imagine\Image\BoxInterface original image box
$width integer new image width
$height integer new image height
$keepAspectRatio boolean should we keep aspect ratio even if both with and height are set
Результат Imagine\Image\BoxInterface new image box

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

Returns the Imagine object that supports various image manipulations.
public static getImagine ( ) : Imagine\Image\ImagineInterface
Результат Imagine\Image\ImagineInterface the `Imagine` object

getThumbnailBox() защищенный статический Метод

Returns box for a thumbnail to be created. If one of the dimensions is set to null, another one is calculated automatically based on width to height ratio of original image box.
С версии: 2.0.4
protected static getThumbnailBox ( Imagine\Image\BoxInterface $sourceBox, integer $width, integer $height ) : Imagine\Image\BoxInterface
$sourceBox Imagine\Image\BoxInterface original image box
$width integer thumbnail width
$height integer thumbnail height
Результат Imagine\Image\BoxInterface thumbnail box

isUpscaling() защищенный статический Метод

Checks if upscaling is going to happen
protected static isUpscaling ( Imagine\Image\BoxInterface $sourceBox, Imagine\Image\BoxInterface $destinationBox ) : boolean
$sourceBox Imagine\Image\BoxInterface
$destinationBox Imagine\Image\BoxInterface
Результат boolean

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

If one of the dimensions is set to null, another one is calculated automatically based on aspect ratio of original image. If both of the dimensions are set then new dimensions are calculated so that image keeps aspect ratio. You can set $keepAspectRatio to false if you want to force fixed width and height.
С версии: 2.1.1
public static resize ( string | resource | Imagine\Image\ImageInterface $image, integer $width, integer $height, boolean $keepAspectRatio = true, boolean $allowUpscaling = false ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$width integer the width in pixels
$height integer the height in pixels
$keepAspectRatio boolean should the image keep aspect ratio
$allowUpscaling boolean should the image be upscaled if needed
Результат Imagine\Image\ImageInterface

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

public static setImagine ( Imagine\Image\ImagineInterface $imagine )
$imagine Imagine\Image\ImagineInterface the `Imagine` object.

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

Draws a text string on an existing image.
public static text ( string | resource | Imagine\Image\ImageInterface $image, string $text, string $fontFile, array $start = [0, 0], array $fontOptions = [] ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$text string the text to write to the image
$fontFile string the file path or path alias
$start array the starting position of the text. This must be an array with two elements representing `x` and `y` coordinates.
$fontOptions array the font options. The following options may be specified: - color: The font color. Defaults to "fff". - size: The font size. Defaults to 12. - angle: The angle to use to write the text. Defaults to 0.
Результат Imagine\Image\ImageInterface

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

If one of thumbnail dimensions is set to null, another one is calculated automatically based on aspect ratio of original image. Note that calculated thumbnail dimension may vary depending on the source image in this case. If both dimensions are specified, resulting thumbnail would be exactly the width and height specified. How it's achieved depends on the mode. If ImageInterface::THUMBNAIL_OUTBOUND mode is used, which is default, then the thumbnail is scaled so that its smallest side equals the length of the corresponding side in the original image. Any excess outside of the scaled thumbnail’s area will be cropped, and the returned thumbnail will have the exact width and height specified. If thumbnail mode is ImageInterface::THUMBNAIL_INSET, the original image is scaled down so it is fully contained within the thumbnail dimensions. The rest is filled with background that could be configured via [[Image::$thumbnailBackgroundColor]] and [[Image::$thumbnailBackgroundAlpha]].
public static thumbnail ( string | resource | Imagine\Image\ImageInterface $image, integer $width, integer $height, string $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$width integer the width in pixels to create the thumbnail
$height integer the height in pixels to create the thumbnail
$mode string mode of resizing original image to use in case both width and height specified
Результат Imagine\Image\ImageInterface

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

Adds a watermark to an existing image.
public static watermark ( string | resource | Imagine\Image\ImageInterface $image, string | resource | Imagine\Image\ImageInterface $watermarkImage, array $start = [0, 0] ) : Imagine\Image\ImageInterface
$image string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing file path
$watermarkImage string | resource | Imagine\Image\ImageInterface either ImageInterface, resource or a string containing watermark file path
$start array the starting point. This must be an array with two elements representing `x` and `y` coordinates.
Результат Imagine\Image\ImageInterface

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

$driver публичное статическое свойство

the driver to use. This can be either a single driver name or an array of driver names. If the latter, the first available driver will be used.
public static $driver

$thumbnailBackgroundAlpha публичное статическое свойство

background alpha (transparency) to use when creating thumbnails in ImageInterface::THUMBNAIL_INSET mode with both width and height specified. Default is solid.
С версии: 2.0.4
public static $thumbnailBackgroundAlpha

$thumbnailBackgroundColor публичное статическое свойство

background color to use when creating thumbnails in ImageInterface::THUMBNAIL_INSET mode with both width and height specified. Default is white.
С версии: 2.0.4
public static $thumbnailBackgroundColor