Hi! I have a PHP function which I use to resize the images that I get from the database.
These are the functions inside my getImage.php:
function resize($image){
$background = imagecreatetruecolor(116,84);
$source = imagecreatefromjpeg($image);
$width= imagesx($source);
$height = imagesy($source);
header("Content-type: image/jpeg");
if($width>$height){
imagecopyresampled($background,$source,0,0,0,0,116,84,$width,$height);
imagejpeg($background);
imagedestroy($background);
}
else{
imagefill($background,0,0,imagecolorallocate($background, 255, 255, 80));
imagecopyresampled($background,$source,20,0,0,0,75,84,$width,$height);
imagejpeg($background);
imagedestroy($background);
}
}
function getImage($id){
$query="SELECT i.filepath FROM users u, items i
WHERE u.userid=i.userid AND u.userid=$id";
$res = mysql_query($query);
while ($obj = mysql_fetch_object($res)) {
$file = $obj->filepath;
return resize($file);
}
}
Basically, I don't have any problems with resizing the image. My problem is that whenever I try to call this function to output in another page either by using <img src="<?=getImage($id)?>" border="0"> OR <img src="getImage.php" border="0">, the image does not show itself. It's as if I didn't call any image. Please help!
By the way, I really need the getImage.php to output the image to another page.