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

Image manipulation service. More...

Public Member Functions

 __construct (ImagineInterface $imagine, Config $config)
 Constructor. More...
 
 resize ($source, $destination=null, array $params=[])
 Crop and resize an image. More...
 
 normalizeResizeParameters ($width, $height, array $params=[])
 Calculate the parameters for resizing an image. More...
 

Public Attributes

const JPEG_QUALITY = 75
 

Protected Member Functions

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

Detailed Description

Image manipulation service.

Since
2.3 private

Definition at line 17 of file ImageService.php.

Constructor & Destructor Documentation

Elgg\ImageService::__construct ( ImagineInterface  $imagine,
Config  $config 
)

Constructor.

Parameters
ImagineInterface$imagineImagine interface
Config$configElgg config

Definition at line 37 of file ImageService.php.

Member Function Documentation

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 212 of file ImageService.php.

Elgg\ImageService::normalizeResizeParameters (   $width,
  $height,
array  $params = [] 
)

Calculate the parameters for resizing an image.

Parameters
int$widthNatural width of the image
int$heightNatural height of the image
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

Definition at line 127 of file ImageService.php.

Elgg\ImageService::resize (   $source,
  $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 66 of file ImageService.php.

Member Data Documentation

const Elgg\ImageService::JPEG_QUALITY = 75

Definition at line 19 of file ImageService.php.


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