Greeting to all
am trying to create thumbnail from image stored in mysql database..
this is the coding am using to create the thumbnail...
this works like charm.. but the problem is that the image quality is not as in the original image..
i tried to change $out = imagejpeg($thum b); to $out = imagejpeg($thum b, $fileType, 100); but it doesnt print the image...
pls help me getrit of this problem or suggest me some other coding for the above..
Thanks in Advance...
Regards,
Guna
am trying to create thumbnail from image stored in mysql database..
this is the coding am using to create the thumbnail...
this works like charm.. but the problem is that the image quality is not as in the original image..
Code:
<?php
// Place the code to connect your Database here
// DATABASE CONNECTION
include('config.php');
$id = $_GET['id'];
// Check if ID exists
if(!is_numeric($id)) die("No image with the ID: " .$id);
// Get data from database
$dbQuery = "SELECT image, file_name ";
$dbQuery .= "FROM imagesdata ";
$dbQuery .= "WHERE id = $id ";
$dbQuery .= "LIMIT 1";
$result = mysql_query($dbQuery);
// read imagetype + -data from database
if(mysql_num_rows($result) == 1) {
$file_Type = mysql_result($result, 0, "file_name");
$fileContent = mysql_result($result, 0, "image");
//$fileType = str_replace(".","",strtolower(substr( $file_Type,strrpos( $file_Type,"."))));
//$filename = $file_Type;
header("Content-type: $fileType");
// get originalsize of image
$im = imagecreatefromstring($fileContent);
$width = imagesx($im);
$height = imagesy($im);
// Set thumbnail-width to 100 pixel
$imgw = 150;
// calculate thumbnail-height from given width to maintain aspect ratio
$imgh = $height / $width * $imgw;
// create new image using thumbnail-size
$thumb=imagecreatetruecolor($imgw,$imgh);
$filename = addslashes (file_get_contents($fileContent));
$image_name= stripslashes($fileContent);
// copy original image to thumbnail
imagecopyresampled($thumb,$im,0,0,0,0,$imgw,$imgh,ImageSX($im),ImageSY($im));
// show thumbnail on screen
$out = imagejpeg($thumb);
print($out);
// clean memory
imagedestroy ($im);
imagedestroy ($thumb);
}
?>
pls help me getrit of this problem or suggest me some other coding for the above..
Thanks in Advance...
Regards,
Guna
Comment