TCPDF error :Unable to get the size of the image
This might be due to filesize()
failing to stat()
the remote image file via the HTTP wrapper (since the wrapper doesn't support it).
According to the TCPDF image() method documentation you can pass the image data in directly by prepending it with an @
symbol. So you could get the raw image data and then pass it to TCPDF like so:
$img = file_get_contents('http://example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=');
$pdf->Image('@' . $img, 55, 19, '', '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
Note that I haven't tested this (and the TCPDF documentation is sparse) so you might need to experiment a little to get it to work correctly.
Edit:
This is a fully working example (on my PC). Use this to test if you can successfully retrieve the image and output the PDF to your browser. Of course you'll need to set a known valid path for the image!
<?php
require './tcpdf/tcpdf.php';
$pdf = new TCPDF();
$pdf->AddPage();
$img = file_get_contents('http://path/to/your.jpg');
$pdf->Image('@' . $img);
$pdf->Output();
?>
TCPDF ERROR: [Image] Unable to get image
Apparently the "fopen"-wrappers are not used by TCPDF.
If you supply the URL of an image, TCPDF tries to download it with cURL into the "cache"-directory where your TCPDF-installation is stored (you have to check what the K_PATH_CACHE
-constant contains to be sure).
So I guess you have to have write permissions in this directory that the magic works. Also you need cURL enabled.
How to fix: Unable to get the size of the image [] with HTML2PDF
Problem solved
For some reason in vendor\spipu\html2pdf\src\Html2Pdf.php
protected function _tag_open_IMG($param)
{
print_r($param);
$src = str_replace('&', '&', $param['src']);
im getting result like this
Array (
[style] => Array ( )
[alt] =>
[src] =>
[href] => https://my.hostname.co.uk/assets/company/logo-png-3.png
[num] => 1
)
so i just change
$src = str_replace('&', '&', $param['src']);
to
$src = str_replace('&', '&', $param['href']);
How to catch TCPDF Exception TCPDF ERROR: [Image] Unable to get the size of the image
In general an ERROR can not be catched. You have to transform your error to an exception so you can catch it but this isnt a best practise.
Its better you test your $renderedView for the image size before you put it to TCPDF
Related Topics
PHP String Doesn't Allow < and > Characters
Laravel 4.1: How to Paginate Eloquent Eager Relationship
How to Get Value from Form Without Submitting It
How to Http Post Special Chars in Swift
Regex Matching Table Rows in HTML
How to Get the Function Name Inside a Function in PHP
Guzzle 6: No More JSON() Method for Responses
Browscap Ini Directive Not Set
When Should I Use a Bitwise Operator
Mysqli - Fetch_Array Error Call to a Member Function Fetch_Array() on a Non-Object MySQLi
How to Use an Object Method as a Callback Function
Random Float Between 0 and 1 in PHP
How to Find Timezone Id from Ip Address/Country Name in PHP