找不到图片或类型未知的Dompdf 0.8.1和CodeIgniter [英] Image not found or type unknown Dompdf 0.8.1 and CodeIgniter
问题描述
我想从生成的图像中将图像加载到PDF。
I want to load an image to PDF from generated image.
我已将 isRemoteEnabled设置为true ,并且
生成了QRCode工作正常
I had set isRemoteEnabled to true and generated QRCode working fine
这是我的代码。
$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">
但是输出显示找不到图片或类型未知。
那我该怎么办?
But the output say Image not found or type unknown. So what should I do?
谢谢。
干杯。
推荐答案
我遇到了类似的问题,经过数小时的搜索,我发现(由于Atiruz ), Dompdf 确实不可以很好地利用远程网址呈现图像,例如 http://your-domain.com/com/images/img.png /> 总是给我相同的错误[找不到图像或键入未知]。 ***我不得不使用base64编码的图像,它似乎已经解决了我的问题。
I had a similar issue and after many hours searching the inter-web, I found out (thanks to Atiruz ) that Dompdf does NOT render images well with remote urls e.g. http://your-domain.com/com/images/img.png" /> always gave me the same error [Image not found or type unknown]. In my case***strong text*** I had to use a base64 encoded image and it seemed to have resolved my issue.
我写了一个小片段,可以将您的图像编码为base64并返回在标签内使用的字符串。
I wrote a small snippet that can encode your image into base64 and return a string to use inside your tag.
以下是如何使用base64编码数据作为img src
Here is how to use the base64 encode data as your img src
//Use a valid base64 encoded data string
<img src="your-base64-encoded-image-string" />
以下是将您的图像转换为base64编码图像数据的代码段
Here is the snippet to convert your image into a base64 encoded image data
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;
}
我希望这对外面的人有帮助!
I hope this helps someone out there!
这篇关于找不到图片或类型未知的Dompdf 0.8.1和CodeIgniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!