Reputation: 11
the image is not showing upon clicking the upload button, base64 encoding error.
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'>";
?>
Upvotes: 1
Views: 476
Reputation: 4283
Try:
$imageData = base64_encode($show->getImageBlob);
echo "<img src='data:image/png;base64,$imageData'>";
Upvotes: 1
Reputation: 3096
$imgData =addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
// Stores image to $imgData which have data ytpe blo bin mysql
echo '<img src="data:image/png;base64,' . base64_encode($imgData) . '"/>';
Upvotes: 0
Reputation: 68446
You need to provide header
for the image type and also you don't have to echo
using <img>
tag.
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
?>
Upvotes: 0