public function preprocessImage($imageSource = null)
{
$src = null === $imageSource ? $this->arguments['src'] : $imageSource;
$width = $this->arguments['width'];
$height = $this->arguments['height'];
$minW = $this->arguments['minW'];
$minH = $this->arguments['minH'];
$maxW = $this->arguments['maxW'];
$maxH = $this->arguments['maxH'];
$format = $this->arguments['format'];
$quality = $this->arguments['quality'];
$treatIdAsReference = (bool) $this->arguments['treatIdAsReference'];
$crop = $this->arguments['crop'];
if (is_object($src) && $src instanceof FileReference) {
$src = $src->getUid();
$treatIdAsReference = true;
}
if ($crop === null) {
$crop = is_object($src) && $src instanceof FileReference ? $src->getProperty('crop') : null;
}
if ('BE' === TYPO3_MODE) {
$this->simulateFrontendEnvironment();
}
$setup = ['width' => $width, 'height' => $height, 'minW' => $minW, 'minH' => $minH, 'maxW' => $maxW, 'maxH' => $maxH, 'treatIdAsReference' => $treatIdAsReference, 'crop' => $crop];
if (false === empty($format)) {
$setup['ext'] = $format;
}
if (0 < (int) $quality) {
$quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
$setup['params'] = '-quality ' . $quality;
}
if (TYPO3_MODE === 'BE' && strpos($src, '../') === 0) {
$src = substr($src, 3);
}
$this->imageInfo = $this->contentObject->getImgResource($src, $setup);
$GLOBALS['TSFE']->lastImageInfo = $this->imageInfo;
if (false === is_array($this->imageInfo)) {
throw new Exception('Could not get image resource for "' . htmlspecialchars($src) . '".', 1253191060);
}
if ($this->hasArgument('canvasWidth') && $this->hasArgument('canvasHeight')) {
$canvasWidth = (int) $this->arguments['canvasWidth'];
$canvasHeight = (int) $this->arguments['canvasHeight'];
$canvasColor = str_replace('#', '', $this->arguments['canvasColor']);
$originalFilename = $this->imageInfo[3];
$originalExtension = substr($originalFilename, -3);
$destinationFilename = 'typo3temp/vhs-canvas-' . md5($originalFilename . $canvasColor . $canvasWidth . $canvasHeight) . '.' . $originalExtension;
$destinationFilepath = GeneralUtility::getFileAbsFileName($destinationFilename);
if (!file_exists($destinationFilepath)) {
$arguments = sprintf('%s -background \'#%s\' -gravity center -extent %dx%d %s', $originalFilename, $canvasColor, $canvasWidth, $canvasHeight, $destinationFilepath);
$command = CommandUtility::imageMagickCommand('convert', $arguments);
CommandUtility::exec($command);
}
$this->imageInfo[3] = $destinationFilename;
}
$GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
$GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
$publicUrl = rawurldecode($this->imageInfo[3]);
$this->mediaSource = GeneralUtility::rawUrlEncodeFP($publicUrl);
if (TYPO3_MODE === 'BE') {
$this->resetFrontendEnvironment();
}
}