/** * Resize an image according to given parameter. * * @throws \Exception * @param string $fileNameAndPath * @param int $width * @param int $height * @return void */ public function resize($fileNameAndPath, $width = 0, $height = 0) { // Skip profile of the image $imParams = '###SkipStripProfile###'; $options = array('maxW' => $width, 'maxH' => $height); $tempFileInfo = $this->gifCreator->imageMagickConvert($fileNameAndPath, '', '', '', $imParams, '', $options, TRUE); if ($tempFileInfo) { // Overwrite original file @unlink($fileNameAndPath); @rename($tempFileInfo[3], $fileNameAndPath); } }
/** * Optimize the given uploaded image * * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile * @return \Fab\Media\FileUpload\UploadedFileInterface */ public function optimize($uploadedFile) { $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); $isRotated = $this->isRotated($orientation); // Only rotate image if necessary! if ($isRotated > 0) { $transformation = $this->getTransformation($orientation); $imParams = '###SkipStripProfile###'; if ($transformation !== '') { $imParams .= ' ' . $transformation; } $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', array(), TRUE); if ($tempFileInfo) { // Replace original file @unlink($uploadedFile->getFileWithAbsolutePath()); @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); } } } return $uploadedFile; }