diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-17 09:45:23 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-17 09:45:23 +0000 |
commit | 71d3cdc4f8b21cfa8ffd69746b80bfe18ed54c18 (patch) | |
tree | 8af800eb7da9e2c2826491ede08abd80e2b68e9c /engine | |
parent | e529507118a057b908016b823f4307661f861ee7 (diff) | |
download | elgg-71d3cdc4f8b21cfa8ffd69746b80bfe18ed54c18.tar.gz elgg-71d3cdc4f8b21cfa8ffd69746b80bfe18ed54c18.tar.bz2 |
Fixed #33 - all profile icons except for the largest size are cropped to squares. Additionally, the image resampling functions now take an extra boolean parameter to specify squareness (or not).
git-svn-id: https://code.elgg.org/elgg/trunk@943 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/filestore.php | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index 33f5cbaaf..061fe9f4f 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -593,13 +593,14 @@ * @param string $input_name The name of the file input field on the submission form
* @param int $maxwidth The maximum width of the resized image
* @param int $maxheight The maximum height of the resized image
+ * @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_uploaded_file($input_name, $maxwidth, $maxheight) {
+ function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false) {
// If our file exists ...
if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
- return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight); + return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square); } @@ -612,10 +613,11 @@ * * @param string $input_name The name of the file input field on the submission form * @param int $maxwidth The maximum width of the resized image - * @param int $maxheight The maximum height of the resized image + * @param int $maxheight The maximum height of the resized image
+ * @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) { + function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false) { // Get the size information from the image if ($imgsizearray = getimagesize($input_name)) { @@ -628,6 +630,19 @@ $height = $imgsizearray[1]; $newwidth = $width; $newheight = $height; +
+ // Square the image dimensions if we're wanting a square image
+ if ($square) {
+ if ($width < $height) {
+ $height = $width;
+ } else {
+ $width = $height;
+ }
+
+ $newwidth = $width;
+ $newheight = $height;
+
+ }
if ($width > $maxwidth) { $newheight = floor($height * ($maxwidth / $width)); @@ -648,11 +663,22 @@ if (array_key_exists($imgsizearray['mime'],$accepted_formats)) { $function = "imagecreatefrom" . $accepted_formats[$imgsizearray['mime']]; - $newimage = imagecreatetruecolor($newwidth,$newheight); - if (is_callable($function) && $oldimage = $function($input_name)) { + $newimage = imagecreatetruecolor($newwidth,$newheight);
- // Resize and return the image contents! - imagecopyresampled($newimage, $oldimage, 0,0,0,0,$newwidth,$newheight,$width,$height); + if (is_callable($function) && $oldimage = $function($input_name)) { +
+ // Crop the image if we need a square
+ if ($square) {
+ $widthoffset = floor(($imgsizearray[0] - $width) / 2);
+ $heightoffset = floor(($imgsizearray[1] - $height) / 2);
+ } else {
+ $widthoffset = 0;
+ $heightoffset = 0;
+ }//else { + // Resize and return the image contents! + imagecopyresampled($newimage, $oldimage, 0,0,$widthoffset,$heightoffset,$newwidth,$newheight,$width,$height);
+ //}
+ // imagecopyresized($newimage, $oldimage, 0,0,0,0,$newwidth,$newheight,$width,$height); ob_start(); imagejpeg($newimage, null, 90); |