]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
more branding
[friendica.git] / include / Photo.php
index 0f5003a6f7839b7f24f8e92a117ac5eab633bed3..ca9ae0703c3162e1d0d853d4131b9b5a284fe0e7 100644 (file)
@@ -6,12 +6,15 @@ class Photo {
        private $image;
        private $width;
        private $height;
+       private $valid;
 
        public function __construct($data) {
+               $this->valid = false;
                $this->image = @imagecreatefromstring($data);
                if($this->image !== FALSE) {
                        $this->width  = imagesx($this->image);
                        $this->height = imagesy($this->image);
+                       $this->valid  = true;
                }
        }
 
@@ -20,6 +23,10 @@ class Photo {
                        imagedestroy($this->image);
        }
 
+       public function is_valid() {
+               return $this->valid;
+       }
+
        public function getWidth() {
                return $this->width;
        }
@@ -201,3 +208,44 @@ class Photo {
 }}
 
 
+function import_profile_photo($photo,$uid,$cid) {
+
+       $a = get_app();
+
+       $photo_failure = false;
+
+       $filename = basename($photo);
+       $img_str = fetch_url($photo,true);
+       $img = new Photo($img_str);
+       if($img->is_valid()) {
+
+               $img->scaleImageSquare(175);
+                                       
+               $hash = photo_new_resource();
+
+               $r = $img->store($uid, $cid, $hash, $filename, t('Contact Photos'), 4 );
+
+               if($r === false)
+                       $photo_failure = true;
+
+               $img->scaleImage(80);
+
+               $r = $img->store($uid, $cid, $hash, $filename, t('Contact Photos'), 5 );
+
+               if($r === false)
+                       $photo_failure = true;
+
+               $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
+               $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';
+       }
+       else
+               $photo_failure = true;
+
+       if($photo_failure) {
+               $photo = $a->get_baseurl() . '/images/default-profile.jpg';
+               $thumb = $a->get_baseurl() . '/images/default-profile-sm.jpg';
+       }
+
+       return(array($photo,$thumb));
+
+}