summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/grouplogo.php44
-rwxr-xr-xclasses/User_group.php29
2 files changed, 52 insertions, 21 deletions
diff --git a/actions/grouplogo.php b/actions/grouplogo.php
index ba9cdfe2a..d8f7a9353 100644
--- a/actions/grouplogo.php
+++ b/actions/grouplogo.php
@@ -364,7 +364,7 @@ class GrouplogoAction extends Action
$this->mode = 'crop';
- $this->showForm(_('Pick a square area of the image to be your avatar'),
+ $this->showForm(_('Pick a square area of the image to be the logo.'),
true);
}
@@ -377,7 +377,6 @@ class GrouplogoAction extends Action
function cropLogo()
{
$user = common_current_user();
-
$profile = $user->getProfile();
$filedata = $_SESSION['FILEDATA'];
@@ -387,11 +386,6 @@ class GrouplogoAction extends Action
return;
}
- $x = $this->arg('avatar_crop_x');
- $y = $this->arg('avatar_crop_y');
- $w = ($this->arg('avatar_crop_w')) ? $this->arg('avatar_crop_w') : $filedata['width'];
- $h = ($this->arg('avatar_crop_h')) ? $this->arg('avatar_crop_h') : $filedata['height'];
-
$filepath = common_avatar_path($filedata['filename']);
if (!file_exists($filepath)) {
@@ -414,17 +408,39 @@ class GrouplogoAction extends Action
return;
}
- $size = ($w > MAX_ORIGINAL) ? MAX_ORIGINAL : $w;
+ // If image is not being cropped assume pos & dimentions of original
+ $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x'):0;
+ $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y'):0;
+ $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w'):$filedata['width'];
+ $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$filedata['height'];
+ $size = ($dest_w > MAX_ORIGINAL) ? MAX_ORIGINAL : $dest_w;
+
+ common_debug("W = $dest_w, H = $dest_h, X = $dest_x, Y = $dest_y, size = $size");
$image_dest = imagecreatetruecolor($size, $size);
+
+ if ($filedata['type'] == IMAGETYPE_GIF || $filedata['type'] == IMAGETYPE_PNG) {
+
+ $transparent_idx = imagecolortransparent($image_src);
+
+ if ($transparent_idx >= 0) {
- $background = imagecolorallocate($image_dest, 0, 0, 0);
- ImageColorTransparent($image_dest, $background);
- imagealphablending($image_dest, false);
+ $transparent_color = imagecolorsforindex($image_src, $transparent_idx);
+ $transparent_idx = imagecolorallocate($image_dest, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
+ imagefill($image_dest, 0, 0, $transparent_idx);
+ imagecolortransparent($image_dest, $transparent_idx);
+
+ } elseif ($filedata['type'] == IMAGETYPE_PNG) {
+
+ imagealphablending($image_dest, false);
+ $transparent = imagecolorallocatealpha($image_dest, 0, 0, 0, 127);
+ imagefill($image_dest, 0, 0, $transparent);
+ imagesavealpha($image_dest, true);
+
+ }
+ }
- imagecopyresized($image_dest, $image_src,
- 0, 0, $x, $y,
- $size, $size, $w, $h);
+ imagecopyresampled($image_dest, $image_src, 0, 0, $dest_x, $dest_y, $size, $size, $dest_w, $dest_h);
$filename = common_avatar_filename($this->group->id,
image_type_to_extension($filedata['type']),
diff --git a/classes/User_group.php b/classes/User_group.php
index 522dd8143..092c1bc34 100755
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -132,14 +132,29 @@ class User_group extends Memcached_DataObject
}
$image_dest = imagecreatetruecolor($size, $size);
+
+ if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_PNG) {
+
+ $transparent_idx = imagecolortransparent($image_src);
+
+ if ($transparent_idx >= 0) {
+
+ $transparent_color = imagecolorsforindex($image_src, $transparent_idx);
+ $transparent_idx = imagecolorallocate($image_dest, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
+ imagefill($image_dest, 0, 0, $transparent_idx);
+ imagecolortransparent($image_dest, $transparent_idx);
+
+ } elseif ($type == IMAGETYPE_PNG) {
+
+ imagealphablending($image_dest, false);
+ $transparent = imagecolorallocatealpha($image_dest, 0, 0, 0, 127);
+ imagefill($image_dest, 0, 0, $transparent);
+ imagesavealpha($image_dest, true);
+
+ }
+ }
- $background = imagecolorallocate($image_dest, 0, 0, 0);
- ImageColorTransparent($image_dest, $background);
- imagealphablending($image_dest, false);
-
- imagecopyresized($image_dest, $image_src,
- 0, 0, 0, 0,
- $size, $size, $info[0], $info[1]);
+ imagecopyresampled($image_dest, $image_src, 0, 0, 0, 0, $size, $size, $info[0], $info[1]);
$outname = common_avatar_filename($this->id,
image_type_to_extension($type),