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

Error displaying image. Any solution? #2966

Closed
zlukasmoura opened this issue Jul 28, 2022 · 5 comments
Closed

Error displaying image. Any solution? #2966

zlukasmoura opened this issue Jul 28, 2022 · 5 comments
Labels

Comments

@zlukasmoura
Copy link

image
image

@bsweeney
Copy link
Member

Have you allowed remote files (set isRemoteEnabled to true)? I know "localhost" is not a remote URL but as far as Dompdf is concerned anything accessed over HTTP is remote.

@Ajility97
Copy link

@bsweeney I'm using laravel-dompdf wrapper (dompdf 1.2.2) and having the same issue.

Offending line:
<img class="{{ $logo->class }}" src="{{ $logo->url }}" alt="logo"/>

Result:
image

config/dompdf.php:
'enable_remote' => true

$logo->url is a temporary URL to a JPG image in AWS S3. It looks something like this:
https://bucketname.s3.amazonaws.com/10/400px.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA3REDACTEDTHIS%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220802T160626Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86400&X-Amz-Signature=REDACTEDTHIS

It works fine in my local environment, but fails in our staging environment, don't see anything in the PHP log. I'm having trouble finding out why.

Things I've confirmed about the staging environment:

  • The temporary directory is writeable by the webserver process.
  • gd extension is enabled
  • allow_url_fopen is true
  • Environment uses a wildcard SSL certificate

@bsweeney
Copy link
Member

bsweeney commented Aug 2, 2022

Sounds like you've done the basics with regard to trouble-shooting. I don't have any additional thoughts off the top of my head. You might try enabling additional debugging (debug configuration in the wiki).

@Ajility97
Copy link

As a note to anyone who runs into this, my work-around was to base64 encode the image. No issues that way, and I default to a local image on error:

...
    private function getLogoTemporaryUrl(): string
    {
        return $this->logo?->getTemporaryUrl(now()->addMinutes(15)) ?? public_path('images/error-image.png');
    }

    public function getLogoBase64(): ?string
    {
        $mimeType = $this->logo?->mime_type ?? 'image/png';

        return 'data:' . $mimeType . ';base64, ' . base64_encode(
            file_get_contents($this->getLogoTemporaryUrl())
        );
    }
...

@bsweeney
Copy link
Member

bsweeney commented Aug 3, 2022

@Ajility97 yeah that is definitely one way around the issue. Sorry I didn't have any better advice on what was causing problems fetching the image.

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

No branches or pull requests

3 participants