找不到图像或类型未知 Dompdf 0.8.1 和 CodeIgniter
Image not found or type unknown Dompdf 0.8.1 and CodeIgniter
我想从生成的图像加载图像到 PDF。
我已将 isRemoteEnabled 设置为 true 并且
生成的 QRCode 工作正常
这是我的代码。
$this->load->library(array('pdf', 'ciqrcode'));
$data = array('qrlink' => base_url('generateQR?text=123'));
$this->pdf->set_paper('folio');
$this->pdf->loadHtml($this->load->view('pdfoutput', $data, true));
$this->pdf->set_base_path(base_url());
$this->pdf->render();
$this->pdf->stream('QR-PDF', array("Attachment" => false));
这是我的观点
<img src="<?= $qrlink ?>" alt="QRcode" width="150px">
但输出显示 未找到图像或类型未知。
那我该怎么办呢?
提前致谢。
干杯。
我有一个类似的问题,在网上搜索了很多小时后,我发现(感谢 Atiruz )Dompdf 确实 NOT 使用远程 URL 可以很好地渲染图像,例如http://your-domain.com/com/images/img.png" /> 总是给我同样的错误 [找不到图像或类型未知]。在我的例子中 ***strong text*** 我不得不使用 base64 编码的图像,它似乎解决了我的问题。
我写了一个小片段,可以将您的图像编码为 base64 和 return 一个字符串以在您的标签中使用。
这里是如何使用 base64 编码数据作为你的 img src
//Use a valid base64 encoded data string
<img src="your-base64-encoded-image-string" />
这是将您的图像转换为 base64 编码图像数据的代码片段
function encode_img_base64( $img_path = false, $img_type = 'png' ){
if( $img_path ){
//convert image into Binary data
$img_data = fopen ( $img_path, 'rb' );
$img_size = filesize ( $img_path );
$binary_image = fread ( $img_data, $img_size );
fclose ( $img_data );
//Build the src string to place inside your img tag
$img_src = "data:image/".$img_type.";base64,".str_replace ("\n", "", base64_encode($binary_image));
return $img_src;
}
return false;
}
我希望这对外面的人有帮助!
我和 pdf 有同样的问题,我用这个函数解决了
function encode_img_base64($img_path = false): string
{
if($img_path){
$path = $img_path;
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
return 'data:image/' . $type . ';base64,' . base64_encode($data);
}
return '';
}
我想从生成的图像加载图像到 PDF。
我已将 isRemoteEnabled 设置为 true 并且 生成的 QRCode 工作正常
这是我的代码。
$this->load->library(array('pdf', 'ciqrcode'));
$data = array('qrlink' => base_url('generateQR?text=123'));
$this->pdf->set_paper('folio');
$this->pdf->loadHtml($this->load->view('pdfoutput', $data, true));
$this->pdf->set_base_path(base_url());
$this->pdf->render();
$this->pdf->stream('QR-PDF', array("Attachment" => false));
这是我的观点
<img src="<?= $qrlink ?>" alt="QRcode" width="150px">
但输出显示 未找到图像或类型未知。 那我该怎么办呢?
提前致谢。
干杯。
我有一个类似的问题,在网上搜索了很多小时后,我发现(感谢 Atiruz )Dompdf 确实 NOT 使用远程 URL 可以很好地渲染图像,例如http://your-domain.com/com/images/img.png" /> 总是给我同样的错误 [找不到图像或类型未知]。在我的例子中 ***strong text*** 我不得不使用 base64 编码的图像,它似乎解决了我的问题。
我写了一个小片段,可以将您的图像编码为 base64 和 return 一个字符串以在您的标签中使用。
这里是如何使用 base64 编码数据作为你的 img src
//Use a valid base64 encoded data string
<img src="your-base64-encoded-image-string" />
这是将您的图像转换为 base64 编码图像数据的代码片段
function encode_img_base64( $img_path = false, $img_type = 'png' ){
if( $img_path ){
//convert image into Binary data
$img_data = fopen ( $img_path, 'rb' );
$img_size = filesize ( $img_path );
$binary_image = fread ( $img_data, $img_size );
fclose ( $img_data );
//Build the src string to place inside your img tag
$img_src = "data:image/".$img_type.";base64,".str_replace ("\n", "", base64_encode($binary_image));
return $img_src;
}
return false;
}
我希望这对外面的人有帮助!
我和 pdf 有同样的问题,我用这个函数解决了
function encode_img_base64($img_path = false): string
{
if($img_path){
$path = $img_path;
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
return 'data:image/' . $type . ';base64,' . base64_encode($data);
}
return '';
}