/** * rotate an imagick object based on it's exif data. * * @param imagick $image an instance of imagick * @return void */ protected function _exifRotateImagick($image) { $orientation = $image->getImageOrientation(); $trans = $this->_exifOrientationTransformations($orientation); if ($trans['flip_vert']) { $image->flopImage(); } if ($trans['flip_horz']) { $image->flipImage(); } if ($trans['rotate_clockwise']) { $image->rotateimage("#000", $trans['rotate_clockwise']); } $image->setImageOrientation(imagick::ORIENTATION_TOPLEFT); }
private function resize_imagick($src, $width, $height, $quality, $preserveExif) { try { $img = new imagick($src); if (strtoupper($img->getImageFormat()) === 'JPEG') { $img->setImageCompression(imagick::COMPRESSION_JPEG); $img->setImageCompressionQuality($quality); if (!$preserveExif) { try { $orientation = $img->getImageOrientation(); } catch (ImagickException $e) { $orientation = 0; } $img->stripImage(); if ($orientation) { $img->setImageOrientation($orientation); } } } $img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, true); $result = $img->writeImage($src); $img->clear(); $img->destroy(); return $result ? true : false; } catch (Exception $e) { return false; } }