2 namespace TYPO3\CMS\Core\Resource\Processing;
17 use TYPO3\CMS\Core\Resource;
64 $originalFileName = $sourceFile->getForLocalProcessing(
false);
68 $gifBuilder->absPrefix = PATH_site;
70 $configuration = $targetFile->getProcessingConfiguration();
73 if (empty($configuration[
'fileExtension'])) {
80 if (!empty($configuration[
'crop'])) {
83 $cropData = json_decode($configuration[
'crop']);
85 $crop = implode(
',', array((
int)$cropData->x, (
int)$cropData->y, (
int)$cropData->width, (
int)$cropData->height));
87 $crop = $configuration[
'crop'];
90 list($offsetLeft, $offsetTop, $newWidth, $newHeight) = explode(
',', $crop, 4);
92 $backupPrefix = $gifBuilder->filenamePrefix;
93 $gifBuilder->filenamePrefix =
'crop_';
96 $result = $gifBuilder->imageMagickConvert(
101 sprintf(
'-crop %dx%d+%d+%d', $newWidth, $newHeight, $offsetLeft, $offsetTop),
106 $gifBuilder->filenamePrefix = $backupPrefix;
108 if ($result !== null) {
109 $originalFileName = $croppedImage = $result[3];
114 if (!(is_array($configuration[
'maskImages']) &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'im'])) {
117 if ($croppedImage === null && $sourceFile->getExtension() ===
'svg') {
118 $newDimensions = $this->
getNewSvgDimensions($sourceFile, $configuration, $options, $gifBuilder);
120 0 => $newDimensions[
'width'],
121 1 => $newDimensions[
'height'],
128 $result = $gifBuilder->imageMagickConvert(
130 $configuration[
'fileExtension'],
131 $configuration[
'width'],
132 $configuration[
'height'],
133 $configuration[
'additionalParameters'],
134 $configuration[
'frame'],
140 $temporaryFileName = $gifBuilder->tempPath . $targetFileName;
141 $maskImage = $configuration[
'maskImages'][
'maskImage'];
142 $maskBackgroundImage = $configuration[
'maskImages'][
'backgroundImage'];
143 if ($maskImage instanceof Resource\FileInterface && $maskBackgroundImage instanceof Resource\FileInterface) {
144 $temporaryExtension =
'png';
145 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'im_mask_temp_ext_gif']) {
147 $temporaryExtension = $gifBuilder->gifExtension;
149 $tempFileInfo = $gifBuilder->imageMagickConvert(
152 $configuration[
'width'],
153 $configuration[
'height'],
154 $configuration[
'additionalParameters'],
155 $configuration[
'frame'],
158 if (is_array($tempFileInfo)) {
159 $maskBottomImage = $configuration[
'maskImages'][
'maskBottomImage'];
160 if ($maskBottomImage instanceof Resource\FileInterface) {
161 $maskBottomImageMask = $configuration[
'maskImages'][
'maskBottomImageMask'];
163 $maskBottomImageMask = null;
167 $tempScale = array();
168 $command =
'-geometry ' . $tempFileInfo[0] .
'x' . $tempFileInfo[1] .
'!';
170 $tmpStr = $gifBuilder->randomName();
172 $tempScale[
'm_mask'] = $tmpStr .
'_mask.' . $temporaryExtension;
173 $gifBuilder->imageMagickExec($maskImage->getForLocalProcessing(
true), $tempScale[
'm_mask'], $command);
175 $tempScale[
'm_bgImg'] = $tmpStr .
'_bgImg.miff';
176 $gifBuilder->imageMagickExec($maskBackgroundImage->getForLocalProcessing(), $tempScale[
'm_bgImg'], $command);
178 if ($maskBottomImage instanceof Resource\FileInterface && $maskBottomImageMask instanceof Resource\FileInterface) {
179 $tempScale[
'm_bottomImg'] = $tmpStr .
'_bottomImg.' . $temporaryExtension;
180 $gifBuilder->imageMagickExec($maskBottomImage->getForLocalProcessing(), $tempScale[
'm_bottomImg'], $command);
181 $tempScale[
'm_bottomImg_mask'] = ($tmpStr .
'_bottomImg_mask.') . $temporaryExtension;
182 $gifBuilder->imageMagickExec($maskBottomImageMask->getForLocalProcessing(), $tempScale[
'm_bottomImg_mask'], $command);
185 $gifBuilder->combineExec($tempScale[
'm_bgImg'], $tempScale[
'm_bottomImg'], $tempScale[
'm_bottomImg_mask'], $tempScale[
'm_bgImg']);
188 $gifBuilder->combineExec($tempScale[
'm_bgImg'], $tempFileInfo[3], $tempScale[
'm_mask'], $temporaryFileName);
189 $tempFileInfo[3] = $temporaryFileName;
191 foreach ($tempScale as $tempFile) {
192 if (@is_file($tempFile)) {
197 $result = $tempFileInfo;
202 if ($result !== null) {
203 if ($result[3] !== $originalFileName || $originalFileName === $croppedImage) {
205 'width' => $result[0],
206 'height' => $result[1],
207 'filePath' => $result[3],
216 if ($croppedImage && ($result === null || $croppedImage !== $result[
'filePath'])) {
235 $info = array($file->getProperty(
'width'), $file->getProperty(
'height'));
236 $data = $gifBuilder->
getImageScale($info, $configuration[
'width'], $configuration[
'height'], $options);
240 if (!$data[
'origW']) {
241 $data[
'origW'] = $data[0];
243 if (!$data[
'origH']) {
244 $data[
'origH'] = $data[1];
246 if ($data[0] > $data[
'origW']) {
247 $data[1] = (int)(($data[
'origW'] * $data[1]) / $data[0]);
248 $data[0] = $data[
'origW'];
250 $data[0] = (int)(($data[
'origH'] * $data[0]) / $data[1]);
251 $data[1] = $data[
'origH'];
269 $configuration = $processedFile->getProcessingConfiguration();
271 if ($configuration[
'useSample']) {
272 $gifBuilder->scalecmd =
'-sample';
275 if ($configuration[
'maxWidth']) {
276 $options[
'maxW'] = $configuration[
'maxWidth'];
278 if ($configuration[
'maxHeight']) {
279 $options[
'maxH'] = $configuration[
'maxHeight'];
281 if ($configuration[
'minWidth']) {
282 $options[
'minW'] = $configuration[
'minWidth'];
284 if ($configuration[
'minHeight']) {
285 $options[
'minH'] = $configuration[
'minHeight'];
288 $options[
'noScale'] = $configuration[
'noScale'];
301 $configuration = $task->
getTargetFile()->getProcessingConfiguration();
302 $targetFileExtension = $task->
getSourceFile()->getExtension();
303 $processedFileExtension =
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'gdlib_png'] ?
'png' :
'gif';
304 if (is_array($configuration[
'maskImages']) &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'im'] && $task->
getSourceFile()->getExtension() != $processedFileExtension) {
305 $targetFileExtension =
'jpg';
306 }
elseif ($configuration[
'fileExtension']) {
307 $targetFileExtension = $configuration[
'fileExtension'];
310 return $task->
getTargetFile()->generateProcessedFileNameWithoutExtension() .
'.' . ltrim(trim($targetFileExtension),
'.');
323 if (isset($configuration[
'stripProfile'])) {
324 if ($configuration[
'stripProfile']) {
325 $parameters =
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'im_stripProfileCommand'] . $parameters;
327 $parameters .=
'###SkipStripProfile###';