0

I select an image from a database table and save it in a variable:

(Connection already established)

require('fpdf.php');

$sql = "SELECT * FROM users WHERE ID=1";
$result = $dbConnection->query($sql);
$row = $result->fetch_assoc();

$id = $row['ID'];               
$image = $row['Profile'];


//Encode the image selected
$img = 'data://text/plain;base64,' . base64_encode($image);

//FPDF STUFF
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Image($img,10,10,39,'jpg');
$pdf->Cell(0,8,$id,0,1);

Then i get this error Message when trying to run the php script:

Fatal error: Uncaught Exception: FPDF error: Image file has no extension and no type was specified: data://text/plain;base64, [BINARY IMAGE DATA] in C:\xampp\htdocs\fpdf.php on line 271

So what am i supposed to do? Or what did i do wrong? (Code Snippet was found on GitHub)

Ali
  • 746
  • 1
  • 7
  • 17

1 Answers1

2

You're misplacing the type parameter.

$pdf->Image($img,10,10,39,HEIGHT_HERE,'jpg');

see documentation

naamhierzo
  • 345
  • 2
  • 8
  • I thought so aswell, i even checked it many times, and couldn't figure it out. Now it works...so strange, well thanks! –  Dec 04 '18 at 16:28