TCPDF ERROR: [Image] Unable to get the size of the image:

If you are runnig Joomla 3.x and Virtuemart 3.x please post to this forum your questions or support tickets about One Page Checkout

TCPDF ERROR: [Image] Unable to get the size of the image:

Postby admin » Tue May 31, 2016 2:38 pm

TCPDF ERROR: [Image] Unable to get the size of the image: http://domain.com/image.png

hello friends, we recently came around this TCPDF error and we found a solution to the above problem.

locate this file:
\libraries\tcpdf\include\tcpdf_static.php

and update whole function in this file to this:
Code: Select all
/**
    * Reads entire file into a string.
    * The file can be also an URL.
    * @param $file (string) Name of the file or URL to read.
    * @return The function returns the read data or FALSE on failure.
    * @author Nicola Asuni
    * @since 6.0.025
    * @public static
    */
   public static function fileGetContents($file) {
      $alt = array($file);
      //
      if ((strlen($file) > 1)
          && ($file[0] === '/')
          && ($file[1] !== '/')
          && !empty($_SERVER['DOCUMENT_ROOT'])
          && ($_SERVER['DOCUMENT_ROOT'] !== '/')
      ) {
          $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
          if (($findroot === false) || ($findroot > 1)) {
         $alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file));
          }
      }
      
      
      
      
      //
      $protocol = 'http';
      if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
          $protocol .= 's';
      }
      //
      $url = $file;
      if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) {
         $url = $protocol.':'.str_replace(' ', '%20', $url);
      }
      $url = htmlspecialchars_decode($url);
      $alt[] = $url;
      

      
      //
      if (preg_match('%^(https?)://%', $url)
          && empty($_SERVER['HTTP_HOST'])
          && empty($_SERVER['DOCUMENT_ROOT'])
      ) {
         $urldata = parse_url($url);
         if (empty($urldata['query'])) {
            $host = $protocol.'://'.$_SERVER['HTTP_HOST'];
            if (strpos($url, $host) === 0) {
                // convert URL to full server path
                $tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url);
                $alt[] = htmlspecialchars_decode(urldecode($tmp));
            }
         }
      }
      
            
      //
      if (isset($_SERVER['SCRIPT_URI'])
          && !preg_match('%^(http?|ftp)://%', $file)
          && !preg_match('%^//%', $file)
      ) {
          $urldata = @parse_url($_SERVER['SCRIPT_URI']);
          return $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file;
      }
      
      
      
      
      
      
      $alt = array_unique($alt);
      
      foreach ($alt as $path) {
         $ret = @file_get_contents($path);

         
         if (!empty($ret))
         {
             return $ret;
         }
         // try to use CURL for URLs
         
         if (function_exists('curl_init') && (preg_match('%^(http?|ftp)://%', $path)))
         {
            // try to get remote file data using cURL
            
            
            
            $crs = curl_init();
            curl_setopt($crs, CURLOPT_URL, $path);
            curl_setopt($crs, CURLOPT_BINARYTRANSFER, true);
            curl_setopt($crs, CURLOPT_FAILONERROR, true);
            curl_setopt($crs, CURLOPT_RETURNTRANSFER, true);
            if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) {
                curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true);
            }
            curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($crs, CURLOPT_TIMEOUT, 30);
            curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file');
            $ret = curl_exec($crs);
            $err = curl_error ($crs);
            curl_close($crs);
            
            
         
            
            
            if (!empty($ret)) {
               return $ret;
            }
         }
      }
      return false;
   }



our modifications include:
- change of using FALSE to "not empty" since file_get_contents may return an empty string instead of false in some cases (and php versions)
- making the CURL to be default for both http and https once the file_get_contents does not work

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 3 on Joomla 3.x

cron