Webstie Designer Webstie DesignerWebstie DesignerWebstie DesignerWebstie Designer
 
 
Cheap Webstie Designer Cheap Webstie Designer Cheap Webstie Designer Cheap Webstie Designer Cheap Webstie Designer Cheap Webstie Designer
 
 

How To Correctly Resize An Image

 

This is a big problem and often leads to squished images looking very poor. I have developed this simple formula to resize the images without losing their aspect ratio.

function MikesImageResize($width, $height, $target) {

if ($width > $target)
{
$percentage = ($target / $width);
}else
{
$percentage = "1";
}

$width = round($width * $percentage);
$height = round($height * $percentage);

return "width=\"$width\" height=\"$height\"";
}

 

Its that simple now this will compress an image to the width entered and reduce the height b the same percentage. If the image is smaller than the width it will be displayed centred but will not stretch it so it looks fine

$Images_Width = "200";

$myimages = getimagesize(“images/image1.png”);

echo "<img src='$Image_Name'" . MikesImageResize($myimages[0], $ myimages[1], $Images_Width) . ">";

 

Simple and elegant, hope this helps.  

 
  Webstie DesignerCheap Webstie Designer