Skip to content

Commit

Permalink
Fixes #2499 - fixed resize of non square tall images and resizing of …
Browse files Browse the repository at this point in the history
…images not allowed to be upscaled

git-svn-id: http://code.elgg.org/elgg/branches/1.7@6990 36083f99-b078-4883-b0ff-0f9b5a30f544
  • Loading branch information
cash committed Oct 1, 2010
1 parent 8c8b8d8 commit f69dde3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
31 changes: 14 additions & 17 deletions engine/lib/filestore.php
Expand Up @@ -758,12 +758,13 @@ function get_uploaded_file($input_name) {
* @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.
* @param true|false $upscale Resize images smaller than $maxwidth x $maxheight?
* @return false|mixed The contents of the resized image, or false on failure
*/
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false) {
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = 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, $square);
return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
}
return false;
}
Expand Down Expand Up @@ -937,7 +938,7 @@ function get_image_resize_parameters($width, $height, $options) {
} else {
// non-square new image
$new_width = $maxwidth;
$new_height = $maxwidth;
$new_height = $maxheight;

// maintain aspect ratio of original image/crop
if (($selection_height / (float)$new_height) > ($selection_width / (float)$new_width)) {
Expand All @@ -956,21 +957,17 @@ function get_image_resize_parameters($width, $height, $options) {
}
}

// check for upscaling
if (!$upscale && ($height < $new_height || $width < $new_width)) {
// determine if we can scale it down at all
// (ie, if only one dimension is too small)
// if not, just use original size.
if ($height < $new_height && $width < $new_width) {
$ratio = 1;
} elseif ($height < $new_height) {
$ratio = $new_width / $width;
} elseif ($width < $new_width) {
$ratio = $new_height / $height;
if (!$upscale && ($selection_height < $new_height || $selection_width < $new_width)) {
// we cannot upscale and selected area is too small so we decrease size of returned image
if ($square) {
$new_height = $selection_height;
$new_width = $selection_width;
} else {
if ($selection_height < $new_height && $selection_width < $new_width) {
$new_height = $selection_height;
$new_width = $selection_width;
}
}

$selection_height = $height;
$selection_width = $width;
}

$params = array(
Expand Down
8 changes: 4 additions & 4 deletions mod/profile/actions/iconupload.php
Expand Up @@ -24,10 +24,10 @@
) {


$topbar = get_resized_image_from_uploaded_file('profileicon',16,16, true);
$tiny = get_resized_image_from_uploaded_file('profileicon',25,25, true);
$small = get_resized_image_from_uploaded_file('profileicon',40,40, true);
$medium = get_resized_image_from_uploaded_file('profileicon',100,100, true);
$topbar = get_resized_image_from_uploaded_file('profileicon',16,16, true, true);
$tiny = get_resized_image_from_uploaded_file('profileicon',25,25, true, true);
$small = get_resized_image_from_uploaded_file('profileicon',40,40, true, true);
$medium = get_resized_image_from_uploaded_file('profileicon',100,100, true, true);
$large = get_resized_image_from_uploaded_file('profileicon',200,200);
$master = get_resized_image_from_uploaded_file('profileicon',550,550);

Expand Down

0 comments on commit f69dde3

Please sign in to comment.