[英]Base64 encoding error
the image is not showing upon clicking the upload button, base64 encoding error. 点击上传按钮后,图片未显示,base64编码错误。
the browser is just displaying binary codes. 浏览器仅显示二进制代码。
$showimage = "images/".$_FILES['image']["name"];
$show = new imagick( $showimage );
$points = array(
0,0, 0,0, # top left
213,0, 213,20, # top right
213,160, 213,110, # bottom right
0,160, 0,160,# bottum left
);
$show->setimagebackgroundcolor("#ffffff");
$show->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_BACKGROUND );
$show->distortImage( Imagick::DISTORTION_PERSPECTIVE, $points, TRUE );
echo "<img src='$show'>";
?>
Try: 尝试:
$imageData = base64_encode($show->getImageBlob);
echo "<img src='data:image/png;base64,$imageData'>";
You need to provide header
for the image type and also you don't have to echo
using <img>
tag. 您需要提供header
的图像类型,你也不必echo
使用<img>
标签。
Follow below code.. 请遵循以下代码。
$showimage = "images/".$_FILES['image']["name"];
$show = new imagick( $showimage );
$points = array(
0,0, 0,0, # top left
213,0, 213,20, # top right
213,160, 213,110, # bottom right
0,160, 0,160,# bottum left
);
$show->setimagebackgroundcolor("#ffffff");
$show->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_BACKGROUND );
$show->distortImage( Imagick::DISTORTION_PERSPECTIVE, $points, TRUE );
header("Content-Type: image/png"); //<--- Provide the header
echo $show; //<--- Removed the tags
?>
$imgData =addslashes(file_get_contents($_FILES['userImage']['tmp_name'])); $ imgData = addslashes(file_get_contents($ _ FILES ['userImage'] ['tmp_name'])));
// Stores image to $imgData which have data ytpe blo bin mysql //将图像存储到具有数据的$ imgData数据ytpe blo bin mysql
echo '<img src="data:image/png;base64,' . base64_encode($imgData) . '"/>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.