4images Forum & Community

4images Help / Hilfe => Bug Fixes & Patches => Topic started by: V@no on March 27, 2005, 07:11:23 PM

Title: [FIX] Max height has no affect when do image resize
Post by: V@no 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);
Title: Re: [FIX] Max height has no affect when do image resize
Post by: vanish on April 03, 2005, 11:41:07 PM
This MOD don't working  :(
After install it resizing function don't work...
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no on April 04, 2005, 12:25:19 AM
doesnt work HOW?
Title: Re: [FIX] Max height has no affect when do image resize
Post by: vanish 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
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no 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?
Title: Re: [FIX] Max height has no affect when do image resize
Post by: vanish 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
Title: Re: [FIX] Max height has no affect when do image resize
Post by: vanish 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
Title: Re: [FIX] Max height has no affect when do image resize
Post by: vanish on April 05, 2005, 09:48:43 PM
V@no where are u? Why do u keep silent?
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no 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.
Title: Re: [FIX] Max height has no affect when do image resize
Post by: Olphi 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:
Title: Re: [FIX] Max height has no affect when do image resize
Post by: artistichideaway on March 07, 2006, 10:53:36 AM
It works for me perfect and I have 1.7.1. installed.
Thanks Vano.
Title: Re: [FIX] Max height has no affect when do image resize
Post by: nobita on February 26, 2007, 02:17:50 PM
Have any modifications to fix the same for thumbnail images?
Title: Re: [FIX] Max height has no affect when do image resize
Post by: ebnifkin 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.
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no 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 (http://www.4homepages.de/forum/index.php?topic=7700.0) then then there is no option to "force" vertical/horizontal resizing, images will always be resized proportionally.
Title: Re: [FIX] Max height has no affect when do image resize
Post by: shally87 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??
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no on April 01, 2009, 01:53:15 AM
Hello and welcome to 4images forum.
If you didn't have this problem before installing this fix, then I can only assume you made a mistake installing it. Double check each step again.
Title: Re: [FIX] Max height has no affect when do image resize
Post by: hlalink on July 28, 2009, 05:49:46 AM
i have this error

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/XXXXXX/public_html/includes/image_utils.php on line 74

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

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

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


can i get help please
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no on July 28, 2009, 09:28:11 AM
And these errors you see when...
Title: Re: [FIX] Max height has no affect when do image resize
Post by: waynenort on August 02, 2009, 10:00:18 AM
I figure this error that hlalink shally87 mean is happening after the image resize and before the thumbmail creation. What seems to happen is that it goes through the process of resizing the image which it does successfully then errors. The thumbnail then isn't created. The default jpeg thumbnail is shown instead.  The error is on the control panel webpage after the upload and resize is executed. See the screen capture.
Hope this helps V@no
Title: Re: [FIX] Max height has no affect when do image resize
Post by: Sunny C. on March 15, 2010, 10:11:44 AM
Thanx
Title: Re: [FIX] Max height has no affect when do image resize
Post by: surferboy on March 16, 2010, 12:11:56 AM
Just installed this MOD aka Step 8 for the auto upload resize

Using 4images version 1.7.7

Worked perfectly with single image upload.

Here are my settings for max upload dimensions:
width 818
height 1024

Upoaded an image that had dimensions of:
width 1181
height 1575

After auto resize and this MOD, new dimensions in our gallery for this image:
width 767
height 1023

Seems like it is working perfectly.

Thanks,

Brian
Title: Re: [FIX] Max height has no affect when do image resize
Post by: V@no on March 23, 2010, 06:35:14 AM
I just discovered a bug in step 1.2 (it's fixed on first page), which might cause creating images 0x0 pixels

In includes/image_utils.php find:
function resize_image($file, $quality, $dimension, $resize_type = 1, $height = 0) {

Replace it with:
function resize_image($file, $quality, $dimension, $resize_type = 1, $height = false) {
Title: Re: [FIX] Max height has no affect when do image resize
Post by: clubbu on July 20, 2011, 09:53:49 AM
Hello, in 1.7.10 is fixing or not?
Title: Re: [FIX] Max height has no affect when do image resize
Post by: Rembrandt on July 20, 2011, 11:00:50 AM
Hello, in 1.7.10 is fixing or not?
sure
Title: Re: [FIX] Max height has no affect when do image resize
Post by: clubbu on July 26, 2011, 09:48:57 AM
But when i use multiupload don't resize...
Title: Re: [FIX] Max height has no affect when do image resize
Post by: Sunny C. on August 11, 2011, 12:14:07 AM
Is this included in 1.7.10 !?!?!
Title: Re: [FIX] Max height has no affect when do image resize
Post by: Rembrandt on August 11, 2011, 05:26:12 AM
habe ich oben schon geschrieben, ja ist es.
Title: Re: [FIX] Max height has no affect when do image resize
Post by: Sunny C. on August 11, 2011, 06:40:07 PM
Überlesen  :roll:
Danke  :wink:
Ich finde das sollte man im Post #1 auch dazu schreiben