aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-06-18 20:10:11 -0700
committerfriendica <info@friendica.com>2012-06-18 20:10:11 -0700
commit633726e4a90c1bb931967206117e59ca6fe20bb2 (patch)
tree6568c11b82c69868b0890092c8df68a004d41b0f
parent9374e1966fcb42ca45e6af788852be0aafd4e34e (diff)
parent7cd516e34f95945b7f15f42cfe7318dfd907c8d8 (diff)
downloadvolse-hubzilla-633726e4a90c1bb931967206117e59ca6fe20bb2.tar.gz
volse-hubzilla-633726e4a90c1bb931967206117e59ca6fe20bb2.tar.bz2
volse-hubzilla-633726e4a90c1bb931967206117e59ca6fe20bb2.zip
Merge pull request #341 from fermionic/auto-orient-uploaded-images
rotate uploaded images if an EXIF rotation is present
-rw-r--r--include/Photo.php62
-rw-r--r--mod/photos.php1
2 files changed, 62 insertions, 1 deletions
diff --git a/include/Photo.php b/include/Photo.php
index aa6f5f113..54db9278e 100644
--- a/include/Photo.php
+++ b/include/Photo.php
@@ -121,7 +121,67 @@ class Photo {
$this->image = imagerotate($this->image,$degrees,0);
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
- }
+ }
+
+ public function flip($horiz = true, $vert = false) {
+ $w = imagesx($this->image);
+ $h = imagesy($this->image);
+ $flipped = imagecreate($w, $h);
+ if($horiz) {
+ for ($x = 0; $x < $w; $x++) {
+ imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
+ }
+ }
+ if($vert) {
+ for ($y = 0; $y < $h; $y++) {
+ imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
+ }
+ }
+ $this->image = $flipped;
+ }
+
+ public function orient($filename) {
+ // based off comment on http://php.net/manual/en/function.imagerotate.php
+
+ $exif = exif_read_data($filename);
+ $ort = $exif['Orientation'];
+
+ switch($ort)
+ {
+ case 1: // nothing
+ break;
+
+ case 2: // horizontal flip
+ $this->flip();
+ break;
+
+ case 3: // 180 rotate left
+ $this->rotate(180);
+ break;
+
+ case 4: // vertical flip
+ $this->flip(false, true);
+ break;
+
+ case 5: // vertical flip + 90 rotate right
+ $this->flip(false, true);
+ $this->rotate(-90);
+ break;
+
+ case 6: // 90 rotate right
+ $this->rotate(-90);
+ break;
+
+ case 7: // horizontal flip + 90 rotate right
+ $this->flip();
+ $this->rotate(-90);
+ break;
+
+ case 8: // 90 rotate left
+ $this->rotate(90);
+ break;
+ }
+ }
diff --git a/mod/photos.php b/mod/photos.php
index a6552994e..4fa8aca08 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -718,6 +718,7 @@ function photos_post(&$a) {
killme();
}
+ $ph->orient($src);
@unlink($src);
$width = $ph->getWidth();