4images Help / Hilfe > Bug Fixes & Patches

[FIX] Max height has no affect when do image resize

(1/6) > >>

V@no:
If u set max width bigger then max height in the settings and tryed to resize an image witch width is smaller then height, after resize it height will be equal to max width, but bigger then max height.
This is because 4images uses max width as max dimentions when resizing images.

To correct this and resize images acording your max widht AND max height, do this:

Step 1
Open includes/image_utils.php
Find:
--- Code: ---
function get_width_height($dimension, $width, $height, $resize_type = 1) {
  if ($resize_type == 2) {
    $new_width = $dimension;
    $new_height = floor(($dimension/$width) * $height);
  }
  elseif ($resize_type == 3) {
    $new_width = floor(($dimension/$height) * $width);
    $new_height = $dimension;
  }
  else {
    $ratio = $width / $height;
    if ($ratio > 1) {
      $new_width = $dimension;
      $new_height = floor(($dimension/$width) * $height);
    }
    else {
      $new_width = floor(($dimension/$height) * $width);
      $new_height = $dimension;
    }
  }
  return array("width" => $new_width, "height" => $new_height);
}
--- End code ---


Replace it with:

--- Code: ---function get_width_height($dimension, $width, $height, $resize_type = 1, $max_height = false) {
  $max_width = $dimension;
  $max_height = ($max_height === false) ? $max_width : $max_height;
  if ($resize_type == 2)
  {
    $new_width = $max_width;
    $new_height = floor(($max_width/$width) * $height);
  }
  elseif ($resize_type == 3)
  {
    $new_width = floor(($max_height/$height) * $width);
    $new_height = $max_height;
  }
  else
  {
    $new_width = $width;
    $new_height = $height;
    if ($width > $max_width || $height > $max_height)
    {
      $scale = min($max_width/$width, $max_height/$height);
      $new_width = floor($scale*$width);
      $new_height = floor($scale*$height);
    }
  }
  return array("width" => $new_width, "height" => $new_height);
}

--- End code ---




Step 1.2
Find:

--- Code: ---function resize_image($file, $quality, $dimension, $resize_type = 1) {
--- End code ---


Replace it with:

--- Code: ---function resize_image($file, $quality, $dimension, $resize_type = 1, $height = false) {
--- End code ---




Step 1.3
Find:

--- Code: ---  $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
--- End code ---


Replace it with:

--- Code: ---  $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type, $height);
--- End code ---





Step 2
Open admin/resizer.php
Find:

--- Code: ---  $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : 200;
  $resize_type = (isset($HTTP_POST_VARS['resize_type'])) ? intval($HTTP_POST_VARS['resize_type']) : 1;
--- End code ---


Replace it with:

--- Code: ---  $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : $config['max_image_width'];
  $height = (isset($HTTP_POST_VARS['height'])) ? intval($HTTP_POST_VARS['height']) : $config['max_image_height'];
  $resize_type = (isset($HTTP_POST_VARS['resize_type'])) ? intval($HTTP_POST_VARS['resize_type']) : $config['auto_thumbnail_resize_type'];
--- End code ---




Step 2.2
Find:

--- Code: ---  $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : 200;
  $resize_type = (isset($HTTP_POST_VARS['resize_type'])) ? intval($HTTP_POST_VARS['resize_type']) : 1;
--- End code ---


Replace it with:

--- Code: ---  $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : $config['max_image_width'];
  $height = (isset($HTTP_POST_VARS['height'])) ? intval($HTTP_POST_VARS['height']) : $config['max_image_height'];
  $resize_type = (isset($HTTP_POST_VARS['resize_type'])) ? intval($HTTP_POST_VARS['resize_type']) : $config['auto_thumbnail_resize_type'];
--- End code ---




Step 2.3
Find:

--- Code: ---  show_input_row($lang['resize_dimension_desc'], "dimension", $dimension);
--- End code ---


Replace it with:

--- Code: ---  show_input_row($lang['max_imagewidth'], "dimension", $dimension);
  show_input_row($lang['max_imageheight'], "height", $height);
--- End code ---




Step 2.4
Find:

--- Code: ---  $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : 200;
--- End code ---


Replace it with:

--- Code: ---  $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : $config['max_image_height'];
  $height = (isset($HTTP_POST_VARS['height'])) ? intval($HTTP_POST_VARS['height']) : $config['max_image_height'];
--- End code ---



Step 2.5
Find:

--- Code: ---          if ($resize_type == 1 && ($image_info[0] > $dimension || $image_info[1] > $dimension)) {
--- End code ---


Replace it with:

--- Code: ---          if ($resize_type == 1 && ($image_info[0] > $dimension || $image_info[1] > $height)) {
--- End code ---




Step 2.6
Find:

--- Code: ---          elseif ($resize_type == 3 && $image_info[1] > $dimension) {
--- End code ---


Replace it with:

--- Code: ---          elseif ($resize_type == 3 && $image_info[1] > $height) {
--- End code ---




Step 2.7
Find:

--- Code: ---            $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
--- End code ---


Replace it with:

--- Code: ---            $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type, $height);
--- End code ---




Step 2.8
Find:

--- Code: ---    show_hidden_input("dimension", $dimension);
--- End code ---


Add above:

--- Code: ---    show_hidden_input("height", $height);
--- End code ---

vanish:
This MOD don't working  :(
After install it resizing function don't work...

V@no:
doesnt work HOW?

vanish:
1. Apply all changes - try to resize image - have success message - go to view image - image has old size....
2. Discard all changes - try to resize image - have success message - go to view image - image has NEW size....

In both cases I set height to resize

V@no:
what is your max width and max height settings and what is your original image dimmentions u were testing with?

Navigation

[0] Message Index

[#] Next page

Go to full version