diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-23 21:05:35 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-23 21:05:35 +0000 |
commit | d53280ff80b672255a8ae2469a668f3b8f63977f (patch) | |
tree | 7823d86eb3f273452c246edc5477901e9bf3696c | |
parent | 7172a9c77c3885e889208693f0f1044b6d502eaa (diff) | |
download | elgg-d53280ff80b672255a8ae2469a668f3b8f63977f.tar.gz elgg-d53280ff80b672255a8ae2469a668f3b8f63977f.tar.bz2 |
Image cropping works!
git-svn-id: https://code.elgg.org/elgg/trunk@1082 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/filestore.php | 24 | ||||
-rw-r--r-- | mod/profile/actions/iconupload.php | 3 | ||||
-rw-r--r-- | mod/profile/languages/en.php | 3 | ||||
-rw-r--r-- | mod/profile/start.php | 1 | ||||
-rw-r--r-- | mod/profile/views/default/profile/editicon.php | 19 |
5 files changed, 36 insertions, 14 deletions
diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index 061fe9f4f..dcf802cd5 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -617,7 +617,7 @@ * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped. * @return false|mixed The contents of the resized image, or false on failure */ - function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false) { + function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) { // Get the size information from the image if ($imgsizearray = getimagesize($input_name)) { @@ -669,11 +669,25 @@ // Crop the image if we need a square
if ($square) {
- $widthoffset = floor(($imgsizearray[0] - $width) / 2);
- $heightoffset = floor(($imgsizearray[1] - $height) / 2);
+ if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
+ $widthoffset = floor(($imgsizearray[0] - $width) / 2);
+ $heightoffset = floor(($imgsizearray[1] - $height) / 2);
+ } else {
+ $widthoffset = $x1;
+ $heightoffset = $y1;
+ $width = ($x2 - $x1);
+ $height = $width;
+ }
} else {
- $widthoffset = 0;
- $heightoffset = 0;
+ if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
+ $widthoffset = 0;
+ $heightoffset = 0;
+ } else {
+ $widthoffset = $x1;
+ $heightoffset = $y1;
+ $width = ($x2 - $x1);
+ $height = ($y2 - $y1);
+ }
}//else { // Resize and return the image contents! imagecopyresampled($newimage, $oldimage, 0,0,$widthoffset,$heightoffset,$newwidth,$newheight,$width,$height);
diff --git a/mod/profile/actions/iconupload.php b/mod/profile/actions/iconupload.php index 8dcfeea36..bb3b19528 100644 --- a/mod/profile/actions/iconupload.php +++ b/mod/profile/actions/iconupload.php @@ -23,7 +23,8 @@ if ($small !== false
&& $medium !== false
- && $large !== false) {
+ && $large !== false
+ && $tiny !== false) {
$filehandler = new ElggFile();
$filehandler->owner_guid = $_SESSION['user']->getGUID();
diff --git a/mod/profile/languages/en.php b/mod/profile/languages/en.php index 4074b2d53..40d5bb0ac 100644 --- a/mod/profile/languages/en.php +++ b/mod/profile/languages/en.php @@ -22,6 +22,9 @@ 'profile:edit' => "Edit profile",
'profile:editicon' => "Change your profile picture",
+ 'profile:icon' => "Profile icon",
+ 'profile:createicon' => "Create your avatar",
+ 'profile:createicon:instructions' => "Click and drag to crop your image",
'profile:aboutme' => "About me",
'profile:description' => "About me",
diff --git a/mod/profile/start.php b/mod/profile/start.php index 63b579784..0cd8f2100 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -119,6 +119,7 @@ global $CONFIG;
register_action("profile/edit",false,$CONFIG->pluginspath . "profile/actions/edit.php");
register_action("profile/iconupload",false,$CONFIG->pluginspath . "profile/actions/iconupload.php");
+ register_action("profile/cropicon",false,$CONFIG->pluginspath . "profile/actions/cropicon.php");
// Define widgets for use in this context
use_widgets('profile');
diff --git a/mod/profile/views/default/profile/editicon.php b/mod/profile/views/default/profile/editicon.php index f6a863ab7..7bc142a26 100644 --- a/mod/profile/views/default/profile/editicon.php +++ b/mod/profile/views/default/profile/editicon.php @@ -35,7 +35,7 @@ <?php
- echo "Your current master photo: <br />";
+ echo elgg_echo("profile:createicon:instructions") . ": <br />";
//display the current user photo
$user_master_image = $vars['url'] . "pg/icon/" . $_SESSION['user']->username . "/master/" . $_SESSION['user']->icontime . ".jpg";
@@ -106,9 +106,11 @@ </script>
<p>
-<img id="user_avatar" src="<?php echo $user_master_image; ?>" alt="User profile photo"
+<img id="user_avatar" src="<?php echo $user_master_image; ?>" alt="<?php echo elgg_echo("profile:icon"); ?>"
style="float: left; margin-right: 10px;" />
+ <br />
</p>
+
<div style="float: right; margin-left: 10px; margin-top:-200px;">
<p style="background: #eee; border: solid 1px #ddd; margin: 0; padding: 10px;">
<b>Selection coordinates:</b><br />
@@ -126,10 +128,11 @@ </p>
</div>
-<form name="" action="" />
- <input type="hidden" name="x_1" value="" id="x_1" />
- <input type="hidden" name="x_2" value="" id="x_2" />
- <input type="hidden" name="y_1" value="" id="y_1" />
- <input type="hidden" name="y_2" value="" id="y_2" />
- <input type="submit" name="submit" value="create your avatar" />
+<form action="<?php echo $vars['url']; ?>action/profile/cropicon" method="post" />
+ <input type="hidden" name="username" value="<?php echo $vars['user']->username; ?>" />
+ <input type="hidden" name="x_1" value="<?php echo $vars['user']->x1; ?>" id="x_1" />
+ <input type="hidden" name="x_2" value="<?php echo $vars['user']->x2; ?>" id="x_2" />
+ <input type="hidden" name="y_1" value="<?php echo $vars['user']->y1; ?>" id="y_1" />
+ <input type="hidden" name="y_2" value="<?php echo $vars['user']->y2; ?>" id="y_2" />
+ <input type="submit" name="submit" value="<?php echo elgg_echo("profile:createicon"); ?>" />
</form>
\ No newline at end of file |