I want to save the output of the imagepng to a variable instead of dispaying it, and then want to use variable in a img tag to display the image.How can I do this?
I am using a smarty template for that I need to save the resultant image to variabe and then display it in a smarty template tpl file
Thanks it advance
imagepng
— Output a PNG image to either the browser or a file
Try as below :
ob_start();
imagepng($png);
$imagedata = ob_get_contents();
ob_end_clean();
echo '<img src="data:image/png;base64,'.base64_encode($imagedata).'"/>';
Try using streams. Implement a stream wrapper that saves the contents written into a variable, and pass a stream of this type into imagepng
.
For more details, see image outputs .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.