4images Forum & Community
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 18, 2018, 12:37:46 AM

Login with username, password and session length
Search:     Advanced search
4images is now on facebook. Click here and become a fan!
Togle to toolbar
Translate this page with =>
Translate this page >
* Home Help Search Login Register
 
+  4images Forum & Community
|-+  4images Help / Hilfe
| |-+  Bug Fixes & Patches
| | |-+  [FIX] Max height has no affect when do image resize
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 » »» Print
Author Topic: [FIX] Max height has no affect when do image resize  (Read 81570 times)
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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:
1
function resize_image($file, $quality, $dimension, $resize_type = 1) {


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




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


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





Step 2
Open admin/resizer.php
Find:
1
2
 $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:
1
2
3
 $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:
1
2
 $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:
1
2
3
 $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:
1
 show_input_row($lang['resize_dimension_desc'], "dimension", $dimension);


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




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


Replace it with:
1
2
 $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:
1
         if ($resize_type == 1 && ($image_info[0] > $dimension || $image_info[1] > $dimension)) {


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




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


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




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


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




Step 2.8
Find:
1
   show_hidden_input("dimension", $dimension);


Add above:
1
   show_hidden_input("height", $height);

« Last Edit: March 23, 2010, 06:30:24 AM by V@no » Logged

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)
vanish
Jr. Member
**
Offline Offline

Posts: 60

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« Reply #1 on: April 03, 2005, 11:41:07 PM »

This MOD don't working  Sad
After install it resizing function don't work...
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« Reply #2 on: April 04, 2005, 12:25:19 AM »

doesnt work HOW?
Logged

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)
vanish
Jr. Member
**
Offline Offline

Posts: 60

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« 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
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« 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?
Logged

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)
vanish
Jr. Member
**
Offline Offline

Posts: 60

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« 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
Logged
vanish
Jr. Member
**
Offline Offline

Posts: 60

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« 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
Logged
vanish
Jr. Member
**
Offline Offline

Posts: 60

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« Reply #7 on: April 05, 2005, 09:48:43 PM »

V@no where are u? Why do u keep silent?
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« 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.
Logged

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)
Olphi
Full Member
***
Offline Offline

Posts: 101

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #9 on: January 07, 2006, 03:43:03 PM »

This MOD don't working  Sad
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
Logged
artistichideaway
Newbie
*
Offline Offline

Posts: 15

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #10 on: March 07, 2006, 10:53:36 AM »

It works for me perfect and I have 1.7.1. installed.
Thanks Vano.
Logged
nobita
Jr. Member
**
Offline Offline

Posts: 61

Thank You
-Given: 0
-Receive: 0

ondesktop.org


View Profile WWW
« Reply #11 on: February 26, 2007, 02:17:50 PM »

Have any modifications to fix the same for thumbnail images?
Logged

ebnifkin
Pre-Newbie

Offline Offline

Posts: 1

Thank You
-Given: 0
-Receive: 0


View Profile
« 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 » Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« 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 » Logged

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)
shally87
Pre-Newbie

Offline Offline

Posts: 4

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #14 on: March 31, 2009, 07:04:12 PM »

Quote  [Expand]
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 » Logged
Pages: [1] 2 » »» Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 5.052 seconds with 19 queries.