I\'ve some as base64 stored images in a database. Is it possible to print those data directly in a PDF document, using FPDF?
Data sctructure of the image
<
To ensure the images work with FPDF and to avoid errors, here is a modified version of @pedro-soares' code:
function getImage($dataURI){
$img = explode(',',$dataURI,2);
$pic = 'data://text/plain;base64,'.$img[1];
$type = explode("/", explode(':', substr($dataURI, 0, strpos($dataURI, ';')))[1])[1]; // get the image type
if ($type=="png"||$type=="jpeg"||$type=="gif") return array($pic, $type);
return false;
}
Because FPDF only allows these three file types, it is important to check that it is valid. To use:
$pic = getImage($Base64StringGoesHere);
if ($pic!==false) $pdf->Image($pic[0], 10,30,0,0, $pic[1]);