Created
April 14, 2016 14:36
-
-
Save timneutkens/e7b1b20e976dff3d4e8408f4979cac6d 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); | |
// 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(); |
Thank you!!
Same here, thanks for the snippet !
Perfect, thanks you!!
Helped a lot, thanks!!
Thanks!!
hellow, someone in 2019, i have problems
Shouldn't the data type be the same as the image coming in, or does FPDF genuinely not care?
Also, the image width and height are optional, so you could get away with leaving those off - YMMV though.
Thank you so much, it helped me. May God bless you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!! Really helped!