/**
* File formats supported by gdlib. This variable get's filled in "init" method
*
- * @var string
+ * @var array
*/
- public $gdlibExtensions = '';
+ protected $gdlibExtensions = [];
/**
* defines the RGB colorspace to use
public $truecolorColors = 16777215;
/**
- * Commalist of file extensions perceived as images by TYPO3.
- * List should be set to 'gif,png,jpeg,jpg' if IM is not available. Lowercase and no spaces between!
+ * Allowed file extensions perceived as images by TYPO3.
+ * List should be set to 'gif,png,jpeg,jpg' if IM is not available.
*
- * @var string
+ * @var array
*/
- public $imageFileExt = 'gif,jpg,jpeg,png,tif,bmp,tga,pcx,ai,pdf';
+ protected $imageFileExt = ['gif', 'jpg', 'jpeg', 'png', 'tif', 'bmp', 'tga', 'pcx', 'ai', 'pdf'];
/**
- * Commalist of web image extensions (can be shown by a webbrowser)
+ * Web image extensions (can be shown by a webbrowser)
*
- * @var string
+ * @var array
*/
- public $webImageExt = 'gif,jpg,jpeg,png';
+ protected $webImageExt = ['gif', 'jpg', 'jpeg', 'png'];
/**
- * @var string
+ * Enable ImageMagick effects, disabled by default as IM5+ effects slow down the image generation
+ *
+ * @var bool
*/
- public $NO_IM_EFFECTS = '';
+ protected $processorEffectsEnabled = false;
/**
* @var array
];
/**
- * @var string
+ * @var bool
*/
- public $NO_IMAGE_MAGICK = '';
+ protected $NO_IMAGE_MAGICK = false;
/**
* @var bool
*/
- public $mayScaleUp = 1;
+ protected $mayScaleUp = true;
/**
* Filename prefix for images scaled in imageMagickConvert()
*
* @var bool
*/
- public $dontCheckForExistingTempFile = 0;
+ public $dontCheckForExistingTempFile = false;
/**
* Prevents imageMagickConvert() from compressing the gif-files with self::gifCompress()
*
* @var bool
*/
- public $dontCompress = 0;
-
- /**
- * For debugging ONLY!
- *
- * @var bool
- */
- public $dontUnlinkTempFiles = 0;
+ public $dontCompress = false;
/**
* For debugging only.
*/
protected $saveAlphaLayer = false;
- /**
- * Prefix for relative paths. Used in "show_item.php" script. Is prefixed the output file name IN imageMagickConvert()
- *
- * @var string
- */
- public $absPrefix = '';
-
/**
* ImageMagick scaling command; "-geometry" or "-sample". Used in makeText() and imageMagickConvert()
*
*
* @var string
*/
- public $im5fx_blurSteps = '1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5';
+ protected $im5fx_blurSteps = '1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5';
/**
* Used by v5_sharpen() to simulate 10 continuous steps of sharpening.
*
* @var string
*/
- public $im5fx_sharpenSteps = '1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5';
+ protected $im5fx_sharpenSteps = '1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5';
/**
* This is the limit for the number of pixels in an image before it will be rendered as JPG instead of GIF/PNG
*
* @var int
*/
- public $pixelLimitGif = 10000;
+ protected $pixelLimitGif = 10000;
/**
* Array mapping HTML color names to RGB values.
*
* @var array
*/
- public $colMap = [
+ protected $colMap = [
'aqua' => [0, 255, 255],
'black' => [0, 0, 0],
'blue' => [0, 0, 255],
*
* @var CharsetConverter
*/
- public $csConvObj;
+ protected $csConvObj;
/**
* @var int
*/
- public $jpegQuality = 85;
+ protected $jpegQuality = 85;
/**
* @var string
/**
* @var array
*/
- public $OFFSET;
+ protected $OFFSET;
/**
* @var resource
{
$gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
if (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
- $this->gdlibExtensions .= ',jpg,jpeg';
+ $this->gdlibExtensions[] = 'jpg';
+ $this->gdlibExtensions[] = 'jpeg';
}
if (function_exists('imagecreatefrompng') && function_exists('imagepng')) {
- $this->gdlibExtensions .= ',png';
+ $this->gdlibExtensions[] = 'png';
}
if (function_exists('imagecreatefromgif') && function_exists('imagegif')) {
- $this->gdlibExtensions .= ',gif';
+ $this->gdlibExtensions[] = 'gif';
}
if ($gfxConf['processor_colorspace'] && in_array($gfxConf['processor_colorspace'], $this->allowedColorSpaceNames, true)) {
}
if (!$gfxConf['processor_enabled']) {
- $this->NO_IMAGE_MAGICK = 1;
+ $this->NO_IMAGE_MAGICK = true;
}
// Setting default JPG parameters:
$this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 85);
if ($gfxConf['gdlib_png']) {
$this->gifExtension = 'png';
}
- $this->imageFileExt = $gfxConf['imagefile_ext'];
+ $this->imageFileExt = GeneralUtility::trimExplode(',', $gfxConf['imagefile_ext']);
// Boolean. This is necessary if using ImageMagick 5+.
// Effects in Imagemagick 5+ tends to render very slowly!!
// - therefore must be disabled in order not to perform sharpen, blurring and such.
- $this->NO_IM_EFFECTS = 1;
$this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace ' . $this->colorspace . ' -quality ' . $this->jpegQuality;
// ... but if 'processor_effects' is set, enable effects
if ($gfxConf['processor_effects']) {
- $this->NO_IM_EFFECTS = 0;
+ $this->processorEffectsEnabled = true;
$this->cmds['jpg'] .= $this->v5_sharpen(10);
$this->cmds['jpeg'] .= $this->v5_sharpen(10);
}
// Secures that images are not scaled up.
- if (!$gfxConf['processor_allowUpscaling']) {
- $this->mayScaleUp = 0;
- }
+ $this->mayScaleUp = (bool)$gfxConf['processor_allowUpscaling'];
$this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
}
if ($conf['file'] && $conf['mask']) {
$imgInf = pathinfo($conf['file']);
$imgExt = strtolower($imgInf['extension']);
- if (!GeneralUtility::inList($this->gdlibExtensions, $imgExt)) {
+ if (!in_array($imgExt, $this->gdlibExtensions, true)) {
$BBimage = $this->imageMagickConvert($conf['file'], $this->gifExtension);
} else {
$BBimage = $this->getImageDimensions($conf['file']);
}
$maskInf = pathinfo($conf['mask']);
$maskExt = strtolower($maskInf['extension']);
- if (!GeneralUtility::inList($this->gdlibExtensions, $maskExt)) {
+ if (!in_array($maskExt, $this->gdlibExtensions, true)) {
$BBmask = $this->imageMagickConvert($conf['mask'], $this->gifExtension);
} else {
$BBmask = $this->getImageDimensions($conf['mask']);
$im = $backIm;
}
// Unlink files from process
- if (!$this->dontUnlinkTempFiles) {
- unlink($theDest);
- unlink($theImage);
- unlink($theMask);
- }
+ unlink($theDest);
+ unlink($theImage);
+ unlink($theMask);
}
}
}
public function copyImageOntoImage(&$im, $conf, $workArea)
{
if ($conf['file']) {
- if (!GeneralUtility::inList($this->gdlibExtensions, $conf['BBOX'][2])) {
+ if (!in_array($conf['BBOX'][2], $this->gdlibExtensions, true)) {
$conf['BBOX'] = $this->imageMagickConvert($conf['BBOX'][3], $this->gifExtension);
$conf['file'] = $conf['BBOX'][3];
}
$this->ImageWrite($maskImg, $fileMask);
imagedestroy($maskImg);
// Downscales the mask
- if ($this->NO_IM_EFFECTS) {
+ if (!$this->processorEffectsEnabled) {
$command = trim($this->scalecmd . ' ' . $w . 'x' . $h . '! -negate');
} else {
$command = trim($conf['niceText.']['before'] . ' ' . $this->scalecmd . ' ' . $w . 'x' . $h . '! ' . $conf['niceText.']['after'] . ' -negate');
$im = $backIm;
}
// Deleting temporary files;
- if (!$this->dontUnlinkTempFiles) {
- unlink($fileMenu);
- unlink($fileColor);
- unlink($fileMask);
- }
+ unlink($fileMenu);
+ unlink($fileColor);
+ unlink($fileMask);
}
}
}
$workArea = $this->applyOffset($workArea, GeneralUtility::intExplode(',', $conf['offset']));
$blurRate = MathUtility::forceIntegerInRange((int)$conf['blur'], 0, 99);
// No effects if ImageMagick ver. 5+
- if (!$blurRate || $this->NO_IM_EFFECTS) {
+ if (!$blurRate || !$this->processorEffectsEnabled) {
$txtConf['fontColor'] = $conf['color'];
$this->makeText($im, $txtConf, $workArea);
} else {
}
}
// Deleting temporary files;
- if (!$this->dontUnlinkTempFiles) {
- unlink($fileMenu);
- unlink($fileColor);
- unlink($fileMask);
- }
+ unlink($fileMenu);
+ unlink($fileColor);
+ unlink($fileMask);
}
}
$commands .= ' -gamma ' . (float)$value;
break;
case 'blur':
- if (!$this->NO_IM_EFFECTS) {
+ if ($this->processorEffectsEnabled) {
$commands .= $this->v5_blur($value);
}
break;
case 'sharpen':
- if (!$this->NO_IM_EFFECTS) {
+ if ($this->processorEffectsEnabled) {
$commands .= $this->v5_sharpen($value);
}
break;
$conf['offset'] = $cords[0] . ',' . $cords[1];
$cords = $this->objPosition($conf, $this->workArea, [$cords[2], $cords[3]]);
$newIm = imagecreatetruecolor($cords[2], $cords[3]);
- $cols = $this->convertColor($conf['backColor'] ? $conf['backColor'] : $this->setup['backColor']);
+ $cols = $this->convertColor($conf['backColor'] ?: $this->setup['backColor']);
$Bcolor = imagecolorallocate($newIm, $cols[0], $cols[1], $cols[2]);
imagefilledrectangle($newIm, 0, 0, $cords[2], $cords[3], $Bcolor);
$newConf = [];
// Clears workArea to total image
$this->setWorkArea('');
}
- if (!$this->dontUnlinkTempFiles) {
- unlink($theFile);
- if ($theNewFile[3] && $theNewFile[3] != $theFile) {
- unlink($theNewFile[3]);
- }
+ unlink($theFile);
+ if ($theNewFile[3] && $theNewFile[3] != $theFile) {
+ unlink($theNewFile[3]);
}
}
}
$newExt = $info[2];
}
if ($newExt === 'web') {
- if (GeneralUtility::inList($this->webImageExt, $info[2])) {
+ if (in_array($info[2], $this->webImageExt, true)) {
$newExt = $info[2];
} else {
$newExt = $this->gif_or_jpg($info[2], $info[0], $info[1]);
}
}
}
- if (!GeneralUtility::inList($this->imageFileExt, $newExt)) {
+ if (!in_array($newExt, $this->imageFileExt, true)) {
return null;
}
}
// Making the temporary filename:
GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
- $output = $this->absPrefix . 'typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
+ $output = PATH_site . 'typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
if ($this->dontCheckForExistingTempFile || !file_exists($output)) {
$this->imageMagickExec($imagefile, $output, $command, $frame);
}
public function getImageDimensions($imageFile)
{
preg_match('/([^\\.]*)$/', $imageFile, $reg);
- if (file_exists($imageFile) && GeneralUtility::inList($this->imageFileExt, strtolower($reg[0]))) {
+ if (file_exists($imageFile) && in_array(strtolower($reg[0]), $this->imageFileExt, true)) {
if ($returnArr = $this->getCachedImageDimensions($imageFile)) {
return $returnArr;
}
$this->w = imagesx($im);
$this->h = imagesy($im);
}
- if (!$this->dontUnlinkTempFiles) {
- unlink($theFile);
- }
+ unlink($theFile);
}
/**
$result = false;
switch ($ext) {
case 'jpg':
-
case 'jpeg':
if (function_exists('imagejpeg')) {
- if ($quality == 0) {
+ if ($quality === 0) {
$quality = $this->jpegQuality;
}
$result = imagejpeg($destImg, $theImage, $quality);
}
break;
case 'jpg':
-
case 'jpeg':
if (function_exists('imagecreatefromjpeg')) {
return imagecreatefromjpeg($sourceImg);
}
}
// Unlink files from process
- if (!$this->dontUnlinkTempFiles) {
- if ($origName) {
- @unlink($origName);
- }
- if ($postName) {
- @unlink($postName);
- }
+ if ($origName) {
+ @unlink($origName);
+ }
+ if ($postName) {
+ @unlink($postName);
}
}
return $retCol;