X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FPhoto.php;h=9934b9a3928f2e79ec060ede1cb55f547718f4ef;hb=de131c9e58ac2b14380d145d643bf2bd902ae9dc;hp=0f5003a6f7839b7f24f8e92a117ac5eab633bed3;hpb=adce88e564f2e9a6c8487bf23762afe1413ed263;p=friendica.git diff --git a/include/Photo.php b/include/Photo.php index 0f5003a6f7..9934b9a392 100644 --- 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; } @@ -168,8 +175,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` ) @@ -181,9 +187,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), @@ -201,3 +207,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)); + +}