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:
Code: Select all
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);
}
}By the way, I really need the getImage.php to output the image to another page.
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: