Display PNG with raw image data within an html document using PHP -
with code, trying create image of signature json , display image directly in browser without saving it. problem have want display image within html document header information has been modified. there way display image it's raw image data within html document? or other way around issue?
$json = $ticket->sig; // json representing signature $img = sigjsontoimage($json); //get image resource json // here want display image cannot modify header information header('content-type: image/png'); imagepng($img, null, 0, png_no_filter); imagedestroy($img);
sure, can use 2 things this.
the html image tag supports base64 encoded image. can big html, work. can output image buffer using ob_start , ob_end functions. see http://us2.php.net/manual/pt_br/function.ob-start.php
so php file can do:
$json = $ticket->sig; // json representing signature $img = sigjsontoimage($json); //get image resource json ob_start(); // start buffering output imagepng($img, null, 0, png_no_filter); $b64 = base64_encode(ob_get_contents()); // we've outputted , base64 imagedestroy($img); ob_end_clean(); // print html tag image embedded echo '<img src="data:image/png;base64,'.$b64.'"/>';
this make html img tag embedded image. hope want.
ps: keep in mind increase loading time html data, since browser opens thread downloading image if link it.
Comments
Post a Comment