TYPO3 CMS  TYPO3_6-2
LocalCropScaleMaskHelper.php
Go to the documentation of this file.
1 <?php
3 
17 use \TYPO3\CMS\Core\Resource, \TYPO3\CMS\Core\Utility;
18 
23 
27  protected $processor;
28 
33  $this->processor = $processor;
34  }
35 
52  public function process(TaskInterface $task) {
53  $result = NULL;
54  $targetFile = $task->getTargetFile();
55  $sourceFile = $task->getSourceFile();
56 
57  $originalFileName = $sourceFile->getForLocalProcessing(FALSE);
59  $gifBuilder = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
60  $gifBuilder->init();
61  $gifBuilder->absPrefix = PATH_site;
62 
63  $configuration = $targetFile->getProcessingConfiguration();
64  $configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters($configuration['additionalParameters'], $configuration);
65 
66  if (empty($configuration['fileExtension'])) {
67  $configuration['fileExtension'] = $task->getTargetFileExtension();
68  }
69 
70  $options = $this->getConfigurationForImageCropScaleMask($targetFile, $gifBuilder);
71 
72  // Normal situation (no masking)
73  if (!(is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'])) {
74  // the result info is an array with 0=width,1=height,2=extension,3=filename
75  $result = $gifBuilder->imageMagickConvert(
76  $originalFileName,
77  $configuration['fileExtension'],
78  $configuration['width'],
79  $configuration['height'],
80  $configuration['additionalParameters'],
81  $configuration['frame'],
82  $options
83  );
84  } else {
85  $targetFileName = $this->getFilenameForImageCropScaleMask($task);
86  $temporaryFileName = $gifBuilder->tempPath . $targetFileName;
87  $maskImage = $configuration['maskImages']['maskImage'];
88  $maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
89  if ($maskImage instanceof Resource\FileInterface && $maskBackgroundImage instanceof Resource\FileInterface) {
90  $temporaryExtension = 'png';
91  if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif']) {
92  // If ImageMagick version 5+
93  $temporaryExtension = $gifBuilder->gifExtension;
94  }
95  $tempFileInfo = $gifBuilder->imageMagickConvert(
96  $originalFileName,
97  $temporaryExtension,
98  $configuration['width'],
99  $configuration['height'],
100  $configuration['additionalParameters'],
101  $configuration['frame'],
102  $options
103  );
104  if (is_array($tempFileInfo)) {
105  $maskBottomImage = $configuration['maskImages']['maskBottomImage'];
106  if ($maskBottomImage instanceof Resource\FileInterface) {
107  $maskBottomImageMask = $configuration['maskImages']['maskBottomImageMask'];
108  } else {
109  $maskBottomImageMask = NULL;
110  }
111 
112  // Scaling: ****
113  $tempScale = array();
114  $command = '-geometry ' . $tempFileInfo[0] . 'x' . $tempFileInfo[1] . '!';
115  $command = $this->modifyImageMagickStripProfileParameters($command, $configuration);
116  $tmpStr = $gifBuilder->randomName();
117  // m_mask
118  $tempScale['m_mask'] = $tmpStr . '_mask.' . $temporaryExtension;
119  $gifBuilder->imageMagickExec($maskImage->getForLocalProcessing(TRUE), $tempScale['m_mask'], $command);
120  // m_bgImg
121  $tempScale['m_bgImg'] = $tmpStr . '_bgImg.miff';
122  $gifBuilder->imageMagickExec($maskBackgroundImage->getForLocalProcessing(), $tempScale['m_bgImg'], $command);
123  // m_bottomImg / m_bottomImg_mask
124  if ($maskBottomImage instanceof Resource\FileInterface && $maskBottomImageMask instanceof Resource\FileInterface) {
125  $tempScale['m_bottomImg'] = $tmpStr . '_bottomImg.' . $temporaryExtension;
126  $gifBuilder->imageMagickExec($maskBottomImage->getForLocalProcessing(), $tempScale['m_bottomImg'], $command);
127  $tempScale['m_bottomImg_mask'] = ($tmpStr . '_bottomImg_mask.') . $temporaryExtension;
128  $gifBuilder->imageMagickExec($maskBottomImageMask->getForLocalProcessing(), $tempScale['m_bottomImg_mask'], $command);
129  // BEGIN combining:
130  // The image onto the background
131  $gifBuilder->combineExec($tempScale['m_bgImg'], $tempScale['m_bottomImg'], $tempScale['m_bottomImg_mask'], $tempScale['m_bgImg']);
132  }
133  // The image onto the background
134  $gifBuilder->combineExec($tempScale['m_bgImg'], $tempFileInfo[3], $tempScale['m_mask'], $temporaryFileName);
135  $tempFileInfo[3] = $temporaryFileName;
136  // Unlink the temp-images...
137  foreach ($tempScale as $tempFile) {
138  if (@is_file($tempFile)) {
139  unlink($tempFile);
140  }
141  }
142  }
143  $result = $tempFileInfo;
144  }
145  }
146  // check if the processing really generated a new file
147  if ($result !== NULL) {
148  if ($result[3] !== $originalFileName) {
149  $result = array(
150  'width' => $result[0],
151  'height' => $result[1],
152  'filePath' => $result[3],
153  );
154  } else {
155  // No file was generated
156  $result = NULL;
157  }
158  }
159 
160  return $result;
161  }
162 
169  protected function getConfigurationForImageCropScaleMask(Resource\ProcessedFile $processedFile, \TYPO3\CMS\Frontend\Imaging\GifBuilder $gifBuilder) {
170  $configuration = $processedFile->getProcessingConfiguration();
171 
172  if ($configuration['useSample']) {
173  $gifBuilder->scalecmd = '-sample';
174  }
175  $options = array();
176  if ($configuration['maxWidth']) {
177  $options['maxW'] = $configuration['maxWidth'];
178  }
179  if ($configuration['maxHeight']) {
180  $options['maxH'] = $configuration['maxHeight'];
181  }
182  if ($configuration['minWidth']) {
183  $options['minW'] = $configuration['minWidth'];
184  }
185  if ($configuration['minHeight']) {
186  $options['minH'] = $configuration['minHeight'];
187  }
188 
189  $options['noScale'] = $configuration['noScale'];
190 
191  return $options;
192  }
193 
201 
202  $configuration = $task->getTargetFile()->getProcessingConfiguration();
203  $targetFileExtension = $task->getSourceFile()->getExtension();
204  $processedFileExtension = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif';
205  if (is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && $task->getSourceFile()->getExtension() != $processedFileExtension) {
206  $targetFileExtension = 'jpg';
207  } elseif ($configuration['fileExtension']) {
208  $targetFileExtension = $configuration['fileExtension'];
209  }
210 
211  return $task->getTargetFile()->generateProcessedFileNameWithoutExtension() . '.' . ltrim(trim($targetFileExtension), '.');
212  }
213 
221  protected function modifyImageMagickStripProfileParameters($parameters, array $configuration) {
222  // Strips profile information of image to save some space:
223  if (isset($configuration['stripProfile'])) {
224  if ($configuration['stripProfile']) {
225  $parameters = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_stripProfileCommand'] . $parameters;
226  } else {
227  $parameters .= '###SkipStripProfile###';
228  }
229  }
230  return $parameters;
231  }
232 }
$parameters
Definition: FileDumpEID.php:15
getConfigurationForImageCropScaleMask(Resource\ProcessedFile $processedFile, \TYPO3\CMS\Frontend\Imaging\GifBuilder $gifBuilder)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]