Author Topic: [FIX] Max height has no affect when do image resize  (Read 86877 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[FIX] Max height has no affect when do image resize
« on: March 27, 2005, 07:11:23 PM »
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: [Select]

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);
}


Replace it with:
Code: [Select]
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);
}




Step 1.2
Find:
Code: [Select]
function resize_image($file, $quality, $dimension, $resize_type = 1) {

Replace it with:
Code: [Select]
function resize_image($file, $quality, $dimension, $resize_type = 1, $height = false) {



Step 1.3
Find:
Code: [Select]
 $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);

Replace it with:
Code: [Select]
 $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type, $height);




Step 2
Open admin/resizer.php
Find:
Code: [Select]
 $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;


Replace it with:
Code: [Select]
 $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'];




Step 2.2
Find:
Code: [Select]
 $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;


Replace it with:
Code: [Select]
 $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'];




Step 2.3
Find:
Code: [Select]
 show_input_row($lang['resize_dimension_desc'], "dimension", $dimension);

Replace it with:
Code: [Select]
 show_input_row($lang['max_imagewidth'], "dimension", $dimension);
  show_input_row($lang['max_imageheight'], "height", $height);




Step 2.4
Find:
Code: [Select]
 $dimension = (isset($HTTP_POST_VARS['dimension'])) ? intval($HTTP_POST_VARS['dimension']) : 200;

Replace it with:
Code: [Select]
 $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'];



Step 2.5
Find:
Code: [Select]
         if ($resize_type == 1 && ($image_info[0] > $dimension || $image_info[1] > $dimension)) {

Replace it with:
Code: [Select]
         if ($resize_type == 1 && ($image_info[0] > $dimension || $image_info[1] > $height)) {



Step 2.6
Find:
Code: [Select]
         elseif ($resize_type == 3 && $image_info[1] > $dimension) {

Replace it with:
Code: [Select]
         elseif ($resize_type == 3 && $image_info[1] > $height) {



Step 2.7
Find:
Code: [Select]
           $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);

Replace it with:
Code: [Select]
           $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type, $height);



Step 2.8
Find:
Code: [Select]
   show_hidden_input("dimension", $dimension);

Add above:
Code: [Select]
   show_hidden_input("height", $height);
« Last Edit: March 23, 2010, 06:30:24 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [FIX] Max height has no affect when do image resize
« Reply #1 on: April 03, 2005, 11:41:07 PM »
This MOD don't working  :(
After install it resizing function don't work...

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [FIX] Max height has no affect when do image resize
« Reply #2 on: April 04, 2005, 12:25:19 AM »
doesnt work HOW?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [FIX] Max height has no affect when do image resize
« Reply #3 on: April 04, 2005, 08:47:10 AM »
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

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [FIX] Max height has no affect when do image resize
« Reply #4 on: April 04, 2005, 02:20:10 PM »
what is your max width and max height settings and what is your original image dimmentions u were testing with?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [FIX] Max height has no affect when do image resize
« Reply #5 on: April 04, 2005, 02:57:26 PM »
For example:
image - 580x700
1. Resize by width - set width 500 (not change height-1024), check correct radio button(by wigth) - GO! - correct new size in table (500x603) - GO!:
Result - fine! Picture is 500x603. Super...
continue with this picture...
2. Resize by height - set height 600 (not change width-1024), check correct radio button(by height) - GO! - correct new size in table (498x600) - GO!:
Result - WRONG! Picture is 849x1024. Bad...

3.If I set new height < image height and, check radio button proportionally images not changed

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [FIX] Max height has no affect when do image resize
« Reply #6 on: April 04, 2005, 03:26:54 PM »
Also after changes in image_utils.php I see problem after upload file...
Another image you can see on screen after upload procedure: Added one file (right file name), on screen -  another file

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [FIX] Max height has no affect when do image resize
« Reply #7 on: April 05, 2005, 09:48:43 PM »
V@no where are u? Why do u keep silent?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [FIX] Max height has no affect when do image resize
« Reply #8 on: April 06, 2005, 12:36:41 AM »
V@no where are u? Why do u keep silent?
because I dont have any sollution for u. This mod is working for me and many other people, so either u did something wrong, or u are trying install it on v1.7.1 which I havent test it on.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Olphi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: [FIX] Max height has no affect when do image resize
« Reply #9 on: January 07, 2006, 03:43:03 PM »
This MOD don't working  :(
After install it resizing function don't work...

I have the same problem, after installing this MOD, the resize function doesn't work anymore...
Think, it could be really a problem with the v1.7.1!  :wink:

Offline artistichideaway

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: [FIX] Max height has no affect when do image resize
« Reply #10 on: March 07, 2006, 10:53:36 AM »
It works for me perfect and I have 1.7.1. installed.
Thanks Vano.

Offline nobita

  • Jr. Member
  • **
  • Posts: 61
  • ondesktop.org
    • View Profile
    • Car Wallpapers
Re: [FIX] Max height has no affect when do image resize
« Reply #11 on: February 26, 2007, 02:17:50 PM »
Have any modifications to fix the same for thumbnail images?

Offline ebnifkin

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: [FIX] Max height has no affect when do image resize
« Reply #12 on: February 20, 2009, 07:35:41 PM »
V@no - FYI - I'm using v. 1.7.6, applied this fix twice, two different edit sessions, carefully, after applying the mod --Auto image resize on upload--. All is fine except for vertical resizing, which is resizing vertically at the horizontal max value instead of vertical max value (vertical size is too large) . Auto image resizer now has the same fault, whether I do proportional or forced vertical resizing. The latter, forced vertical resizing, did work correctly before.

Update: I dropped Step 2 edits and restored the original resizer.php file; the auto resizer now works, but new vertical pic uploads are still resized to the horizontal max pixel dimension.
« Last Edit: February 20, 2009, 07:49:05 PM by ebnifkin »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [FIX] Max height has no affect when do image resize
« Reply #13 on: February 22, 2009, 09:27:13 AM »
Hello and welcome to 4images forum.

Would you please post step-by-step how to reproduce that, including settings information.
I'm having hard time understand exactly what is the problem you described...
The changes in this topic do not affect "Resize with fixed width" and "Resize with fixed height" settings at all...

P.S.
I've updated code in Step 1 to less confusing and more optimized version.

[EDIT]
if you were talking about [Mod] Auto image resize on upload then then there is no option to "force" vertical/horizontal resizing, images will always be resized proportionally.
« Last Edit: February 22, 2009, 10:35:28 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline shally87

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: [FIX] Max height has no affect when do image resize
« Reply #14 on: March 31, 2009, 07:04:12 PM »
Quote
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/hoton1/public_html/festivals/includes/image_utils.php on line 74

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/hoton1/public_html/festivals/includes/image_utils.php on line 82

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/hoton1/public_html/festivals/includes/image_utils.php on line 93

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/hoton1/public_html/festivals/includes/image_utils.php on line 95

i get this error when uploading width size of 1024x768px, plus i dont get any thumbnails..

when i see in the admin >> setting panels, the auto resize is set to no even i set to yes many times it still set to no.

after i return everything to original code, the warning did not occur anymore but i wonder why the auto resize still set to no and i unable to set it to yes.
Any solutions??
« Last Edit: March 31, 2009, 07:24:31 PM by shally87 »