我想将裁剪后的图像保存在数据库中,但找不到任何方法。如何保存图像并从数据库中获取图像?我尝试过的是:
if (isset($_POST['submit']))
{
$conn = mysqli_connect('localhost','pma','123','test');
if(!$conn){
echo mysqli_error($conn);
}
$targ_w = $targ_h = 200;
$jpeg_quality = 90;
$src = $_POST['img'];
$ext = $_POST['ext'];
$name = "image.".$ext;
$newname = strstr($src,$name);
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
if($ext == "png")
{
$img_r = imagecreatefrompng($src);
imagepng($img_r,'ima.png',$jpeg_quality);
header('Content-Type: image/png');
$im = imagecreatefrompng($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
imagepng($dst_r,'image.png');
imagedestroy($im);
}else{
$im = imagejpeg($dst_r,'image.jpg',$jpeg_quality);
header('Content-type: image/jpeg');
$localimage = dirname(__FILE__)."/demo_files/image.".$ext;
if($conn){
$sql = "INSERT INTO `celeb` (`img` ) VALUES ('$localimage')";
$qry = mysqli_query($conn,$sql);
}
$sel = "SELECT * FROM `celeb` WHERE `image_name` ='772.jpeg' ";
$selqry = mysqli_query($conn,$sel);
while($row = mysqli_fetch_array($selqry)){
echo '<img src ="'.$row['img'].'" id= "nnnn">';
}
exit;
}
}
但是没有运气。