‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Imaging\GraphicalFunctions Class Reference

Public Member Functions

 __construct ()
 
string v5_sharpen ($factor)
 
string v5_blur ($factor)
 
string randomName ()
 
array null imageMagickConvert ($imagefile, $targetFileExtension='', $w='', $h='', $params='', $frame='', $options=[], $mustCreate=false)
 
 crop (string $imageFile, string $targetFileExtension, string $cropInformation, array $options)
 
 mask (string $inputFile, string $outputFile, string $maskImage, string $maskBackgroundImage, string $params, array $options)
 
array null getImageDimensions ($imageFile)
 
array null imageMagickIdentify ($imagefile)
 
string imageMagickExec ($input, $output, $params, $frame=0)
 
string combineExec ($input, $overlay, $mask, $output)
 
string gif_or_jpg ($type, $w, $h)
 
 setImageFileExt (array $imageFileExt)
 
 getImageFileExt ()
 

Public Attributes

bool $addFrameSelection = true
 
array $cmds
 
string $filenamePrefix = ''
 
string $imageMagickConvert_forceFileNameBody = ''
 
bool $dontCheckForExistingTempFile = false
 
string $alternativeOutputKey = ''
 
array $IM_commands = array( )
 
string $scalecmd = '-auto-orient -geometry'
 

Protected Member Functions

string null executeIdentifyCommandForImageFile (string $imageFile)
 
 modifyImageMagickStripProfileParameters (string $parameters, array $options)
 
 getColorspaceFromConfiguration ()
 

Protected Attributes

string $colorspace = 'RGB'
 
array $allowedColorSpaceNames
 
array $imageFileExt = ['gif', 'jpg', 'jpeg', 'png', 'tif', 'bmp', 'tga', 'pcx', 'ai', 'pdf', 'webp']
 
array $webImageExt = ['gif', 'jpg', 'jpeg', 'png']
 
bool $processorEnabled
 
bool $mayScaleUp = true
 
string $im5fx_blurSteps = '1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'
 
string $im5fx_sharpenSteps = '1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'
 
int $pixelLimitGif = 10000
 
int $jpegQuality = 85
 

Detailed Description

Standard graphical functions

Class contains a bunch of cool functions for manipulating graphics with GDlib/Freetype and ImageMagick. VERY OFTEN used with gifbuilder that uses this class and provides a TypoScript API to using these functions

Definition at line 32 of file GraphicalFunctions.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::__construct ( )

Reads configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] and sets some values in internal variables.

Definition at line 161 of file GraphicalFunctions.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\getColorspaceFromConfiguration(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\v5_sharpen().

Member Function Documentation

◆ combineExec()

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::combineExec (   $input,
  $overlay,
  $mask,
  $output 
)

Executes an ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to) Can be used for many things, mostly scaling and effects.

Parameters
string$input‪The relative to public web path image filepath, bottom file
string$overlay‪The relative to public web path image filepath, overlay file (top)
string$mask‪The relative to public web path image filepath, the mask file (grayscale)
string$output‪The relative to public web path image filepath, output filename (written to)
Returns
‪string

Definition at line 539 of file GraphicalFunctions.php.

References $output, TYPO3\CMS\Core\Utility\CommandUtility\exec(), TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions(), TYPO3\CMS\Core\Imaging\ImageMagickFile\fromFilePath(), TYPO3\CMS\Core\Utility\CommandUtility\imageMagickCommand(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickExec(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\randomName().

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\mask().

◆ crop()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::crop ( string  $imageFile,
string  $targetFileExtension,
string  $cropInformation,
array  $options 
)

This only crops the image, but does not take other "options" such as maxWidth etc. not into account. Do not use standalone if you don't know what you are doing.

until API is finalized

Definition at line 375 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert().

◆ executeIdentifyCommandForImageFile()

string null TYPO3\CMS\Core\Imaging\GraphicalFunctions::executeIdentifyCommandForImageFile ( string  $imageFile)
protected

Internal function to execute an IM command fetching information on an image

Parameters
string$imageFile‪the absolute path to the image
Returns
‪string|null the raw result of the identify command.

Definition at line 484 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Utility\CommandUtility\exec(), TYPO3\CMS\Core\Imaging\ImageMagickFile\fromFilePath(), and TYPO3\CMS\Core\Utility\CommandUtility\imageMagickCommand().

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickIdentify().

◆ getColorspaceFromConfiguration()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::getColorspaceFromConfiguration ( )
protected

Returns the recommended colorspace for a processor or the one set in the configuration

Definition at line 627 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Imaging\GraphicalFunctions\$colorspace, and $GLOBALS.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\__construct().

◆ getImageDimensions()

array null TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions (   $imageFile)

Gets the input image dimensions.

Parameters
string$imageFile‪The absolute image filepath
Returns
‪array|null Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the absolute filepath.
See also
imageMagickConvert()
‪\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getImgResource()

Definition at line 429 of file GraphicalFunctions.php.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert().

◆ getImageFileExt()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageFileExt ( )

Not part of TYPO3 Core API.

Definition at line 618 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Imaging\GraphicalFunctions\$imageFileExt.

◆ gif_or_jpg()

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::gif_or_jpg (   $type,
  $w,
  $h 
)

Returns an image extension for an output image based on the number of pixels of the output and the file extension of the original file. For example: If the number of pixels exceeds $this->pixelLimitGif (normally 10000) then it will be a "jpg" string in return.

Parameters
string$type‪The file extension, lowercase.
int$w‪The width of the output image.
int$h‪The height of the output image.
Returns
‪string The filename, either "jpg" or "png"

Definition at line 599 of file GraphicalFunctions.php.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert().

◆ imageMagickConvert()

array null TYPO3\CMS\Core\Imaging\GraphicalFunctions::imageMagickConvert (   $imagefile,
  $targetFileExtension = '',
  $w = '',
  $h = '',
  $params = '',
  $frame = '',
  $options = [],
  $mustCreate = false 
)

Converts $imagefile to another file in temp-dir of type $targetFileExtension.

Parameters
string$imagefile‪The absolute image filepath
string$targetFileExtension‪New image file extension. If $targetFileExtension is NOT set, the new imagefile will be of the original format. If set to = 'WEB' then one of the web-formats is applied.
string$w‪Width. $w / $h is optional. If only one is given the image is scaled proportionally. If an 'm' exists in the $w or $h and if both are present the $w and $h is regarded as the Maximum w/h and the proportions will be kept
string$h‪Height. See $w
string$params‪Additional ImageMagick parameters.
string$frame‪Refers to which frame-number to select in the image. '' or 0 will select the first frame, 1 will select the next and so on...
array$options‪An array with options passed to getImageScale (see this function).
bool$mustCreate‪If set, then another image than the input imagefile MUST be returned. Otherwise, you can risk that the input image is good enough regarding measures etc and is of course not rendered to a new, temporary file in typo3temp/. But this option will force it to.
Returns
‪array|null [0]/[1] is w/h, [2] is file extension and [3] is the filename.
See also
‪\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getImgResource()
‪\TYPO3\CMS\Frontend\Imaging\GifBuilder::maskImageOntoImage()
‪\TYPO3\CMS\Frontend\Imaging\GifBuilder::copyImageOntoImage()
‪\TYPO3\CMS\Frontend\Imaging\GifBuilder::scale()

Definition at line 259 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Imaging\GraphicalFunctions\$colorspace, TYPO3\CMS\Core\Imaging\GraphicalFunctions\$imageMagickConvert_forceFileNameBody, TYPO3\CMS\Core\Imaging\GraphicalFunctions\$jpegQuality, $output, TYPO3\CMS\Core\Imaging\GraphicalFunctions\$scalecmd, TYPO3\CMS\Core\Utility\PathUtility\basename(), TYPO3\CMS\Core\Imaging\ImageProcessingInstructions\fromCropScaleValues(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\getImageDimensions(), TYPO3\CMS\Core\Core\Environment\getPublicPath(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\gif_or_jpg(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickExec(), TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\modifyImageMagickStripProfileParameters().

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\crop().

◆ imageMagickExec()

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::imageMagickExec (   $input,
  $output,
  $params,
  $frame = 0 
)

Executes an ImageMagick "convert" on two filenames, $input and $output using $params before them. Can be used for many things, mostly scaling and effects.

Parameters
string$input‪The relative to public web path image filepath, input file (read from)
string$output‪The relative to public web path image filepath, output filename (written to)
string$params‪ImageMagick parameters
int$frame‪Optional, refers to which frame-number to select in the image. '' or 0
Returns
‪string The result of a call to PHP function "exec()

Definition at line 508 of file GraphicalFunctions.php.

References $output, TYPO3\CMS\Core\Utility\CommandUtility\exec(), TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions(), TYPO3\CMS\Core\Imaging\ImageMagickFile\fromFilePath(), and TYPO3\CMS\Core\Utility\CommandUtility\imageMagickCommand().

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\combineExec(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\mask().

◆ imageMagickIdentify()

array null TYPO3\CMS\Core\Imaging\GraphicalFunctions::imageMagickIdentify (   $imagefile)

Call the identify command

Parameters
string$imagefile‪The relative to public web path image filepath
Returns
‪array|null Returns an array where [0]/[1] is w/h, [2] is extension, [3] is the filename and [4] the real image type identified by ImageMagick.

Definition at line 462 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Imaging\GraphicalFunctions\executeIdentifyCommandForImageFile().

◆ mask()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::mask ( string  $inputFile,
string  $outputFile,
string  $maskImage,
string  $maskBackgroundImage,
string  $params,
array  $options 
)

◆ modifyImageMagickStripProfileParameters()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::modifyImageMagickStripProfileParameters ( string  $parameters,
array  $options 
)
protected

Modifies the parameters for ImageMagick for stripping of profile information. Strips profile information of image to save some space ideally

Parameters
string$parameters‪The parameters to be modified (if required)

Definition at line 572 of file GraphicalFunctions.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\mask().

◆ randomName()

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::randomName ( )

Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension). Used by functions in this class to create truly temporary files for the on-the-fly processing. These files will most likely be deleted right away.

Returns
‪string

Definition at line 231 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Utility\StringUtility\getUniqueId(), TYPO3\CMS\Core\Core\Environment\getVarPath(), and TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep().

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\combineExec(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\mask().

◆ setImageFileExt()

TYPO3\CMS\Core\Imaging\GraphicalFunctions::setImageFileExt ( array  $imageFileExt)

Only used for ext:install, not part of TYPO3 Core API.

Definition at line 610 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Imaging\GraphicalFunctions\$imageFileExt.

◆ v5_blur()

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::v5_blur (   $factor)

Returns the IM command for blurring with ImageMagick 5. Uses $this->im5fx_blurSteps for translation of the factor to an actual command.

Parameters
int$factor‪The blurring factor, 0-100 (effectively in 10 steps)
Returns
‪string The blurring command, e.g. " -blur 3x4"
See also
‪makeText()
‪IMparams()
v5_sharpen()

Definition at line 214 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange().

◆ v5_sharpen()

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::v5_sharpen (   $factor)

Returns the IM command for sharpening with ImageMagick 5 Uses $this->im5fx_sharpenSteps for translation of the factor to an actual command.

Parameters
int$factor‪The sharpening factor, 0-100 (effectively in 10 steps)
Returns
‪string The sharpening command, eg. " -sharpen 3x4"
See also
‪makeText()
‪IMparams()
v5_blur()

Definition at line 193 of file GraphicalFunctions.php.

References TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange().

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\__construct().

Member Data Documentation

◆ $addFrameSelection

bool TYPO3\CMS\Core\Imaging\GraphicalFunctions::$addFrameSelection = true

If set, the frame pointer is appended to the filenames.

Definition at line 38 of file GraphicalFunctions.php.

◆ $allowedColorSpaceNames

array TYPO3\CMS\Core\Imaging\GraphicalFunctions::$allowedColorSpaceNames
protected
Initial value:
= [
'CMY',
'CMYK',
'Gray',
'HCL',
'HSB',
'HSL',
'HWB',
'Lab',
'LCH',
'LMS',
'Log',
'Luv',
'OHTA',
'Rec601Luma',
'Rec601YCbCr',
'Rec709Luma',
'Rec709YCbCr',
'RGB',
'sRGB',
'Transparent',
'XYZ',
'YCbCr',
'YCC',
'YIQ',
'YCbCr',
'YUV',
]

colorspace names allowed

Definition at line 48 of file GraphicalFunctions.php.

◆ $alternativeOutputKey

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$alternativeOutputKey = ''

For debugging only. Filenames will not be based on mtime and only filename (not path) will be used. This key is also included in the hash of the filename...

Definition at line 127 of file GraphicalFunctions.php.

◆ $cmds

array TYPO3\CMS\Core\Imaging\GraphicalFunctions::$cmds
Initial value:
= array(
'jpg' => '',
'jpeg' => '',
'gif' => '',
'png' => '',
)

Definition at line 90 of file GraphicalFunctions.php.

◆ $colorspace

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$colorspace = 'RGB'
protected

◆ $dontCheckForExistingTempFile

bool TYPO3\CMS\Core\Imaging\GraphicalFunctions::$dontCheckForExistingTempFile = false

This flag should always be FALSE. If set TRUE, imageMagickConvert will always write a new file to the tempdir! Used for debugging.

Definition at line 119 of file GraphicalFunctions.php.

◆ $filenamePrefix

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$filenamePrefix = ''

Filename prefix for images scaled in imageMagickConvert()

Definition at line 107 of file GraphicalFunctions.php.

◆ $im5fx_blurSteps

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$im5fx_blurSteps = '1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'
protected

Used by v5_blur() to simulate 10 continuous steps of blurring

Definition at line 144 of file GraphicalFunctions.php.

◆ $im5fx_sharpenSteps

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$im5fx_sharpenSteps = '1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'
protected

Used by v5_sharpen() to simulate 10 continuous steps of sharpening.

Definition at line 149 of file GraphicalFunctions.php.

◆ $IM_commands

array TYPO3\CMS\Core\Imaging\GraphicalFunctions::$IM_commands = array( )

All ImageMagick commands executed is stored in this array for tracking. Used by the Install Tools Image section

Definition at line 133 of file GraphicalFunctions.php.

◆ $imageFileExt

array TYPO3\CMS\Core\Imaging\GraphicalFunctions::$imageFileExt = ['gif', 'jpg', 'jpeg', 'png', 'tif', 'bmp', 'tga', 'pcx', 'ai', 'pdf', 'webp']
protected

Allowed file extensions perceived as images by TYPO3. List should be set to 'gif,png,jpeg,jpg' if IM is not available.

Definition at line 81 of file GraphicalFunctions.php.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\getImageFileExt(), and TYPO3\CMS\Core\Imaging\GraphicalFunctions\setImageFileExt().

◆ $imageMagickConvert_forceFileNameBody

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$imageMagickConvert_forceFileNameBody = ''

Forcing the output filename of imageMagickConvert() to this value. However after calling imageMagickConvert() it will be set blank again.

Definition at line 113 of file GraphicalFunctions.php.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert().

◆ $jpegQuality

int TYPO3\CMS\Core\Imaging\GraphicalFunctions::$jpegQuality = 85
protected

◆ $mayScaleUp

bool TYPO3\CMS\Core\Imaging\GraphicalFunctions::$mayScaleUp = true
protected

Definition at line 101 of file GraphicalFunctions.php.

◆ $pixelLimitGif

int TYPO3\CMS\Core\Imaging\GraphicalFunctions::$pixelLimitGif = 10000
protected

This is the limit for the number of pixels in an image before it will be rendered as JPG instead of GIF/PNG

Definition at line 154 of file GraphicalFunctions.php.

◆ $processorEnabled

bool TYPO3\CMS\Core\Imaging\GraphicalFunctions::$processorEnabled
protected

Whether ImageMagick/GraphicsMagick is enabled or not

Definition at line 100 of file GraphicalFunctions.php.

◆ $scalecmd

string TYPO3\CMS\Core\Imaging\GraphicalFunctions::$scalecmd = '-auto-orient -geometry'

ImageMagick scaling command; "-auto-orient -geometry" or "-auto-orient -sample". Used in makeText() and imageMagickConvert()

Definition at line 139 of file GraphicalFunctions.php.

Referenced by TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert().

◆ $webImageExt

array TYPO3\CMS\Core\Imaging\GraphicalFunctions::$webImageExt = ['gif', 'jpg', 'jpeg', 'png']
protected

Web image extensions (can be shown by a webbrowser)

Definition at line 86 of file GraphicalFunctions.php.