diff options
author | Mike Macgirvin <mike@macgirvin.com> | 2010-10-26 14:50:38 -0700 |
---|---|---|
committer | Mike Macgirvin <mike@macgirvin.com> | 2010-10-26 14:50:38 -0700 |
commit | d2e20d029ab603479400393ea4d6fb0e8be9a5eb (patch) | |
tree | 669a6a890dcfd95f2b190e3d6887df10af20033a /include/Photo.php | |
parent | c16f314ec348205f4741e0171335168720e652d2 (diff) | |
download | volse-hubzilla-d2e20d029ab603479400393ea4d6fb0e8be9a5eb.tar.gz volse-hubzilla-d2e20d029ab603479400393ea4d6fb0e8be9a5eb.tar.bz2 volse-hubzilla-d2e20d029ab603479400393ea4d6fb0e8be9a5eb.zip |
de-duplicate photo importation logic
Diffstat (limited to 'include/Photo.php')
-rw-r--r-- | include/Photo.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/Photo.php b/include/Photo.php index e418cde46..ca9ae0703 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -208,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)); + +} |