-
-
Save the7th/73c7a0cfd1a4f15f9e11334fdd0ead78 to your computer and use it in GitHub Desktop.
Insert base64 image data into fpdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// load the 'fpdf' extension | |
require('fpdf.php'); | |
// just for demonstration purpose, the OP gets the content from a database instead | |
$h_img = fopen('img.jpg', "rb"); | |
$img = fread($h_img, filesize('img.jpg')); | |
fclose($h_img); | |
// prepare a base64 encoded "data url" | |
$pic = 'data://text/plain;base64,' . base64_encode($img); // if you already have base64, you don't need to use base64_encode. | |
// extract dimensions from image | |
$info = getimagesize($pic); | |
// create a simple pdf document to prove this is very well possible: | |
$pdf = new FPDF(); | |
$pdf->AddPage(); | |
$pdf->SetFont('Arial','B',16); | |
$pdf->Cell(40,10,'Hello Image!'); | |
$pdf->Image($pic, 10, 30, $info[0], $info[1], 'jpg'); | |
$pdf->Output(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment