Use something like this.
Code:
function image_resize_to_ratio($image_location, $thumb = false)
{
if ($thumb == false)
{
$maximum_width = (empty($this->resize_width))? $this->width : $this->resize_width;
$maximum_height = (empty($this->resize_height))? $this->height : $this->resize_height;
}
else
{
$maximum_height = $this->tmb_height;
$maximum_width = $this->tmb_width;
}
$size = @getimagesize($image_location);
if (empty($size))
{
library::error("Error: image location (".$image_location.") did not yield a valid image in file:".__FILE__." @ Line: ".__LINE__);
return false;
}
$this->actual_width = $size[0];
$this->actual_height = $size[1];
$x_ratio = $maximum_width / $this->actual_width;
$y_ratio = $maximum_height / $this->actual_height;
if (($this->actual_width <= $maximum_width) && ($this->actual_height <= $maximum_height))
{
$this->resize_width = $this->actual_width;
$this->resize_height = $this->actual_height;
}
else if (($x_ratio * $this->actual_height) < $maximum_height)
{
$this->resize_height = ceil($x_ratio * $this->actual_height);
$this->resize_width = $maximum_width;
}
else
{
$this->resize_width = ceil($y_ratio * $this->actual_width);
$this->resize_height = $maximum_height;
}
return;
}
That's a function from an old library of mine that finds the correct width and height with respect to the aspect ratio when resizing an image. I'll leave it to you to figure out the logic and modify the code to how you need it.
HTH!
Regards,
Rich
--
[
http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design