Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images not showing on production but they do on local environment #19

Closed
evilito opened this issue Jul 9, 2015 · 10 comments
Closed

Images not showing on production but they do on local environment #19

evilito opened this issue Jul 9, 2015 · 10 comments

Comments

@evilito
Copy link

evilito commented Jul 9, 2015

Hello, I have a couple of simple PNG images in a view print.php, like this:

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

In the local environment, the images shows fine in the generated PDF and even if I just print it without PDF (controller code):

        return $this->renderPartial('print', [
            'model' => $this->findModel($id),
        ]);

However, on the production server, the images are not showing. They show only if I print the view without PDF (like in the previous code), so for me this means that the images are fine, no broken links (because they show on renderPartial) and leads me to think that there might be some issue with the mpdf?

The generated PDF in the production server shows a red "X" where the image should be loaded. How can I troubleshoot this? Can the PDF be examined? If it was an HTML page I would check where the link in "src" is leading, but in the PDF I'm not sure how to proceed.

Local environment is PHP 5.5 and production is PHP 5.6. Does this has something to do?

Any help will be really welcomed and appreciated!

@evilito
Copy link
Author

evilito commented Jul 9, 2015

The problem was that mpdf doesn't understand well relative paths for images, even if the web browser is fine with them and display the images correctly.

The fix was to generate a path with an absolute base URL, in this case, by setting the second parameter of the "Url::to" function to true, as per the documentation.

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

I hope this helps others having the same issue. Thank you.

@ivanlemeshev
Copy link

The absolute URL didn't solve this problem to me. But using base64 image instead solve it.

@shakalvv
Copy link

shakalvv commented Aug 5, 2016

I had the same problem. The absolute URL and base64 -- didn't work.
You can set $this->_mpdf->showImageErrors = true; in file ... /vendor/kartik-v/yii2-mpdf/Pdf.php in method setApi(). Then you can see the error.
In my case, I had issues with gd (Error parsing image file - image type not recognised, and not supported by GD imagecreate). I changed picture and it helped.

@sunilsoftkochi
Copy link

My problem was a different one and i had problem in local server as well as in the hosting server. I solved problem with a shortcut that I copied the images to web folder instead of database. After the change the application worked without issues.

@spirit-of-wars
Copy link

The absolute URL and base64 -- didn't work me too. I install php5-gd and this solved my problem.

@bdionis
Copy link

bdionis commented May 19, 2017

HI, just try to install php7.0-gd
http://stackoverflow.com/a/22575654/6547455

@parambursys
Copy link

parambursys commented Sep 13, 2017

Hi, just clean browser history or update browser.

@josmanaba
Copy link

Inside the MPDF directory there is a subdirectory "tmp", you need to give write permissions to it.

@MloneThakuri
Copy link

i have problem in uploading the img in yii2, my yii2 framework is in latest version. And i have uploaded some img in home page using code (src="img/product.jpg") and it's working but when i click on another page and come back to the home page , the img is not displaying and it needs code (src="../img/product.jpg") to display it on home page. so why is that? please help me solve this problem.

@aBahrami13
Copy link

aBahrami13 commented Jul 23, 2022

I had a same problem because of SSL error!
If peer verification fails in ssl hand shake, it will not show the image.
I 'm using 8.0.15 version of mpdf, in getImage() function of vendor/mpdf/mpdf/src/Image/ImageProcessor.php the file_get_contents is used and there is no way to pass context options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests