• Hello,

    Images that are .png are not being output in the PDFs. JPG is showing fine. Below is the code where the image is output.

    Please advise why this might be happening, and what can be done to resolve it.

    <?php
    $image = wp_get_attachment_image( get_post_thumbnail_id(), 'full', null, array( 'class' => 'post-image' ) );
    
    if( $image ) {
        echo $image;
    }
    ?>
    • This topic was modified 7 years, 1 month ago by cgoodrich.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi, If you see [X] in place of image try this solution

    1- try not to include the domain in the URL

    change this : https://www.yourdomain.com/wp-content/upload/blablablabla
    to this : wp-content/upload/blablablabl
    or this : /wp-content/upload/blablablabla

    this means dont use “wp_get_attachment_image” but use “get_the_post_thumbnail_url()”
    and then remove the site url from the full URL , something like

    $siteURL = get_site_url()."/"; 
    $imgurl = get_the_post_thumbnail_url();
    $imgurlonly = str_replace($siteURL,"",$courseImg);

    2- if the above didnt work try to go to /wp-content/plugins/dk-pdf/includes/dkpdf-functions.php and paste the below line after line 186

    $mpdf->showImageErrors = true;

    now when you generate the PDF the error will show up for you and you can debug or post it here

    hope your issue will be solved

    • This reply was modified 7 years, 1 month ago by justtryit87. Reason: spelling error
    • This reply was modified 7 years, 1 month ago by justtryit87.
    Plugin Author dinamiko

    (@dinamiko)

    @justtryit87 Thank you very much for the detailed information, I’ll add it to as FAQ at some point in the near future, that way other users will find it more easily.

    Simon

    (@simonmaddox)

    Is there anything you can do to get .png images working without having to edit the source code of each post, Emili?

    I notice that even the header logo fails if it’s a .png

    Simon

    (@simonmaddox)

    Cancel that – I found that I didn’t have GD loaded for php7

    sudo apt-get install php7.0-gd then restart Apache and all is working well.

    Maybe a check for this dependency and a warning would be helpful for other users?

    • This reply was modified 7 years, 1 month ago by Simon.
    Gerald

    (@gerital)

    I also see a [X] in place of image and tried to debug the error adding $mpdf->showImageErrors = true; to dkpdf-functions.php. Where should I see the output of mpdf image errors, in the PDF or somewhere in the logs?

    I see the red [X] appear when on versions of PHP higher than 5.5.38. I recently changed my MAMP install to PHP version 5.6.31 and the images were no longer showing. I switched back to 5.5.38 and also tried 5.4.45 and the images are showing again.

    When I was debugging in PHP version 5.6.31 using the $mpdf->showImageErrors = true; method above, I received the following error:

    “mPDF error: IMAGE Error (//localhost:3000/wp-content/uploads/2017/10/logo-jsslaw-all-gray.png): Could not find image file”

    I tried replacing the src="<?php echo $pdf_header_image_attachment[0];?>" in the dkpdf-header.php file to the relative path of the image (no //localhost:300) and still no luck. I confirmed it was in the uploads folder under the correct path. I assume it would not work for previous versions of PHP if the path was incorrect.

    Is there a “best practice” in terms of what PHP version we should be using to ensure DK PDF’s best performance?

    Also, if the following method brought up by @justtryit87 is the correct solution, where does the code below need to be placed?

    $siteURL = get_site_url()."/"; 
    $imgurl = get_the_post_thumbnail_url();
    $imgurlonly = str_replace($siteURL,"",$courseImg);

    Thank you in advance! This is a great plugin!

    Thread Starter cgoodrich

    (@cgoodrich)

    Some great debugging here! Very useful suggestions.

    @justtryit87 or @dinamiko – can you please advise where the below code should go?

    
    $siteURL = get_site_url()."/"; 
    $imgurl = get_the_post_thumbnail_url();
    $imgurlonly = str_replace($siteURL,"",$courseImg);
    

    is this a 800lb gorilla in the room?

    $siteURL = get_site_url()."/"; 
    $imgurl = get_the_post_thumbnail_url();
    $imgurlonly = str_replace($siteURL,"",$courseImg);

    shouldn’t this code read …

    $siteURL = get_site_url()."/"; 
    $imgurl = get_the_post_thumbnail_url();
    $imgurlonly = str_replace($siteURL,"",$imgurl);

    otherwise I don’t see where it would work?

    -DJ

    • This reply was modified 6 years, 6 months ago by damelco.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘.png images not showing in PDFs’ is closed to new replies.