summaryrefslogtreecommitdiffstats
path: root/application/models/mfile.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-09-19 10:45:56 +0200
committerFlorian Pritz <bluewind@xinu.at>2014-09-20 19:31:42 +0200
commit28129a9e8fbf8a0298585b1344b047a8eb2c68f4 (patch)
tree6c39b4eba7008a3e6ac0f7e7df5a7676bcf155c9 /application/models/mfile.php
parente48be5ef7c6b73e51ab297c55950180261b6c061 (diff)
thumbnails: Handle EXIF orientation
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/models/mfile.php')
-rw-r--r--application/models/mfile.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index 1f5409ec3..c4d2c6e68 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -184,6 +184,48 @@ class Mfile extends CI_Model {
$target_width, $target_height
);
+ /*
+ * Fix orientation according to exif tag
+ */
+ try {
+ $exif = exif_read_data($source_path);
+ } catch (ErrorException $e) {
+ }
+
+ if (isset($exif['Orientation'])) {
+ $mirror = false;
+ $deg = 0;
+
+ switch ($exif['Orientation']) {
+ case 2:
+ $mirror = true;
+ break;
+ case 3:
+ $deg = 180;
+ break;
+ case 4:
+ $deg = 180;
+ $mirror = true;
+ break;
+ case 5:
+ $deg = 270;
+ $mirror = true;
+ break;
+ case 6:
+ $deg = 270;
+ break;
+ case 7:
+ $deg = 90;
+ $mirror = true;
+ break;
+ case 8:
+ $deg = 90;
+ break;
+ }
+ if ($deg) $thumb = imagerotate($thumb, $deg, 0);
+ if ($mirror) $thumb = $this->_mirrorImage($thumb);
+ }
+
ob_start();
switch ($target_type) {
case IMAGETYPE_GIF:
@@ -211,6 +253,27 @@ class Mfile extends CI_Model {
return $result;
}
+ function _mirrorImage($imgsrc)
+ {
+ $width = imagesx($imgsrc);
+ $height = imagesy($imgsrc);
+
+ $src_x = $width -1;
+ $src_y = 0;
+ $src_width = -$width;
+ $src_height = $height;
+
+ $imgdest = imagecreatetruecolor($width, $height);
+ imagealphablending($imgdest,false);
+ imagesavealpha($imgdest,true);
+
+ if (imagecopyresampled($imgdest, $imgsrc, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height)) {
+ return $imgdest;
+ }
+
+ return $imgsrc;
+ }
+
// Add a hash to the DB
function add_file($hash, $id, $filename)
{