]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
add the module to the page title
[friendica.git] / include / Photo.php
index fc2ce149c4b62fc6b4e6a065f3a41d15a5ae69b8..9732801c9a3d8fbe18a0bbfe20c2ca11214b5d7e 100644 (file)
@@ -345,20 +345,37 @@ class Photo {
     }
 
     public function orient($filename) {
+       if ($this->is_imagick()) {
+               // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
+               $orientation = $this->image->getImageOrientation();
+               switch ($orientation) {
+               case imagick::ORIENTATION_BOTTOMRIGHT:
+                   $this->image->rotateimage("#000", 180);
+                   break;
+               case imagick::ORIENTATION_RIGHTTOP:
+                   $this->image->rotateimage("#000", 90);
+                   break;
+               case imagick::ORIENTATION_LEFTBOTTOM:
+                   $this->image->rotateimage("#000", -90);
+                   break;
+               }
+
+               $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
+               return TRUE;
+       }
        // based off comment on http://php.net/manual/en/function.imagerotate.php
 
        if(!$this->is_valid())
-           return FALSE;
+               return FALSE;
 
        if( (! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg') )
-           return;
-
-       $exif = @exif_read_data($filename);
+               return;
 
-               if(! $exif)
-                       return;
+       $exif = @exif_read_data($filename,null,true);
+       if(! $exif)
+               return;
 
-       $ort = $exif['Orientation'];
+       $ort = $exif['IFD0']['Orientation'];
 
        switch($ort)
        {
@@ -395,6 +412,10 @@ class Photo {
                $this->rotate(90);
                break;
        }
+
+       //      logger('exif: ' . print_r($exif,true));
+       return $exif;
+
     }
 
 
@@ -516,7 +537,12 @@ class Photo {
            return FALSE;
 
        $string = $this->imageString();
+
+       $a = get_app();
+
+       $stamp1 = microtime(true);
        file_put_contents($path, $string);
+       $a->save_timestamp($stamp1, "file");
     }
 
     public function imageString() {
@@ -764,11 +790,21 @@ function get_photo_info($url) {
        if (is_null($data)) {
                $img_str = fetch_url($url, true, $redirects, 4);
 
+               $filesize = strlen($img_str);
+
                $tempfile = tempnam(get_temppath(), "cache");
+
+               $a = get_app();
+               $stamp1 = microtime(true);
                file_put_contents($tempfile, $img_str);
+               $a->save_timestamp($stamp1, "file");
+
                $data = getimagesize($tempfile);
                unlink($tempfile);
 
+               if ($data)
+                       $data["size"] = $filesize;
+
                Cache::set($url, serialize($data));
        } else
                $data = unserialize($data);
@@ -846,7 +882,10 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
                return(array());
        } elseif (strlen($imagedata) == 0) {
                logger("Uploading picture from ".$url, LOGGER_DEBUG);
+
+               $stamp1 = microtime(true);
                $imagedata = @file_get_contents($url);
+               $a->save_timestamp($stamp1, "file");
        }
 
        $maximagesize = get_config('system','maximagesize');
@@ -870,7 +909,11 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
 */
 
        $tempfile = tempnam(get_temppath(), "cache");
+
+       $stamp1 = microtime(true);
        file_put_contents($tempfile, $imagedata);
+       $a->save_timestamp($stamp1, "file");
+
        $data = getimagesize($tempfile);
 
        if (!isset($data["mime"])) {
@@ -957,14 +1000,20 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
                        $image["thumb"] = $a->get_baseurl()."/photo/{$hash}-3.".$ph->getExt();
        }
 
-       if (isset($image["thumb"]))
-               $image["preview"] = $image["thumb"];
+       // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
+       $image["preview"] = $image["full"];
+
+       // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
+       //if (isset($image["thumb"]))
+       //      $image["preview"] = $image["thumb"];
 
-       if (isset($image["small"]))
-               $image["preview"] = $image["small"];
+       // Unsure, if this should be activated or deactivated
+       //if (isset($image["small"]))
+       //      $image["preview"] = $image["small"];
 
        if (isset($image["medium"]))
                $image["preview"] = $image["medium"];
 
        return($image);
 }
+