Page 1 of 1

resize thumbnail to correct size (logic)

Posted: Sat May 14, 2005 9:36 pm
by Skara
Heh, this is bugging me.

Original was 1024 x 768.
Thumb ended up being 200 x 112.
Obviously not the same ratio...

Code: Select all

$new_h = 150;
  $new_w = 200;

  $old_x = imageSX($src_img);
  $old_y = imageSY($src_img);
  if ($old_x > $old_y) {
    $thumb_w = $new_w;
    $thumb_h = $old_y * ($new_h / $old_x);
  }
  elseif ($old_x < $old_y) {
    $thumb_w = $old_x * ($new_w / $old_y);
    $thumb_h = $new_h;
  }
  else {
    $thumb_w = $new_w;
    $thumb_h = $new_h;
  }
I need it to shrink so that the height is <= 150 and the width is <= 200.

Anyone want to have a go at fixing this?

Posted: Sat May 14, 2005 9:41 pm
by infolock

Posted: Sat May 14, 2005 10:04 pm
by Skara
Hah! min() is awesome.

Thanks a bunch!

Probably helps that it's 10 @ night here... ^^;