Home > Software design >  FPDF Image Error: Unsupported image type after upgrading to PHP 8
FPDF Image Error: Unsupported image type after upgrading to PHP 8

Time:02-11

I have a signature stored as a base64 string that outputs into PDF reports like so:

$image = $row1['signatureString'];     
        
$trimmedSig = substr($image, 22);
        
$pic = 'data:image/gif;base64,' . $trimmedSig;
        
     $pdf->Cell(20, 7, $pdf->Image($pic, 'C', $pdf->GetX(), $pdf->GetY(), 30, 7, 'png'), 'TBL', 0, 'L', false);
   

after I updagraded to PHP 8, I now get the following error:


Fatal error: Uncaught Exception: FPDF error: Unsupported image type: 7 in /var/www/html/packages/fpdf182/fpdf.php:271 
Stack trace: 
#0 /var/www/html/packages/fpdf182/fpdf.php(890): FPDF->Error('Unsupported ima...') 
#1 /var/www/html/pdfReports/generatePDF.php(1799): FPDF->Image('data:image/gif;...', 'C', 175.00125, 73.00125, 30, '7', 'png') 
#2 /var/www/html/genPDFReport.php(13): include('/var/www/html/p...') 
#3 {main} thrown in /var/www/html/packages/fpdf182/fpdf.php on line 271

CodePudding user response:

You have

$pic = 'data:image/gif;base64,' . $trimmedSig;

but then use

Image($pic, 'C', $pdf->GetX(), $pdf->GetY(), 30, 7, 'png')

I guess it should be

Image($pic, 'C', $pdf->GetX(), $pdf->GetY(), 30, 7, 'gif')
  • Related