0

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";
}
3
Contributors
3
Replies
35
Views
1 Year
Discussion Span
Last Post by hrushi9
0

I want to create receipt for booking.
I tried html2canvas but it is not generating full size image of receipt as it is displayed on page.

Above code is on page reservation.php. 'confirmation-wrapper ' is displayed on booking.php page after booking record is inserted in mysql via ajax form used on booking.php

html2canvas is generating half size image of 'confirmation-wrapper '

I found file_put_contents method to generate receipt but it is generating balnk or Corrupt image .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.