PHP Class Craft\ImagerService

Inheritance: extends craft\BaseApplicationComponent
Mostrar archivo Open project: aelvan/Imager-Craft Class Usage Examples

Public Properties

Property Type Description
$compositeKeyTranslate translate dictionary for composite modes. set in constructor if driver is imagick.
$configModel
$craftPositonTranslate translate dictionary for translating crafts built in position constants into relative format (width/height offset)
$ditherKeyTranslate translate dictionary for dither method
$filterKeyTranslate translate dictionary for resize method
$imageDriver
$imageInstance
$imagineInstance
$interlaceKeyTranslate translate dictionary for interlace method
$invalidatePaths
$taskCreated
$transformKeyTranslate translate dictionary for translating transform keys into filename markers

Public Methods

Method Description
__construct ( ) Constructor
deleteImageTransformCaches ( ) Clear all image transforms caches
deleteRemoteImageCaches ( ) Clear all remote image caches
executeOptimize ( $command, $file = '' ) Executes a shell command
fixSlashes ( $str, boolean | false $removeInitial = false, boolean | false $removeTrailing = false ) : mixed | string Fixes slashes in path
getCropSize ( Imagine\Image\Box $originalSize, $transform ) : Imagine\Image\Box Creates the destination crop size box
getResizeSize ( Imagine\Image\Box $originalSize, $transform ) : Imagine\Image\Box Creates the resize size box
getSetting ( $name, $transform = null ) : mixed Gets a plugin setting
hasSupportForWebP ( ) : boolean Checks for webp support in image driver
makeTask ( string $taskName, array $paths ) Registers a Task with Craft, taking into account if there is already one pending
postOptimize ( $type, $file ) Set up optimization
removeTransformsForAsset ( craft\AssetFileModel $asset ) Remove transforms for a given asset
runJpegoptim ( $file ) Run jpegoptim optimization
runJpegtran ( $file ) Run jpegtran optimization
runMozjpeg ( $file ) Run mozjpeg optimization
runOptipng ( $file ) Run optipng optimization
runTinyPng ( $file ) Runs TinyPNG optimization
transformImage ( craft\AssetFileModel | string $image, Array $transform, Array $transformDefaults, Array $configOverrides ) : craft\Image Do an image transform

Private Methods

Method Description
_applyBackgroundColor ( Imagine\Image\ImageInterface &$imageInstance, $bgColor ) Apply background color to image when converting from transparent to non-transparent
_applyCustomFilter ( $imagick, $filterName ) Applies a custom predefined filter to image
_applyImageEffects ( $imageInstance, $effects ) Apply effects array to image instance
_applyLetterbox ( Imagine\Image\ImageInterface &$imageInstance, $transform ) Apply letterbox to image
_applyWatermark ( $imageInstance, $watermark ) Apply watermark to image
_colorBlend ( $imagickInstance, $color, integer $alpha = 1, integer $composite_flag = Imagick::COMPOSITE_COLORIZE ) Color blend filter, more advanced version of colorize.
_createImagineInstance ( ) Creates the Imagine instance depending on the image driver
_createTargetFilename ( string $filename, string $extension, $transform ) : string Creates the target filename
_createTransformFilestring ( $transform ) : string Creates additional file string that is appended to filename
_enforceMaxSize ( $width, $height, $originalSize, $maintainAspect, $zoomFactor = 1 ) : array Enforces a max size if allowUpscale is false
_getCropPoint ( Imagine\Image\Box $resizeSize, Imagine\Image\Box $cropSize, $transform ) : Imagine\Image\Point Gets crop point
_getCropZoomFactor ( $transform ) : float | integer Get the crop zoom factor
_getFilterMethod ( $transform ) : string Returns the filter method for resize operations
_getSaveOptions ( $extension, $transform ) : array Get the save options based on extension and transform
_getTransformedImage ( Imager_ImagePathsModel $paths, Array $transform ) : Imager_ImageModel Loads an image from a file system path, do transform, return transformed image as an Imager_ImageModel
_moveArrayKeyToPos ( $key, $pos, $arr ) : array Moves a named key in an associative array to a given position
_normalizeTransform ( $transform, $paths = null ) : mixed Normalize transform object and values
_saveAsWebp ( $imageInstance, $path, $sourceExtension, $saveOptions ) Saves image as webp
_saveTemporaryFile ( $imageInstance, $sourceExtension ) : string Save temporary file and return filename
_triggerTasksNow ( ) Method that triggers any pending tasks immediately.
_vignette ( $imagickInstance, string $color1 = 'none', string $color2 = 'black', float $crop_factor = 1.5 ) Create a vignette

Method Details

__construct() public method

Constructor
public __construct ( )

deleteImageTransformCaches() public method

Clear all image transforms caches

deleteRemoteImageCaches() public method

Clear all remote image caches

executeOptimize() public method

Executes a shell command
public executeOptimize ( $command, $file = '' )
$command

fixSlashes() static public method

Fixes slashes in path
static public fixSlashes ( $str, boolean | false $removeInitial = false, boolean | false $removeTrailing = false ) : mixed | string
$str
$removeInitial boolean | false
$removeTrailing boolean | false
return mixed | string

getCropSize() public method

Creates the destination crop size box
public getCropSize ( Imagine\Image\Box $originalSize, $transform ) : Imagine\Image\Box
$originalSize Imagine\Image\Box
$transform
return Imagine\Image\Box

getResizeSize() public method

Creates the resize size box
public getResizeSize ( Imagine\Image\Box $originalSize, $transform ) : Imagine\Image\Box
$originalSize Imagine\Image\Box
$transform
return Imagine\Image\Box

getSetting() public method

Gets a plugin setting
Author: André Elvan
public getSetting ( $name, $transform = null ) : mixed
$name String Setting name
return mixed Setting value

hasSupportForWebP() public method

Checks for webp support in image driver
public hasSupportForWebP ( ) : boolean
return boolean

makeTask() public method

Registers a Task with Craft, taking into account if there is already one pending
public makeTask ( string $taskName, array $paths )
$taskName string The name of the Task you want to register
$paths array An array of paths that should go in that Tasks settings

postOptimize() public method

Set up optimization
public postOptimize ( $type, $file )
$type
$file

removeTransformsForAsset() public method

Remove transforms for a given asset
public removeTransformsForAsset ( craft\AssetFileModel $asset )
$asset craft\AssetFileModel

runJpegoptim() public method

Run jpegoptim optimization
public runJpegoptim ( $file )
$file

runJpegtran() public method

Run jpegtran optimization
public runJpegtran ( $file )
$file

runMozjpeg() public method

Run mozjpeg optimization
public runMozjpeg ( $file )
$file

runOptipng() public method

Run optipng optimization
public runOptipng ( $file )
$file

runTinyPng() public method

Runs TinyPNG optimization
public runTinyPng ( $file )
$file

transformImage() public method

Do an image transform
public transformImage ( craft\AssetFileModel | string $image, Array $transform, Array $transformDefaults, Array $configOverrides ) : craft\Image
$image craft\AssetFileModel | string
$transform Array
$transformDefaults Array
$configOverrides Array
return craft\Image

Property Details

$compositeKeyTranslate public_oe static_oe property

translate dictionary for composite modes. set in constructor if driver is imagick.
public static $compositeKeyTranslate

$configModel public_oe property

public $configModel

$craftPositonTranslate public_oe static_oe property

translate dictionary for translating crafts built in position constants into relative format (width/height offset)
public static $craftPositonTranslate

$ditherKeyTranslate public_oe static_oe property

translate dictionary for dither method
public static $ditherKeyTranslate

$filterKeyTranslate public_oe static_oe property

translate dictionary for resize method
public static $filterKeyTranslate

$imageDriver public_oe property

public $imageDriver

$imageInstance public_oe property

public $imageInstance

$imagineInstance public_oe property

public $imagineInstance

$interlaceKeyTranslate public_oe static_oe property

translate dictionary for interlace method
public static $interlaceKeyTranslate

$invalidatePaths public_oe property

public $invalidatePaths

$taskCreated public_oe property

public $taskCreated

$transformKeyTranslate public_oe static_oe property

translate dictionary for translating transform keys into filename markers
public static $transformKeyTranslate