How to display blob image combined with imagettftext

828 views Asked by At

Still on imagettftext topic, now I have question how to display blob image on the page that created from imagecreatefrompng. I want to do this

<?php
include('../db.php');

$id = $_GET['id'];

$sql = "SELECT * FROM data WHERE id=$id";
$result = $conn->query($sql);
$row = $result->fetch_array();

$id = $row['id']; //varchar
$name = $row['name']; //varchar
$address = $row['address']; //varchar
$photo = base64_encode($row['photo']); //blob image

$im = imagecreatefrompng('../img/idcard.png');
$black = imagecolorallocate($im, 0, 0, 0);
$font = "../fonts/Ubuntu-R.ttf";

imagettftext($im, 15, 0, 200, 175, $black, $font, $id);
imagettftext($im, 15, 0, 240, 200, $black, $font, $name);
imagettftext($im, 15, 0, 280, 275, $black, $font, $address);

imagettftext($im, 15, 0, 350, 315, $black, $font, $photo);

header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

My code display id card, text, but image/photo just display as text character

2

There are 2 answers

0
barpas On
$im2 = imagecreatefromstring($photo);
imagecopyresized ($im,$im2,2,2,0,0,46,46,183,173);//see parameters at: http://php.net/manual/en/function.imagecopyresized.php

(if You not need resizing You can use imagecopy too)

0
Shenal Pigera On
<?php
$dest = imagecreatefrompng($im);
$src = imagecreatefromjpeg('profile_pic.jpg');

imagecopymerge($dest, $src, 250, 650, 0, 0, imagesx($src), imagesx($src), 100);
imagecopyresampled($dest, $src, 250, 650, 0, 0, 577, 540, imagesx($src), imagesy($src));

imagejpeg($dest, $new_image_name, 100);
imagedestroy($dest);
?>