phpyii2mpdf

MpdfException IMAGE Error () : Error parsing image file - Yii2


I'm stuck in very awkward situation where Images are being shown in Local Environment while generating PDF. But, Not in Production. Images being displayed as [X] when to generate PDFs with mPDF.

After inserting $mpdf->showImageErrors = true; in Controller.

public function actionExportCasesPdf($id) {
  .
  .
  .
  .
  $mpdf = new \mPDF();
  $mpdf->showImageErrors = true;
  $mpdf->WriteHTML($output);
  $mpdf->Output($fileName, 'D');
}

Error

MpdfException

IMAGE Error (..17.jpg): Error parsing image file - image type not recognised, and not supported by GD imagecreate

Even, GD library is installed in the server using apt-get install php5-gd command. And, Image Path are also used correct.

I tried to keep image source as such. But, No Luck.

<img src="<?= \yii\helpers\Url::to('@web/images/logo.png', true) ?>" width="100" alt="logo" />

I searched and tried the solution given by these links. But, still no luck :

  1. Images not showing on production but they do on local environment - GitHub
  2. mPDF 5.7.1 - image displays as a broken [x]
  3. Generated picture in mpdf
  4. Error parsing image file

Any help/hint/suggestion is appreciable.


Solution

  • It throws one new error

    failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

    So, problem was : server was secured with password. So, I searched for it to find the way. And, File-get-contents failed to open stream Unauthorized is having correct answer related to above error.

    http://user_name:password@your_site.com/append_your_url 
    

    After appending user name, password and site name as above, It worked correctly.

    Related Search

    1. Images not showing on production but they do on local environment - GitHub
    2. mPDF 5.7.1 - image displays as a broken [x]
    3. Generated picture in mpdf
    4. Error parsing image file