diff --git a/libraries/fabrik/fabrik/Helpers/Image.php b/libraries/fabrik/fabrik/Helpers/Image.php index 1f85941ad80..7b4c4353f7b 100644 --- a/libraries/fabrik/fabrik/Helpers/Image.php +++ b/libraries/fabrik/fabrik/Helpers/Image.php @@ -138,18 +138,21 @@ protected static function testGD() */ protected static function testImagemagick() { + $im = array(); + if (function_exists('NewMagickWand')) { $im['IM'] = 'Magick wand'; } else { + /* $status = ''; $output = array(); @exec('convert -version', $output, $status); $im = array(); - if (!$status && class_exists('Imagick')) + if ($status && class_exists('Imagick')) { if (preg_match("/imagemagick[ \t]+([0-9\.]+)/i", $output[0], $matches)) { @@ -158,6 +161,12 @@ protected static function testImagemagick() } unset($output, $status); + */ + + if (class_exists('Imagick')) + { + $im['IM'] = 'Imagick'; + } } return $im; diff --git a/libraries/fabrik/fabrik/Helpers/Image/Image.php b/libraries/fabrik/fabrik/Helpers/Image/Image.php index 740262cc1af..53b8fae33bf 100644 --- a/libraries/fabrik/fabrik/Helpers/Image/Image.php +++ b/libraries/fabrik/fabrik/Helpers/Image/Image.php @@ -74,7 +74,15 @@ public function getImgType($filename) return 'png'; break; default: + $pathInfo = pathInfo($filename); + + if (ArrayHelper::getValue($pathInfo, 'extension', '') === 'pdf') + { + return 'pdf'; + }; + return false; + break; } } diff --git a/libraries/fabrik/fabrik/Helpers/Image/Imageim.php b/libraries/fabrik/fabrik/Helpers/Image/Imageim.php index 2de74d72cbe..ac92ec3d91c 100644 --- a/libraries/fabrik/fabrik/Helpers/Image/Imageim.php +++ b/libraries/fabrik/fabrik/Helpers/Image/Imageim.php @@ -79,6 +79,7 @@ public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 1 // OK, it's a PDF, so first we need to add the page number we want to the source filename $pdfFile = $fromFile . '[0]'; + /* if (is_callable('exec')) { $destFile = str_replace('.pdf', '.png', $destFile); // Output File @@ -87,6 +88,7 @@ public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 1 } else { + */ // Now just load it, set format, resize, save and garbage collect. // Hopefully IM will call the right delegate (ghostscript) to load the PDF. $im = new \Imagick($pdfFile); @@ -95,7 +97,9 @@ public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 1 $im->writeImage($destFile); // as destroy() is deprecated $im->clear(); + /* } + */ } else { @@ -131,4 +135,75 @@ public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 1 MagickWriteImage($resource, $destFile); } } + + /* + * Check for EXIF orientation data, and rotate image accordingly +* +* @param string path to image file +*/ + public function rotateImageFromExif($src, $dest) + { + if (function_exists('exif_read_data')) + { + $exif = exif_read_data($src); + if ($exif && isset($exif['Orientation'])) + { + $orientation = $exif['Orientation']; + if ($orientation != 1) + { + $deg = 0; + switch ($orientation) + { + case 3: + $deg = 180; + break; + case 6: + $deg = 270; + break; + case 8: + $deg = 90; + break; + } + if ($deg) + { + self::rotate($src, $dest, $deg); + } + } + } + } + } + + /** + * Rotate an image + * + * @param string $source filepath + * @param string $dest output path, if empty defaults to source + * @param int $degrees number of degrees to rotate + * + * @return array (image object, rotated images width, rotated images height) + */ + public function rotate($source, $dest = '', $degrees = 0) + { + if (empty($dest)) + { + $dest = $source; + } + + $source = $this->imageCreateFrom($source); + $app = JFactory::getApplication(); + + // Rotates the image + $rotate = imagerotate($source, $degrees, 0); + + if ($rotate === false) + { + $app->enqueueMessage('Image rotation failed', 'notice'); + } + + $this->imageToFile($dest, $rotate); + list($width, $height) = getimagesize($dest); + + return array($rotate, $width, $height); + } + }