From d3b5e678908864d889b916ad2f976c1af16ca360 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 25 Apr 2013 01:55:35 -0700 Subject: odds and ends in prepearation for photo abstraction, plus red-to-friendica addon --- include/Photo.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'include/Photo.php') diff --git a/include/Photo.php b/include/Photo.php index 8daac450e..5882f39f5 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -1,6 +1,111 @@ is_valid()) + return FALSE; + file_put_contents($path, $this->imageString()); + } + + public function orient($filename) { + + /** + * This function is a bit unusual, because it is operating on a file, but you must + * first create an image from that file to initialise the type and check validity + * of the image. + */ + + if(! $this->is_valid()) + return FALSE; + + if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) + return; + + $exif = @exif_read_data($filename); + if($exif) { + $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; + } + } + } +} + + + + + + + class Photo { private $image; @@ -512,10 +617,12 @@ class Photo { imagepng($this->image,NULL, $quality); break; case "image/jpeg": + default: $quality = get_config('system','jpeg_quality'); if((! $quality) || ($quality > 100)) $quality = JPEG_QUALITY; imagejpeg($this->image,NULL,$quality); + break; } $string = ob_get_contents(); ob_end_clean(); -- cgit v1.2.3