From 6b51941056a361327e8717ede1194df3abe430a9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 11 Dec 2008 23:30:18 -0500 Subject: [PATCH] Actually crop your avatar when hitting 'crop' button on profile darcs-hash:20081212043018-7b5ce-bc83b66e19007aa0a04fbb40053217ef92c44779.gz --- _darcs/inventory | 4 +- ...c83b66e19007aa0a04fbb40053217ef92c44779.gz | Bin 0 -> 2062 bytes _darcs/patches/unrevert | 223 +++++++++++++++--- _darcs/pristine/classes/Avatar.php | 34 ++- _darcs/pristine/classes/Profile.php | 19 +- _darcs/tentative_inventory | 4 +- classes/Avatar.php | 34 ++- classes/Profile.php | 19 +- 8 files changed, 249 insertions(+), 88 deletions(-) create mode 100644 _darcs/patches/20081212043018-7b5ce-bc83b66e19007aa0a04fbb40053217ef92c44779.gz diff --git a/_darcs/inventory b/_darcs/inventory index 0b89ad9627..da63f8216a 100644 --- a/_darcs/inventory +++ b/_darcs/inventory @@ -122,4 +122,6 @@ Zach Copley **20090105045603] [Jcrop v2 (POST cropping to be completed) csarven@controlyourself.ca**20081210021607] [Jcrop CSS updates to original/preview views -csarven@controlyourself.ca**20081210025922] \ No newline at end of file +csarven@controlyourself.ca**20081210025922] +[Actually crop your avatar when hitting 'crop' button on profile +Zach Copley **20081212043018] \ No newline at end of file diff --git a/_darcs/patches/20081212043018-7b5ce-bc83b66e19007aa0a04fbb40053217ef92c44779.gz b/_darcs/patches/20081212043018-7b5ce-bc83b66e19007aa0a04fbb40053217ef92c44779.gz new file mode 100644 index 0000000000000000000000000000000000000000..51acb509bdb7a2284b6bab070fc8b5d6bafeef63 GIT binary patch literal 2062 zcmV+p2=VtHiwFP!000001MOM)Z`(E${@M8}xYVfR#aEK1N3wLwy0*yB3vIRmD++;; zXiJSmX%ZF38}h&J@ziNsNrnv=;-*MUKE8_|-}@+iK5WbtVWo#%|j6v0oD#NC&L#`?#;cV>U z=ih$2H=RD+-P_%pKH8t|KK+9J+KNazCn=har^v2;@pF2C#uMzaAg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hl!67e>_A9bZt6|`8FnTmIdd~kDf`NR}z#@q1;hDht{flipIkOtLk_AXf}RtD?C5$b65s$NbN2 zbO?Vzing^5ec&5aK~HG)iZwWa2R?vh7^>&OMbId1y^i+RBtE zP%UgjEKKN4Rj5pGbSH#^<)RZHVR3Kday)spIe8Ua zF=@!^u>@6Zx|HCKh$w#tSd{8sO?3$(CU-RvxPmtT1Y@OK*A~dS&`7rP0%wqM&MVIV zPf!8S1EeT8;s`4N%jgOykZ@)j%BqT@7HHz6T7l(rNsa=2FOlD?HWYu>Q%@FI&yVQ|oxb2lxxNHPtLvAnQMr zg>QU0PwW<%>V!Z literal 0 HcmV?d00001 diff --git a/_darcs/patches/unrevert b/_darcs/patches/unrevert index 3748132458..f112ac9a51 100644 --- a/_darcs/patches/unrevert +++ b/_darcs/patches/unrevert @@ -2,43 +2,45 @@ New patches: [unrevert -anonymous**20090106212612] { -hunk ./actions/profilesettings.php 140 - common_local_url('profilesettings'))); - common_hidden('token', common_session_token()); +anonymous**20090106212613] { +hunk ./actions/profilesettings.php 57 + return; + } +v v v v v v v - if ($original) { -hunk ./actions/profilesettings.php 142 -+ common_element_start('div', array('id'=>'avatar_original', 'class'=>'avatar_view')); -+ common_element('h3', null, _("Original:")); -+ common_element_start('div', array('id'=>'avatar_original_view')); - common_element('img', array('src' => $original->url, - 'class' => 'avatar original', - 'width' => $original->width, -hunk ./actions/profilesettings.php 150 - 'height' => $original->height, - 'alt' => $user->nickname)); -+ common_element_end('div'); -+ common_element_end('div'); + if ($this->arg('save')) { + $this->save_profile(); + } else if ($this->arg('upload')) { +hunk ./actions/profilesettings.php 62 + $this->upload_avatar(); ++ } else if ($this->arg('crop')) { ++ $this->crop_avatar(); + } else if ($this->arg('changepass')) { + $this->change_password(); +hunk ./actions/profilesettings.php 66 ++ } else { ++ $this->show_form(_('Unexpected form submission.')); } -hunk ./actions/profilesettings.php 153 +hunk ./actions/profilesettings.php 69 +************* -+ if ($original) { -+ common_element('img', array('src' => $original->url, -+ 'class' => 'avatar original', -+ 'width' => $original->width, -+ 'height' => $original->height, -+ 'alt' => $user->nickname)); ++ if ($this->arg('save')) { ++ $this->save_profile(); ++ } else if ($this->arg('upload')) { ++ $this->upload_avatar(); ++ } else if ($this->arg('changepass')) { ++ $this->change_password(); + } +^ ^ ^ ^ ^ ^ ^ + } + +hunk ./actions/profilesettings.php 164 + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); -hunk ./actions/profilesettings.php 165 +v v v v v v v if ($avatar) { -hunk ./actions/profilesettings.php 167 +hunk ./actions/profilesettings.php 166 - common_element('img', array('src' => $avatar->url, + common_element_start('div', array('id'=>'avatar_preview', 'class'=>'avatar_view')); + common_element('h3', null, _("Preview:")); @@ -47,7 +49,7 @@ hunk ./actions/profilesettings.php 167 'class' => 'avatar profile', 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, -hunk ./actions/profilesettings.php 175 +hunk ./actions/profilesettings.php 174 'alt' => $user->nickname)); + common_element_end('div'); + common_element_end('div'); @@ -57,9 +59,9 @@ hunk ./actions/profilesettings.php 175 + 'type' => 'hidden', + 'id' => $crop_info)); + } -+ common_submit('avatar_crop', _('Crop')); ++ common_submit('crop', _('Crop')); } -hunk ./actions/profilesettings.php 185 +hunk ./actions/profilesettings.php 184 +************* + if ($avatar) { + common_element('img', array('src' => $avatar->url, @@ -72,10 +74,171 @@ hunk ./actions/profilesettings.php 185 common_element('input', array('name' => 'MAX_FILE_SIZE', +hunk ./actions/profilesettings.php 429 + $this->show_form(_('Failed updating avatar.')); + } + ++v v v v v v v + @unlink($_FILES['avatarfile']['tmp_name']); + } + +hunk ./actions/profilesettings.php 433 ++ function crop_avatar() { ++ ++ $user = common_current_user(); ++ $profile = $user->getProfile(); ++ ++ $x = $this->arg('avatar_crop_x'); ++ $y = $this->arg('avatar_crop_y'); ++ $w = $this->arg('avatar_crop_w'); ++ $h = $this->arg('avatar_crop_h'); ++ ++ if ($profile->crop_avatars($x, $y, $w, $h)) { ++ $this->show_form(_('Avatar updated.'), true); ++ } else { ++ $this->show_form(_('Failed updating avatar.')); ++ } ++ } ++************* ++ @unlink($_FILES['avatarfile']['tmp_name']); ++ } ++^ ^ ^ ^ ^ ^ ^ ++ + function nickname_exists($nickname) + { + $user = common_current_user(); +hunk ./classes/Avatar.php 82 + } + } + ++v v v v v v v ++ function scale_and_crop($size, $x, $y, $w, $h) { ++ ++ $image_s = imagecreatetruecolor($size, $size); ++ $image_a = $this->to_image(); ++ ++ # Retain alpha channel info if possible for .pngs ++ $background = imagecolorallocate($image_s, 0, 0, 0); ++ ImageColorTransparent($image_s, $background); ++ imagealphablending($image_s, false); ++ ++ imagecopyresized($image_s, $image_a, 0, 0, $x, $y, $size, $size, $w, $h); ++ ++ $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png"; ++ ++ $filename = common_avatar_filename($this->profile_id, $ext, $size, common_timestamp()); ++ ++ if ($this->mediatype == 'image/jpeg') { ++ imagejpeg($image_s, common_avatar_path($filename)); ++ } else { ++ imagepng($image_s, common_avatar_path($filename)); ++ } ++ ++ $cropped = DB_DataObject::factory('avatar'); ++ $cropped->profile_id = $this->profile_id; ++ $cropped->width = $size; ++ $cropped->height = $size; ++ $cropped->original = false; ++ $cropped->mediatype = ($this->mediattype == 'image/jpeg') ? 'image/jpeg' : 'image/png'; ++ $cropped->filename = $filename; ++ $cropped->url = common_avatar_url($filename); ++ $cropped->created = DB_DataObject_Cast::dateTime(); # current time ++ ++ if ($cropped->insert()) { ++ return $cropped; ++ } else { ++ return NULL; ++ } ++ } ++ + function to_image() { + $filepath = common_avatar_path($this->filename); + if ($this->mediatype == 'image/gif') { +hunk ./classes/Avatar.php 138 + function &pkeyGet($kv) { + return Memcached_DataObject::pkeyGet('Avatar', $kv); + } ++************* ++ function to_image() ++ { ++ $filepath = common_avatar_path($this->filename); ++ if ($this->mediatype == 'image/gif') { ++ return imagecreatefromgif($filepath); ++ } else if ($this->mediatype == 'image/jpeg') { ++ return imagecreatefromjpeg($filepath); ++ } else if ($this->mediatype == 'image/png') { ++ return imagecreatefrompng($filepath); ++ } else { ++ return null; ++ } ++ } ++ ++ function &pkeyGet($kv) ++ { ++ return Memcached_DataObject::pkeyGet('Avatar', $kv); ++ } ++^ ^ ^ ^ ^ ^ ^ + } +hunk ./classes/Profile.php 124 + return $avatar; + } + +- function delete_avatars() { ++v v v v v v v ++ function crop_avatars($x, $y, $w, $h) { ++ ++ $avatar = $this->getOriginalAvatar(); ++ $this->delete_avatars(false); # don't delete original ++ ++ foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { ++ # We don't do a scaled one if original is our scaled size ++ if (!($avatar->width == $size && $avatar->height == $size)) { ++ $s = $avatar->scale_and_crop($size, $x, $y, $w, $h); ++ if (!$s) { ++ return NULL; ++ } ++ } ++ } ++ return true; ++ } ++ ++ function delete_avatars($original=true) { + $avatar = new Avatar(); + $avatar->profile_id = $this->id; + $avatar->find(); +hunk ./classes/Profile.php 147 + while ($avatar->fetch()) { ++ if ($avatar->original) { ++ if ($original == false) { ++ continue; ++ } ++ } + $avatar->delete(); + } + return true; +hunk ./classes/Profile.php 156 + } ++************* ++ function delete_avatars() ++ { ++ $avatar = new Avatar(); ++ $avatar->profile_id = $this->id; ++ $avatar->find(); ++ while ($avatar->fetch()) { ++ $avatar->delete(); ++ } ++ return true; ++ } ++^ ^ ^ ^ ^ ^ ^ + + function getBestName() + { } Context: +[Actually crop your avatar when hitting 'crop' button on profile +Zach Copley **20081212043018] [Jcrop CSS updates to original/preview views csarven@controlyourself.ca**20081210025922] [Jcrop v2 (POST cropping to be completed) @@ -201,4 +364,4 @@ Sarven Capadisli **20081218003302 [TAG 0.6.4.1 Evan Prodromou **20081220204906] Patch bundle hash: -b75aa06ac49c2ff8a9fa803da998c6ea5f5c1d17 +316173068f974bea2f9537d45d347f45c12050bc diff --git a/_darcs/pristine/classes/Avatar.php b/_darcs/pristine/classes/Avatar.php index 3c754ec2d5..4fdb99d35e 100644 --- a/_darcs/pristine/classes/Avatar.php +++ b/_darcs/pristine/classes/Avatar.php @@ -79,22 +79,20 @@ class Avatar extends Memcached_DataObject } } - function to_image() - { - $filepath = common_avatar_path($this->filename); - if ($this->mediatype == 'image/gif') { - return imagecreatefromgif($filepath); - } else if ($this->mediatype == 'image/jpeg') { - return imagecreatefromjpeg($filepath); - } else if ($this->mediatype == 'image/png') { - return imagecreatefrompng($filepath); - } else { - return null; - } - } - - function &pkeyGet($kv) - { - return Memcached_DataObject::pkeyGet('Avatar', $kv); - } + function to_image() { + $filepath = common_avatar_path($this->filename); + if ($this->mediatype == 'image/gif') { + return imagecreatefromgif($filepath); + } else if ($this->mediatype == 'image/jpeg') { + return imagecreatefromjpeg($filepath); + } else if ($this->mediatype == 'image/png') { + return imagecreatefrompng($filepath); + } else { + return NULL; + } + } + + function &pkeyGet($kv) { + return Memcached_DataObject::pkeyGet('Avatar', $kv); + } } diff --git a/_darcs/pristine/classes/Profile.php b/_darcs/pristine/classes/Profile.php index fb6ff90f1e..3b6ac1d7f2 100644 --- a/_darcs/pristine/classes/Profile.php +++ b/_darcs/pristine/classes/Profile.php @@ -121,16 +121,15 @@ class Profile extends Memcached_DataObject return $avatar; } - function delete_avatars() - { - $avatar = new Avatar(); - $avatar->profile_id = $this->id; - $avatar->find(); - while ($avatar->fetch()) { - $avatar->delete(); - } - return true; - } + function delete_avatars() { + $avatar = new Avatar(); + $avatar->profile_id = $this->id; + $avatar->find(); + while ($avatar->fetch()) { + $avatar->delete(); + } + return true; + } function getBestName() { diff --git a/_darcs/tentative_inventory b/_darcs/tentative_inventory index 0b89ad9627..da63f8216a 100644 --- a/_darcs/tentative_inventory +++ b/_darcs/tentative_inventory @@ -122,4 +122,6 @@ Zach Copley **20090105045603] [Jcrop v2 (POST cropping to be completed) csarven@controlyourself.ca**20081210021607] [Jcrop CSS updates to original/preview views -csarven@controlyourself.ca**20081210025922] \ No newline at end of file +csarven@controlyourself.ca**20081210025922] +[Actually crop your avatar when hitting 'crop' button on profile +Zach Copley **20081212043018] \ No newline at end of file diff --git a/classes/Avatar.php b/classes/Avatar.php index 3c754ec2d5..4fdb99d35e 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -79,22 +79,20 @@ class Avatar extends Memcached_DataObject } } - function to_image() - { - $filepath = common_avatar_path($this->filename); - if ($this->mediatype == 'image/gif') { - return imagecreatefromgif($filepath); - } else if ($this->mediatype == 'image/jpeg') { - return imagecreatefromjpeg($filepath); - } else if ($this->mediatype == 'image/png') { - return imagecreatefrompng($filepath); - } else { - return null; - } - } - - function &pkeyGet($kv) - { - return Memcached_DataObject::pkeyGet('Avatar', $kv); - } + function to_image() { + $filepath = common_avatar_path($this->filename); + if ($this->mediatype == 'image/gif') { + return imagecreatefromgif($filepath); + } else if ($this->mediatype == 'image/jpeg') { + return imagecreatefromjpeg($filepath); + } else if ($this->mediatype == 'image/png') { + return imagecreatefrompng($filepath); + } else { + return NULL; + } + } + + function &pkeyGet($kv) { + return Memcached_DataObject::pkeyGet('Avatar', $kv); + } } diff --git a/classes/Profile.php b/classes/Profile.php index fb6ff90f1e..3b6ac1d7f2 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -121,16 +121,15 @@ class Profile extends Memcached_DataObject return $avatar; } - function delete_avatars() - { - $avatar = new Avatar(); - $avatar->profile_id = $this->id; - $avatar->find(); - while ($avatar->fetch()) { - $avatar->delete(); - } - return true; - } + function delete_avatars() { + $avatar = new Avatar(); + $avatar->profile_id = $this->id; + $avatar->find(); + while ($avatar->fetch()) { + $avatar->delete(); + } + return true; + } function getBestName() { -- 2.39.5