How to create image of receipt using file_put_contents or imagecreatefromstring , imagejpeg?
I have following code, which generates corrupted images, when I open images it shows invalid image
And how to email generated image ? ( optional )
Thanks in advance.
$html_code = '
<div class=confirmation-wrapper id=test> <div class=container> <div class=row> <div class=col-sm-8 col-md-9> <div class=content> <h2 class=heading><i class=fa fa-check-circle-o></i> Thank you, your booking is complete!</h2> <p>Your confirmation number is <span class=text-primary> '.$b_id.'</span></p> </div> <div class=confirmation-content> <div class=content> <div class=section-title text-left> <h4>Booking Information</h4> </div> </div> <ul class=book-sum-list> <li><span class=font600>Booking Number: </span> '.$b_id.'</li> <li><span class=font600>Room: </span> '.$room_name.'</li> <li><span class=font600>Traveller Name: </span> '.$f_name.' '.$l_name.'</li> <li><span class=font600>Traveller Email: </span>'.$e_mail.'</li> <li><span class=font600>Phone Number: </span> '.$ph_num.'</li> <li><span class=font600>Package Name: </span> '.$title.'</li> <li><span class=font600>Included: </span> '.$cmp.'</li> <li><span class=font600>Starting: </span> '.$cin_date.'</li> <li><span class=font600>End: </span> '.$cout_date.'</li> <li><span class=font600>No. Adults: </span> '.$adlts.' </li> <li><span class=font600>No. Children: </span> '.$childs.' </li> <li><span class=font600>Total Price: </span><i class=fa fa-inr></i> '.$total_price.'/-</li> </ul> </div> </div> </div> </div> </div>'
;
echo "$html_code";
$random = time() . rand(100, 1000);
$newfilename ="receipt_$random";
$path="receipt/";
$filename = $path.$newfilename;
$content = str_replace('data:image/jpeg;base64,','',$html_code);
$savefile = @file_put_contents($filename, $content);
if($savefile){
echo "<img src=$filename>";
}
else
{
echo"error while creating image";
}