X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FPhoto.php;h=1450374ffc27971fd91b20d325c5593d3ac33413;hb=8aa25523721303b6883e1a793f20997f8a33ec0a;hp=95ccccc88df6da1bdf9702a55d61318e0a72e79d;hpb=6348e70daa113e8b3203de8fbc919d08c90d972e;p=friendica.git diff --git a/include/Photo.php b/include/Photo.php old mode 100644 new mode 100755 index 95ccccc88d..1450374ffc --- a/include/Photo.php +++ b/include/Photo.php @@ -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; } @@ -155,17 +162,117 @@ 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; } + + public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { + + $r = q("select `guid` from photo where `resource-id` = '%s' and `guid` != '' limit 1", + dbesc($rid) + ); + if(count($r)) + $guid = $r[0]['guid']; + else + $guid = get_guid(); + + $r = q("INSERT INTO `photo` + ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", + intval($uid), + intval($cid), + dbesc($guid), + dbesc($rid), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(basename($filename)), + dbesc($album), + intval($this->height), + intval($this->width), + dbesc($this->imageString()), + intval($scale), + intval($profile), + dbesc($allow_cid), + dbesc($allow_gid), + dbesc($deny_cid), + dbesc($deny_gid) + ); + return $r; + } + + + + + }} + +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, 'Contact Photos', 4 ); + + if($r === false) + $photo_failure = true; + + $img->scaleImage(80); + + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 ); + + if($r === false) + $photo_failure = true; + + $img->scaleImage(48); + + $r = $img->store($uid, $cid, $hash, $filename, '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)); + +}