Articles / TCPDF ERROR: [Image] Unable to get image

Recently I was creating a PDF using TCPDF as was greeted with a confusing error.

TCPDF ERROR: [Image] Unable to get image: https://localhost/pathToImage/image.png

My first thought where is was clearly a permissions issue on the production server as this was something that was working on the development server. I first checked if the website had the correct permissions and also as SELinux was enabled went down the route of making sure that was not the issue.

However I then found a related issue on stackoverflow which gave the answer:

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).

Low and behold it wasn't even connected to TCPDF at all and simple curl was refusing to download the referenced image url as the SSL Certificate was setup incorrectly and was pointing to a SHA1 key

 

ChristophersMBP:Desktop chenderson$ curl -O https://www.example.com/sites/default/files/2017-11/file.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

After a quick change to the Nginx conf file and success.

ChristophersMBP:Desktop chenderson$ curl -O https://www.example.com/sites/default/files/2017-11/file.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  362k  100  362k    0     0   417k      0 --:--:-- --:--:-- --:--:--  418k
ChristophersMBP:Desktop chenderson$ 

 

Tags
TCPDF curl