]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Photo.php
Update use statements
[friendica.git] / src / Object / Photo.php
index db3c75f99eabca4e936f45036794bca63872d78c..a8bb3b4adac34d76d0e828294f51b57d69964e13 100644 (file)
@@ -11,6 +11,9 @@ use Friendica\Core\Config;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
 use dba;
+use Exception;
+use Imagick;
+use ImagickPixel;
 
 require_once "include/photos.php";
 
@@ -33,6 +36,7 @@ class Photo
 
        /**
         * @brief supported mimetypes and corresponding file extensions
+        * @return array
         */
        public static function supportedTypes()
        {
@@ -109,7 +113,7 @@ class Photo
         * @brief Maps Mime types to Imagick formats
         * @return arr With with image formats (mime type as key)
         */
-       public function getFormatsMap()
+       public static function getFormatsMap()
        {
                $m = array(
                        'image/jpeg' => 'JPG',
@@ -137,7 +141,7 @@ class Photo
                        /*
                         * Setup the image to the format it will be saved to
                         */
-                       $map = $this->getFormatsMap();
+                       $map = self::getFormatsMap();
                        $format = $map[$type];
                        $this->image->setFormat($format);
 
@@ -446,18 +450,18 @@ class Photo
                        // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
                        $orientation = $this->image->getImageOrientation();
                        switch ($orientation) {
-                               case imagick::ORIENTATION_BOTTOMRIGHT:
+                               case Imagick::ORIENTATION_BOTTOMRIGHT:
                                        $this->image->rotateimage("#000", 180);
                                        break;
-                               case imagick::ORIENTATION_RIGHTTOP:
+                               case Imagick::ORIENTATION_RIGHTTOP:
                                        $this->image->rotateimage("#000", 90);
                                        break;
-                               case imagick::ORIENTATION_LEFTBOTTOM:
+                               case Imagick::ORIENTATION_LEFTBOTTOM:
                                        $this->image->rotateimage("#000", -90);
                                        break;
                        }
 
-                       $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
+                       $this->image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
                        return true;
                }
                // based off comment on http://php.net/manual/en/function.imagerotate.php
@@ -764,7 +768,7 @@ class Photo
         *
         * @return object
         */
-       public function guessImageType($filename, $fromcurl = false)
+       public static function guessImageType($filename, $fromcurl = false)
        {
                logger('Photo: guessImageType: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
                $type = null;
@@ -792,7 +796,7 @@ class Photo
                                $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
                        } else {
                                $ext = pathinfo($filename, PATHINFO_EXTENSION);
-                               $types = $this->supportedTypes();
+                               $types = self::supportedTypes();
                                $type = "image/jpeg";
                                foreach ($types as $m => $e) {
                                        if ($ext == $e) {
@@ -805,51 +809,6 @@ class Photo
                return $type;
        }
 
-       /**
-        * @brief Updates the avatar links in a contact only if needed
-        *
-        * @param string $avatar Link to avatar picture
-        * @param int    $uid    User id of contact owner
-        * @param int    $cid    Contact id
-        * @param bool   $force  force picture update
-        *
-        * @return array Returns array of the different avatar sizes
-        */
-       public function updateContactAvatar($avatar, $uid, $cid, $force = false)
-       {
-               // Limit = 1 returns the row so no need for dba:inArray()
-               $r = dba::select('contact', array('avatar', 'photo', 'thumb', 'micro', 'nurl'), array('id' => $cid), array('limit' => 1));
-               if (!DBM::is_result($r)) {
-                       return false;
-               } else {
-                       $data = array($r["photo"], $r["thumb"], $r["micro"]);
-               }
-
-               if (($r["avatar"] != $avatar) || $force) {
-                       $photos = $this->importProfilePhoto($avatar, $uid, $cid, true);
-
-                       if ($photos) {
-                               dba::update(
-                                       'contact',
-                                       array('avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => datetime_convert()),
-                                       array('id' => $cid)
-                               );
-
-                               // Update the public contact (contact id = 0)
-                               if ($uid != 0) {
-                                       $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
-                                       if (DBM::is_result($pcontact)) {
-                                               $this->updateContactAvatar($avatar, 0, $pcontact['id'], $force);
-                                       }
-                               }
-
-                               return $photos;
-                       }
-               }
-
-               return $data;
-       }
-
        /**
         * @param string  $photo         photo
         * @param integer $uid           user id
@@ -857,7 +816,7 @@ class Photo
         * @param boolean $quit_on_error optional, default false
         * @return array
         */
-       private function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
+       public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
        {
                $r = dba::select(
                        'photo',
@@ -881,7 +840,7 @@ class Photo
                        return false;
                }
        
-               $type = $this->guessImageType($photo, true);
+               $type = self::guessImageType($photo, true);
                $img = new Photo($img_str, $type);
                if ($img->isValid()) {
                        $img->scaleImageSquare(175);
@@ -946,14 +905,14 @@ class Photo
                        $micro = System::baseUrl() . '/images/person-48.jpg';
                }
        
-               return(array($photo, $thumb, $micro));
+               return array($photo, $thumb, $micro);
        }
 
        /**
         * @param string $url url
         * @return object
         */
-       public function getPhotoInfo($url)
+       public static function getInfoFromURL($url)
        {
                $data = array();
        
@@ -993,7 +952,7 @@ class Photo
         * @param integer $max    max
         * @return array
         */
-       public function scaleImageTo($width, $height, $max)
+       public static function scaleImageTo($width, $height, $max)
        {
                $dest_width = $dest_height = 0;
        
@@ -1042,14 +1001,14 @@ class Photo
        }
 
        /**
-        * @brief This function doesn't seem to be used
+        * @brief This function is used by the fromgplus addon
         * @param object  $a         App
         * @param integer $uid       user id
         * @param string  $imagedata optional, default empty
         * @param string  $url       optional, default empty
         * @return array
         */
-       private function storePhoto(App $a, $uid, $imagedata = "", $url = "")
+       public static function storePhoto(App $a, $uid, $imagedata = "", $url = "")
        {
                $r = q(
                        "SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
@@ -1115,6 +1074,7 @@ class Photo
                if (! $max_length) {
                        $max_length = MAX_IMAGE_LENGTH;
                }
+
                if ($max_length > 0) {
                        $ph->scaleImage($max_length);
                }
@@ -1139,7 +1099,7 @@ class Photo
                }
        
                $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
-                               "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
+                       "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
        
                if ($width > 800 || $height > 800) {
                        $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt();
@@ -1164,12 +1124,12 @@ class Photo
                if ($width > 160 && $height > 160) {
                        $x = 0;
                        $y = 0;
-       
+               
                        $min = $ph->getWidth();
                        if ($min > 160) {
                                $x = ($min - 160) / 2;
                        }
-       
+               
                        if ($ph->getHeight() < $min) {
                                $min = $ph->getHeight();
                                if ($min > 160) {
@@ -1179,7 +1139,7 @@ class Photo
        
                        $min = 160;
                        $ph->cropImage(160, $x, $y, $min, $min);
-       
+               
                        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
                        if ($r) {
                                $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt();
@@ -1191,11 +1151,11 @@ class Photo
        
                // 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"];
+               //  $image["preview"] = $image["thumb"];
        
                // Unsure, if this should be activated or deactivated
                //if (isset($image["small"]))
-               //      $image["preview"] = $image["small"];
+               //  $image["preview"] = $image["small"];
        
                if (isset($image["medium"])) {
                        $image["preview"] = $image["medium"];