FPDF Image Error: Unsupported image type after upgrading to PHP 8

FPDF Image Error: Unsupported image type after upgrading to PHP 8

我将签名存储为 base64 字符串,输出到 PDF 报告中,如下所示:

$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);
   

升级到 PHP 8 后,我现在收到以下错误:


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

你有

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

然后使用

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

我猜应该是

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