Elgg  Version master
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Elgg\ImageService Class Reference

Image manipulation service. More...

Public Member Functions

 __construct (protected Config $config, protected MimeTypeService $mimetype)
 Constructor. More...
 
 resize (string $source, string $destination=null, array $params=[])
 Crop and resize an image. More...
 
 fixOrientation ($filename)
 If needed the image will be rotated based on orientation information. More...
 
 normalizeResizeParameters (string $source, array $params=[])
 Calculate the parameters for resizing an image. More...
 
 hasWebPSupport ()
 Checks if imagine has WebP support. More...
 

Public Attributes

const JPEG_QUALITY = 75
 
const WEBP_QUALITY = 75
 

Protected Member Functions

 getFileFormat ($filename, $params)
 Determine the image file format, this is needed for correct resizing. More...
 

Protected Attributes

 $imagine
 

Detailed Description

Image manipulation service.

Since
2.3

Definition at line 21 of file ImageService.php.

Constructor & Destructor Documentation

Elgg\ImageService::__construct ( protected Config  $config,
protected MimeTypeService  $mimetype 
)

Constructor.

Parameters
Config$configElgg config
MimeTypeService$mimetypeMimeType service

Definition at line 39 of file ImageService.php.

Member Function Documentation

Elgg\ImageService::fixOrientation (   $filename)

If needed the image will be rotated based on orientation information.

Parameters
string$filenamePath to image
Returns
bool

Definition at line 146 of file ImageService.php.

Elgg\ImageService::getFileFormat (   $filename,
  $params 
)
protected

Determine the image file format, this is needed for correct resizing.

Parameters
string$filenamepath to the file
array$paramsarray of resizing params (can contain 'format' to set save format)
See also
https://github.com/Elgg/Elgg/issues/10686
Returns
void|string

Definition at line 271 of file ImageService.php.

Elgg\ImageService::hasWebPSupport ( )

Checks if imagine has WebP support.

Returns
bool

Definition at line 302 of file ImageService.php.

Elgg\ImageService::normalizeResizeParameters ( string  $source,
array  $params = [] 
)

Calculate the parameters for resizing an image.

Parameters
string$sourceThe source location of the image to validate the parameters for
array$paramsResize parameters
  • 'w' maximum width of the resized image
  • 'h' maximum height of the resized image
  • 'upscale' allow upscaling
  • 'square' constrain to a square
  • 'x1', 'y1', 'x2', 'y2' cropping coordinates
Returns
array
Exceptions
InvalidArgumentException
RangeException

Definition at line 183 of file ImageService.php.

Elgg\ImageService::resize ( string  $source,
string  $destination = null,
array  $params = [] 
)

Crop and resize an image.

Parameters
string$sourcePath to source image
string$destinationPath to destination If not set, will modify the source image
array$paramsAn array of cropping/resizing parameters
  • INT 'w' represents the width of the new image With upscaling disabled, this is the maximum width of the new image (in case the source image is smaller than the expected width)
  • INT 'h' represents the height of the new image With upscaling disabled, this is the maximum height
  • INT 'x1', 'y1', 'x2', 'y2' represent optional cropping coordinates. The source image will first be cropped to these coordinates, and then resized to match width/height parameters
  • BOOL 'square' - square images will fill the bounding box (width x height). In Imagine's terms, this equates to OUTBOUND mode
  • BOOL 'upscale' - if enabled, smaller images will be upscaled to fit the bounding box.
Returns
bool

Definition at line 84 of file ImageService.php.

Member Data Documentation

Elgg\ImageService::$imagine
protected

Definition at line 31 of file ImageService.php.

const Elgg\ImageService::JPEG_QUALITY = 75

Definition at line 25 of file ImageService.php.

const Elgg\ImageService::WEBP_QUALITY = 75

Definition at line 26 of file ImageService.php.


The documentation for this class was generated from the following file: