/** * Fixes image orientation * * @since 1.0 * @access public * @param string * @return */ public function fixOrientation() { $exif = FD::get('Exif'); if (!$exif->isAvailable()) { return false; } // Get the mime type for this image $mime = $this->getMime(); // Only image with jpeg are supported. if ($mime != 'image/jpeg') { return false; } // Load exif data. $exif->load($this->meta->path); $orientation = $exif->getOrientation(); switch ($orientation) { case 1: // Do nothing here as the image is already correct. $this->adapter->rotate($this->image, 0); break; case 2: // Flip image horizontally since it's at top right $this->adapter->flop($this->image); break; case 3: // Rotate image 180 degrees left since it's at bottom right $this->adapter->rotate($this->image, 180); break; case 4: // Flip image vertically because it's at bottom left $this->adapter->flip($this->image); break; case 5: // Flip image vertically $this->adapter->flip($this->image); // Rotate image 90 degrees right. $this->adapter->rotate($this->image, -90); break; case 6: // Rotate image 90 degrees right $this->adapter->rotate($this->image, 90); break; case 7: // Flip image horizontally $this->adapter->flop($this->image); // Rotate 90 degrees right. $this->adapter->rotate($this->image, 90); break; case 8: // Rotate image 90 degrees left $this->adapter->rotate($this->image, -90); break; } }
function generateThumbnail($originalImgPath, $thumbDir, $prefix, $thumbWidth = 0, $thumbHeight = 0, $type = 'resize', $typeParams = array(), $filters = array()) { $thumbSize = AriImageHelper::getThumbnailDimension($originalImgPath, $thumbWidth, $thumbHeight); if (!$thumbSize['w'] || !$thumbSize['h'] || !@is_readable($originalImgPath)) return null; $width = $thumbSize['w']; $height = $thumbSize['h']; $path_parts = pathinfo($originalImgPath); $thumbName = AriImageHelper::generateThumbnailFileName($prefix, $originalImgPath, $width, $height, $type); $thumbImgPath = $thumbDir . DS . $thumbName; if (@file_exists($thumbImgPath) && @filemtime($thumbImgPath) > @filemtime($originalImgPath)) return $thumbName; if (!AriImageHelper::initAsido()) return ; $thumbImg = Asido::image($originalImgPath, $thumbImgPath); $needResize = true; if ($type == 'crop') { Asido::crop( $thumbImg, intval(AriUtils::getParam($typeParams, 'x', 0), 10), intval(AriUtils::getParam($typeParams, 'y', 0), 10), $width ? $width : $height, $height ? $height : $width ); $needResize = false; } else if ($type == 'cropresize') { Asido::crop( $thumbImg, intval(AriUtils::getParam($typeParams, 'x', 0), 10), intval(AriUtils::getParam($typeParams, 'y', 0), 10), intval(AriUtils::getParam($typeParams, 'width', 0), 10), intval(AriUtils::getParam($typeParams, 'height', 0), 10) ); } if ($filters) { if (AriUtils::parseValueBySample( AriUtils::getParam($filters, 'grayscale', false), false) ) { Asido::grayscale($thumbImg); } $rotateFilter = AriUtils::getParam($filters, 'rotate'); if (is_array($rotateFilter) && AriUtils::parseValueBySample( AriUtils::getParam($rotateFilter, 'enable', false), false) ) { $angle = 0; $rotateType = AriUtils::getParam($rotateFilter, 'type', 'fixed'); if ($rotateType == 'random') { $startAngle = intval(AriUtils::getParam($rotateFilter, 'startAngle', 0), 10); $endAngle = intval(AriUtils::getParam($rotateFilter, 'endAngle', 0), 10); $angle = rand($startAngle, $endAngle); } else { $angle = intval(AriUtils::getParam($rotateFilter, 'angle', 0), 10); } $angle = $angle % 360; if ($angle != 0) { Asido::rotate($thumbImg, $angle); } } } if ($needResize) { if (!$width) Asido::height($thumbImg, $height); else if (!$height) Asido::width($thumbImg, $width); else Asido::resize($thumbImg, $width, $height, ASIDO_RESIZE_STRETCH); } $thumbImg->save(ASIDO_OVERWRITE_ENABLED); return $thumbName; }