]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2499 - merged [6990] into trunk from 1.7 branch
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 20 Oct 2010 11:48:37 +0000 (11:48 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 20 Oct 2010 11:48:37 +0000 (11:48 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7106 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/filestore.php
mod/profile/actions/iconupload.php

index a7f3957043dfa9390034455600be0aa136b05a4d..b9bf5bf395ff17c30213b2292e50541b72b152ec 100644 (file)
@@ -56,12 +56,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;
 }
@@ -235,7 +236,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)) {
@@ -254,21 +255,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(
index 23d1967a6b6c6de2081b4becc616091e15569090..fe4efbfeaae6a9025de441ab2970bd07ff8472ef 100644 (file)
@@ -23,19 +23,19 @@ $profile_owner_guid = $profile_owner->getGUID();
 
 //@todo make this configurable?
 $icon_sizes = array(
-       'topbar' => array('w'=>16, 'h'=>16, 'square'=>TRUE),
-       'tiny' => array('w'=>25, 'h'=>25, 'square'=>TRUE),
-       'small' => array('w'=>40, 'h'=>40, 'square'=>TRUE),
-       'medium' => array('w'=>100, 'h'=>100, 'square'=>TRUE),
-       'large' => array('w'=>200, 'h'=>200, 'square'=>FALSE),
-       'master' => array('w'=>1600, 'h'=>1600, 'square'=>FALSE)
+       'topbar' => array('w'=>16, 'h'=>16, 'square'=>TRUE, 'upscale'=>TRUE),
+       'tiny' => array('w'=>25, 'h'=>25, 'square'=>TRUE, 'upscale'=>TRUE),
+       'small' => array('w'=>40, 'h'=>40, 'square'=>TRUE, 'upscale'=>TRUE),
+       'medium' => array('w'=>100, 'h'=>100, 'square'=>TRUE, 'upscale'=>TRUE),
+       'large' => array('w'=>200, 'h'=>200, 'square'=>FALSE, 'upscale'=>FALSE),
+       'master' => array('w'=>1600, 'h'=>1600, 'square'=>FALSE, 'upscale'=>FALSE)
 );
 
 // get the images and save their file handlers into an array
 // so we can do clean up if one fails.
 $files = array();
 foreach ($icon_sizes as $name => $size_info) {
-       $resized = get_resized_image_from_uploaded_file('profileicon', $size_info['w'], $size_info['h'], $size_info['square']);
+       $resized = get_resized_image_from_uploaded_file('profileicon', $size_info['w'], $size_info['h'], $size_info['square'], $size_info['upscale']);
 
        if ($resized) {
                //@todo Make these actual entities.  See exts #348.