Skip to content

Commit

Permalink
Preserve rotation from EXIF data if present
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Cockx committed Dec 26, 2017
1 parent 224d3ca commit cf11b67
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion dist/nano_photos_provider2.json.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,28 @@ protected function Compare($a, $b)
return ($b) ? +1 : -1;
}

function image_fix_orientation(&$image, &$size, $filename) {
$exif = exif_read_data($filename);

if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$image = imagerotate($image, 180, 0);
break;

case 6:
$image = imagerotate($image, -90, 0);
list($size[0],$size[1]) = array($size[1],$size[0]);
break;

case 8:
$image = imagerotate($image, 90, 0);
list($size[0],$size[1]) = array($size[1],$size[0]);
break;
}
}
}


/**
* RETRIEVE ONE IMAGE'S DISPLAY URL
Expand Down Expand Up @@ -387,6 +409,8 @@ protected function GetImageDisplayURL( $baseFolder, $filename )
break;
}

$this->image_fix_orientation($orgImage, $size, $baseFolder . $filename);

$width = $size[0];
$height = $size[1];

Expand Down Expand Up @@ -488,6 +512,9 @@ protected function GetDominantColorsGIF( $img )
return '';
break;
}

$this->image_fix_orientation($orgImage, $size, $img);

$width = $size[0];
$height = $size[1];
$thumb = imagecreate(3, 3);
Expand Down Expand Up @@ -526,6 +553,7 @@ protected function GetDominantColor( $img )
return '#000000';
break;
}
$this->image_fix_orientation($orgImage, $size, $img);
$width = $size[0];
$height = $size[1];

Expand Down Expand Up @@ -591,6 +619,7 @@ protected function GenerateThumbnail2($baseFolder, $imagefilename, $thumbnailFil
break;
}
}
$this->image_fix_orientation($orgImage, $size, $baseFolder . $imagefilename);

$width = $size[0];
$height = $size[1];
Expand Down Expand Up @@ -959,4 +988,4 @@ protected function PrepareData($filename, $kind)
}

}
?>
?>

0 comments on commit cf11b67

Please sign in to comment.