| Conditions | 15 |
| Paths | 73 |
| Total Lines | 109 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 63 | public function processWithLocalFile(TaskInterface $task, string $originalFileName): ?array |
||
| 64 | { |
||
| 65 | if (empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled'])) { |
||
| 66 | return null; |
||
| 67 | } |
||
| 68 | |||
| 69 | $result = null; |
||
| 70 | $targetFile = $task->getTargetFile(); |
||
| 71 | |||
| 72 | $gifBuilder = GeneralUtility::makeInstance(GifBuilder::class); |
||
| 73 | |||
| 74 | $configuration = $targetFile->getProcessingConfiguration(); |
||
| 75 | $configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters($configuration['additionalParameters'], $configuration); |
||
| 76 | |||
| 77 | if (empty($configuration['fileExtension'])) { |
||
| 78 | $configuration['fileExtension'] = $task->getTargetFileExtension(); |
||
| 79 | } |
||
| 80 | |||
| 81 | $options = $this->getConfigurationForImageCropScaleMask($targetFile, $gifBuilder); |
||
| 82 | // Normal situation (no masking) |
||
| 83 | if (empty($configuration['maskImages'])) { |
||
| 84 | // the result info is an array with 0=width,1=height,2=extension,3=filename |
||
| 85 | $result = $gifBuilder->imageMagickConvert( |
||
| 86 | $originalFileName, |
||
| 87 | $configuration['fileExtension'] ?? null, |
||
| 88 | $configuration['width'] ?? null, |
||
| 89 | $configuration['height'] ?? null, |
||
| 90 | $configuration['additionalParameters'] ?? null, |
||
| 91 | $configuration['frame'] ?? null, |
||
| 92 | $options |
||
| 93 | ); |
||
| 94 | } else { |
||
| 95 | $targetFileName = $this->getFilenameForImageCropScaleMask($task); |
||
| 96 | $temporaryFileName = Environment::getPublicPath() . '/typo3temp/' . $targetFileName; |
||
| 97 | $maskImage = $configuration['maskImages']['maskImage']; |
||
| 98 | $maskBackgroundImage = $configuration['maskImages']['backgroundImage']; |
||
| 99 | if ($maskImage instanceof FileInterface && $maskBackgroundImage instanceof FileInterface) { |
||
| 100 | $temporaryExtension = 'png'; |
||
| 101 | if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_allowTemporaryMasksAsPng']) { |
||
| 102 | // If ImageMagick version 5+ |
||
| 103 | $temporaryExtension = $gifBuilder->gifExtension; |
||
| 104 | } |
||
| 105 | $tempFileInfo = $gifBuilder->imageMagickConvert( |
||
| 106 | $originalFileName, |
||
| 107 | $temporaryExtension, |
||
| 108 | $configuration['width'] ?? null, |
||
| 109 | $configuration['height'] ?? null, |
||
| 110 | $configuration['additionalParameters'] ?? null, |
||
| 111 | $configuration['frame'] ?? null, |
||
| 112 | $options |
||
| 113 | ); |
||
| 114 | if (is_array($tempFileInfo)) { |
||
| 115 | $maskBottomImage = $configuration['maskImages']['maskBottomImage'] ?? null; |
||
| 116 | if ($maskBottomImage instanceof FileInterface) { |
||
| 117 | $maskBottomImageMask = $configuration['maskImages']['maskBottomImageMask'] ?? null; |
||
| 118 | } else { |
||
| 119 | $maskBottomImageMask = null; |
||
| 120 | } |
||
| 121 | |||
| 122 | // Scaling: **** |
||
| 123 | $tempScale = []; |
||
| 124 | $command = '-geometry ' . $tempFileInfo[0] . 'x' . $tempFileInfo[1] . '!'; |
||
| 125 | $command = $this->modifyImageMagickStripProfileParameters($command, $configuration); |
||
| 126 | $tmpStr = $gifBuilder->randomName(); |
||
| 127 | // m_mask |
||
| 128 | $tempScale['m_mask'] = $tmpStr . '_mask.' . $temporaryExtension; |
||
| 129 | $gifBuilder->imageMagickExec($maskImage->getForLocalProcessing(true), $tempScale['m_mask'], $command); |
||
| 130 | // m_bgImg |
||
| 131 | $tempScale['m_bgImg'] = $tmpStr . '_bgImg.miff'; |
||
| 132 | $gifBuilder->imageMagickExec($maskBackgroundImage->getForLocalProcessing(), $tempScale['m_bgImg'], $command); |
||
| 133 | // m_bottomImg / m_bottomImg_mask |
||
| 134 | if ($maskBottomImage instanceof FileInterface && $maskBottomImageMask instanceof FileInterface) { |
||
| 135 | $tempScale['m_bottomImg'] = $tmpStr . '_bottomImg.' . $temporaryExtension; |
||
| 136 | $gifBuilder->imageMagickExec($maskBottomImage->getForLocalProcessing(), $tempScale['m_bottomImg'], $command); |
||
| 137 | $tempScale['m_bottomImg_mask'] = ($tmpStr . '_bottomImg_mask.') . $temporaryExtension; |
||
| 138 | $gifBuilder->imageMagickExec($maskBottomImageMask->getForLocalProcessing(), $tempScale['m_bottomImg_mask'], $command); |
||
| 139 | // BEGIN combining: |
||
| 140 | // The image onto the background |
||
| 141 | $gifBuilder->combineExec($tempScale['m_bgImg'], $tempScale['m_bottomImg'], $tempScale['m_bottomImg_mask'], $tempScale['m_bgImg']); |
||
| 142 | } |
||
| 143 | // The image onto the background |
||
| 144 | $gifBuilder->combineExec($tempScale['m_bgImg'], $tempFileInfo[3], $tempScale['m_mask'], $temporaryFileName); |
||
| 145 | $tempFileInfo[3] = $temporaryFileName; |
||
| 146 | // Unlink the temp-images... |
||
| 147 | foreach ($tempScale as $tempFile) { |
||
| 148 | if (@is_file($tempFile)) { |
||
| 149 | unlink($tempFile); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | $result = $tempFileInfo; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | // check if the processing really generated a new file (scaled and/or cropped) |
||
| 158 | if ($result !== null) { |
||
| 159 | if ($result[3] !== $originalFileName) { |
||
| 160 | $result = [ |
||
| 161 | 'width' => $result[0], |
||
| 162 | 'height' => $result[1], |
||
| 163 | 'filePath' => $result[3], |
||
| 164 | ]; |
||
| 165 | } else { |
||
| 166 | // No file was generated |
||
| 167 | $result = null; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | return $result; |
||
| 172 | } |
||
| 265 |