Use PHP to proportionally scale an image
I wrote the following function to proportionally scale images that I was pulling from a directory.
View Code PHP
function img_size($img,$alt) { list($width,$height) = getimagesize($img); $maxwidth = 140; //set max width here if ($width > $maxwidth) { $i = $width - $maxwidth; $x = $width - $i; $percent = $maxwidth/$width; } else { $x = $width; $percent = 1; } $y = $percent * $height; $img_src = '<img src="'.$img.'" width="'.$x.'" height="'.$y.'" alt="'.$alt.'" border="0" />'; return $img_src; } echo img_size('http://somesite.com/image.jpg', 'some alt text'); //result <img src="http://somesite.com/image.jpg" width="140" height="(proportionate to 140)" alt="(alt)" border="0"> |




