Hi all
I want to display image uploaded from a form in a div size of "width=235px and height=61px" with image good quality also(i mean not shrinked or stretched) using php. I'm uploading a image of size "width=452px and height=507px". I have tried the codes i found on internet but all the codes are reducing the image either weight wise or height wise. I want my uploded image to be displayed in width = 235px and hight = 61px with quality.
I tried this type of code but this is not reducing my image to 23561 it is reducing the image to 8161
`<?php
function createThumbnail($img, $imgPath, $suffix,$quality)
{
list($width, $height, $image_type) = getimagesize($img);
$w=235;
$h=61;
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*($r-$w/$h)));
} else {
$height = ceil($height-($height*($r-$w/$h)));
}
$newwidth = $w;
$newheight = $h;
} else {
if ($w/$h > $r) {
$newwidth = $h*$r;
$newheight = $h;
} else {
$newheight = $w/$r;
$newwidth = $w;
}
}
$src = imagecreatefromjpeg($img);
$tmp = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth, $newheight,$width,$height);
// Create the new file name.
$newNameE = explode(".", $img);
$newName = ''. $newNameE[0] .''. $suffix .'.'. $newNameE[1] .'';
// Save the image.
imagejpeg($tmp, "$imgPath/$newName", $quality) or die("Cant save image");
echo "<img src='$imgPath/$newName' style='max-width:100; max-height:100;'>";
// Clean up.
//imagedestroy($src);
imagedestroy($tmp);
return true;
}
$thumb = createThumbnail("hotel-view.jpg", "images", "-thumb", 100);
?>`
Can some body please help me with this issue.It need to be fixed very urgently.