Thursday 25 April 2013

Dispaly Image in Ratio

<?php
/*save below code as demo.php. */
/* Dispaly Image in ratio */
$inputwidth=$_GET['w']; //new user define width for image
$inputheight=$_GET['h']; //new user define Height for image
$imgsrc=$_GET['src']; // imagepath from where image need to be load.
//get image details
list($width, $height, $type, $attr) = getimagesize($imgsrc);
//Generate new height and width based on original image size in ratio
if (($width/$height) > ($inputwidth/$inputheight))
{
    $outputwidth = $inputwidth;
    $outputheight = ($inputwidth * $height)/ $width;
}// And if the image is taller rather than wider, then set the height and figure out the width
elseif (($width/$height) < ($inputwidth/$inputheight)) {
                $outputwidth = ($inputheight * $width)/ $height;
                  $outputheight = $inputheight;
}    // And because it is entirely possible that the image could be the exact same size/aspect ratio of the desired area,
elseif (($width/$height) == ($inputwidth/$inputheight))
{
    $outputwidth = $inputwidth;
    $outputheight = $inputheight;
}             
echo '<img src="'.$imgsrc.'" width="'.$outputwidth.'" height="" alt="'.$outputheight.'">';
?>

No comments:

Post a Comment

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...