]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
Merge branch 'master' of git://github.com/friendika/friendika
[friendica.git] / include / Photo.php
index e418cde4621231048851053a22441ee93c76b773..707b0de5d8c3af8ea8ac849690ad644fb8180fae 100644 (file)
@@ -162,12 +162,20 @@ class Photo {
        }
 
        public function saveImage($path) {
-               imagejpeg($this->image,$path,100);
+               $quality = get_config('system','jpeg_quality');
+               if((! $quality) || ($quality > 100))
+                       $quality = JPEG_QUALITY;
+               imagejpeg($this->image,$path,$quality);
        }
 
        public function imageString() {
                ob_start();
-               imagejpeg($this->image,NULL,100);
+
+               $quality = get_config('system','jpeg_quality');
+               if((! $quality) || ($quality > 100))
+                       $quality = JPEG_QUALITY;
+
+               imagejpeg($this->image,NULL,$quality);
                $s = ob_get_contents();
                ob_end_clean();
                return $s;
@@ -175,8 +183,7 @@ class Photo {
 
 
 
-       public function store($uid, $cid, $rid, $filename, $album, $scale, 
-               $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
+       public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
 
                $r = q("INSERT INTO `photo`
                        ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
@@ -188,9 +195,9 @@ class Photo {
                        dbesc(datetime_convert()),
                        dbesc(basename($filename)),
                        dbesc($album),
-                       intval($this->height),
-                       intval($this->width),
-                       dbesc($this->imageString()),
+                       intval($this->height),
+                       intval($this->width),
+                       dbesc($this->imageString()),
                        intval($scale),
                        intval($profile),
                        dbesc($allow_cid),
@@ -208,3 +215,55 @@ 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;
+
+               $img->scaleImage(48);
+
+               $r = $img->store($uid, $cid, $hash, $filename, t('Contact Photos'), 6 );
+
+               if($r === false)
+                       $photo_failure = true;
+
+
+
+               $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
+               $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';
+               $micro = $a->get_baseurl() . '/photo/' . $hash . '-6.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';
+               $micro = $a->get_baseurl() . '/images/default-profile-mm.jpg';
+       }
+
+       return(array($photo,$thumb,$micro));
+
+}