From 2315aa7aaec13e0725b61d98d0bd5e71ad241295 Mon Sep 17 00:00:00 2001 From: cdujeu Date: Wed, 16 Apr 2014 18:28:46 +0200 Subject: [PATCH] Manual merge of #300 exif rotation --- .../plugins/editor.diaporama/PThumb.lib.php | 57 +++++++++--------- .../editor.diaporama/class.Diaporama.js | 58 +++++++++---------- .../editor.diaporama/class.ImagePreviewer.php | 19 +++++- .../plugins/editor.diaporama/i18n/conf/en.php | 2 + .../plugins/editor.diaporama/i18n/conf/fr.php | 2 + .../plugins/editor.diaporama/i18n/conf/pt.php | 2 + 6 files changed, 81 insertions(+), 59 deletions(-) diff --git a/core/src/plugins/editor.diaporama/PThumb.lib.php b/core/src/plugins/editor.diaporama/PThumb.lib.php index 4b1b02522a..52b957088d 100644 --- a/core/src/plugins/editor.diaporama/PThumb.lib.php +++ b/core/src/plugins/editor.diaporama/PThumb.lib.php @@ -1087,40 +1087,39 @@ function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x return true; } - function exiforientation($image, $fetch) - { - if (!$this -> exif_rotation) - return; - - if ($fetch) - { - $image_data = $this -> retrieve_remote_file($image,true, false, 1); - $exif = @exif_read_data("data://image/jpeg;base64,".@base64_encode($image_data),'IFD0'); - } else - { - $exif = @exif_read_data($image); - } - if ($exif!=FALSE) + function exiforientation($image, $fetch) { - return $exif['Orientation']; + if (!$this -> exif_rotation) + return; + + if ($fetch) + { + $image_data = $this -> retrieve_remote_file($image,true, false, 1); + $exif = @exif_read_data("data://image/jpeg;base64,".@base64_encode($image_data),'IFD0'); + } else + { + $exif = @exif_read_data($image); + } + if ($exif!=FALSE) + { + return $exif['Orientation']; + } } - } - function rotationsupported($exif_orientation) - { - if (!$exif_orientation) - return FALSE; + function rotationsupported($exif_orientation) + { + if (!$exif_orientation) + return FALSE; - if (!$this -> exif_rotation) - return FALSE; + if (!$this -> exif_rotation) + return FALSE; - if (function_exists("imageflip")) - return TRUE; + if (function_exists("imageflip")) + return TRUE; - if ($exif_orientation!=2 and $exif_orientation!=4 and $exif_orientation!=5 and $exif_orientation!=7) - return TRUE; + if ($exif_orientation!=2 and $exif_orientation!=4 and $exif_orientation!=5 and $exif_orientation!=7) + return TRUE; - return FALSE; - } + return FALSE; + } } -?> diff --git a/core/src/plugins/editor.diaporama/class.Diaporama.js b/core/src/plugins/editor.diaporama/class.Diaporama.js index 46dc7338d3..705e480779 100644 --- a/core/src/plugins/editor.diaporama/class.Diaporama.js +++ b/core/src/plugins/editor.diaporama/class.Diaporama.js @@ -343,39 +343,39 @@ Class.create("Diaporama", AbstractEditor, { var height = parseInt(nPercent*this.crtHeight / 100); var width = parseInt(nPercent*this.crtWidth / 100); - // apply rotation - this.imgBorder.removeClassName("ort-rotate-1"); - this.imgBorder.removeClassName("ort-rotate-2"); - this.imgBorder.removeClassName("ort-rotate-3"); - this.imgBorder.removeClassName("ort-rotate-4"); - this.imgBorder.removeClassName("ort-rotate-5"); - this.imgBorder.removeClassName("ort-rotate-6"); - this.imgBorder.removeClassName("ort-rotate-7"); - this.imgBorder.removeClassName("ort-rotate-8"); - var ort = node.getMetadata().get("ort"); - if (ort) - this.imgBorder.addClassName("ort-rotate-"+ort); + // apply rotation + this.imgBorder.removeClassName("ort-rotate-1"); + this.imgBorder.removeClassName("ort-rotate-2"); + this.imgBorder.removeClassName("ort-rotate-3"); + this.imgBorder.removeClassName("ort-rotate-4"); + this.imgBorder.removeClassName("ort-rotate-5"); + this.imgBorder.removeClassName("ort-rotate-6"); + this.imgBorder.removeClassName("ort-rotate-7"); + this.imgBorder.removeClassName("ort-rotate-8"); + var ort = node.getMetadata().get("image_exif_orientation"); + if (ort) + this.imgBorder.addClassName("ort-rotate-"+ort); - // Center vertically - var marginTop=0; - var marginLeft=0; - this.containerDim = $(this.imgContainer).getDimensions(); + // Center vertically + var marginTop=0; + var marginLeft=0; + this.containerDim = $(this.imgContainer).getDimensions(); - if (ort>4) - { - tmp=height; - height=width; - width=tmp; - } + if (ort>4) + { + tmp=height; + height=width; + width=tmp; + } - if (height < this.containerDim.height){ - marginTop = parseInt((this.containerDim.height - height) / 2); - } - if (width < this.containerDim.width){ - marginLeft = parseInt((this.containerDim.width - width) / 2); - } + if (height < this.containerDim.height){ + marginTop = parseInt((this.containerDim.height - height) / 2); + } + if (width < this.containerDim.width){ + marginLeft = parseInt((this.containerDim.width - width) / 2); + } - if(morph && this.imgBorder.visible()){ + if(morph && this.imgBorder.visible()){ new Effect.Morph(this.imgBorder,{ style:{height:height+'px', width:width+'px',marginTop:marginTop+'px',marginLeft:marginLeft+'px'}, duration:0.5, diff --git a/core/src/plugins/editor.diaporama/class.ImagePreviewer.php b/core/src/plugins/editor.diaporama/class.ImagePreviewer.php index 5a873a8c84..06f8688883 100644 --- a/core/src/plugins/editor.diaporama/class.ImagePreviewer.php +++ b/core/src/plugins/editor.diaporama/class.ImagePreviewer.php @@ -122,7 +122,7 @@ public function generateThumbnail($masterFile, $targetFile) { $size = $this->currentDimension; require_once(AJXP_INSTALL_PATH."/plugins/editor.diaporama/PThumb.lib.php"); - $pThumb = new PThumb($this->getFilteredOption("THUMBNAIL_QUALITY")); + $pThumb = new PThumb($this->getFilteredOption("THUMBNAIL_QUALITY"), $this->getFilteredOption("EXIF_ROTATION")); if (!$pThumb->isError()) { $pThumb->remote_wrapper = $this->streamData["classname"]; //$this->logDebug("Will fit thumbnail"); @@ -176,6 +176,23 @@ public function extractImageMetadata(&$ajxpNode) } else { $realFile = $ajxpNode->getRealFile(); list($width, $height, $type, $attr) = @getimagesize($realFile); + + if($this->getFilteredOption("EXIF_ROTATION")){ + require_once(AJXP_INSTALL_PATH."/plugins/editor.diaporama/PThumb.lib.php"); + $pThumb = new PThumb($this->getFilteredOption["THUMBNAIL_QUALITY"],$this->getFilteredOption("EXIF_ROTATION")); + $orientation = $pThumb->exiforientation($realFile, false); + if ($pThumb->rotationsupported($orientation)) + { + $ajxpNode->image_exif_orientation = $orientation; + if ($orientation>4) + { + $tmp=$height; + $height=$width; + $width=$tmp; + } + } + } + $ajxpNode->image_type = image_type_to_mime_type($type); $ajxpNode->image_width = $width; $ajxpNode->image_height = $height; diff --git a/core/src/plugins/editor.diaporama/i18n/conf/en.php b/core/src/plugins/editor.diaporama/i18n/conf/en.php index 0aefc01a3a..96b9d13d30 100644 --- a/core/src/plugins/editor.diaporama/i18n/conf/en.php +++ b/core/src/plugins/editor.diaporama/i18n/conf/en.php @@ -29,4 +29,6 @@ "Generate thumbnails or not" => "Generate thumbnails or not", "Quality" => "Quality", "Thumbs quality" => "Thumbs quality", +"Exif Rotation" => "Exif Rotation", +"Rotate image using exif rotation" => "Rotate image using exif rotation" ); diff --git a/core/src/plugins/editor.diaporama/i18n/conf/fr.php b/core/src/plugins/editor.diaporama/i18n/conf/fr.php index 97b59977c4..a1d9280957 100644 --- a/core/src/plugins/editor.diaporama/i18n/conf/fr.php +++ b/core/src/plugins/editor.diaporama/i18n/conf/fr.php @@ -29,4 +29,6 @@ "Generate thumbnails or not" => "Génération des vignettes ou pas", "Quality" => "Qualité", "Thumbs quality" => "Qualité pour le rendu de la vignette.", + "Exif Rotation" => "Exif Rotation", + "Rotate image using exif rotation" => "Rotate image using exif rotation" ); diff --git a/core/src/plugins/editor.diaporama/i18n/conf/pt.php b/core/src/plugins/editor.diaporama/i18n/conf/pt.php index 6274c8b63b..3e8e296663 100644 --- a/core/src/plugins/editor.diaporama/i18n/conf/pt.php +++ b/core/src/plugins/editor.diaporama/i18n/conf/pt.php @@ -29,4 +29,6 @@ "Generate thumbnails or not" => "Gerar ou não miniaturas", "Quality" => "Qualidade", "Thumbs quality" => "Qualidade das miniaturas", + "Exif Rotation" => "Exif Rotation", + "Rotate image using exif rotation" => "Rotate image using exif rotation" );