Skip to content

Commit

Permalink
Merge pull request #15 from creativecat/master
Browse files Browse the repository at this point in the history
Adding support for exif data "orientation"
  • Loading branch information
sprain committed Sep 8, 2014
2 parents 523e4bd + 65680c5 commit 86b0781
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions class.Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ public function resize($max_width, $max_height, $method="fit", $cropAreaLeftRigh

//Let's get it on, create image!
list($image_create_func, $image_save_func) = $this->getFunctionNames();

// check if it is a jpg and if there are exif data about Orientation (e.g. on uploading an image from smartphone)
if( $this->getMimeType() == "image/jpg" || $this->getMimeType() == "image/jpeg")
{
$exif = exif_read_data($this->image);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$this->rotate(90, $jpgQuality);
break;
case 3:
$this->rotate(180, $jpgQuality);
break;
case 6:
$this->rotate(-90, $jpgQuality);
break;
}
}
}

$imageC = ImageCreateTrueColor($newImage_width, $newImage_height);
$newImage = $image_create_func($this->image);

Expand Down

0 comments on commit 86b0781

Please sign in to comment.