Esempio n. 1
0
 /**
  * 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;
     }
 }