summaryrefslogtreecommitdiff
path: root/actions/grouplogo.php
diff options
context:
space:
mode:
authorSean Murphy <sgmurphy@gmail.com>2009-02-04 14:44:12 -0500
committerSean Murphy <sgmurphy@gmail.com>2009-02-04 14:44:12 -0500
commit5c880bc6cc34793c2eb87697e4ca66ca2e6e12f9 (patch)
tree3d9eeaf897463f35ed283fcd0111b8ea40a1f575 /actions/grouplogo.php
parent22c806a15a957c300cb047cb42e8f5c49d47afa9 (diff)
Fix for #1057; group logo transparecy (and pixilation)
Diffstat (limited to 'actions/grouplogo.php')
-rw-r--r--actions/grouplogo.php44
1 files changed, 30 insertions, 14 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']),