I'm trying to scale images so they remain in proportion with the original image, but do not exceed certain sizes. How can I do this? I can't just take a percentage of the image or strictly set it to a certain size, because the original image sizes vary greatly. The best example of this is here: http://zip.4chan.org/v/imgboard.html How do I restrict the image so it only appears in a certain area of the page without affecting anything else? I'm dynamically loading images, and I don't the differing sizes to alter text on the page. Thanks in advance.
OK, I found out how to do number 1 by using max-height and max-width. I'm still not sure how to do number 2, however.
I wrote a GD based function for one of my projects, if you use GD with PHP following can help you. Here you go: Functio to include: function gd_fit(&$image, $target) { $width = imagesx($image); $height = imagesy($image); if ($width > $height) $percentage = ($target / $width); else $percentage = ($target / $height); $width = round($width * $percentage); $height = round($height * $percentage); $ret=@imagecreatetruecolor($width, $height); @imagecopyresampled ($ret,$image, 0, 0, 0, 0, $width, $height, imagesx($image), imagesy($image)); return $ret; } PHP: Usage: $img = imagecreatefromjpeg("test.jpg"); //suppose it is 800x600 $img = gd_fit($img, 100); //now is fit to 100x100 boundry with aspect ratio imagejpeg($img,"resized.jpg",100); //save new image PHP: I hope it helps. regards