admin管理员组

文章数量:1122832

I'm trying to figure out why one of my WordPress sites is not generating thumbnails for PDF uploads. It works on my dev and staging sites. When comparing them, the only difference that I can find is that my production site is running PHP 7.2, whereas dev and staging are running PHP 7.3. I have the imagick extension installed on all of them.

Thumbnails are being generated for image files - it's only PDF files that aren't working. The iMagick PHP extension should be all that's needed, right? I've turned on WordPress debug logging and looked for errors there and in the Apache error logs, but have found nothing.

Any suggestions?

I'm trying to figure out why one of my WordPress sites is not generating thumbnails for PDF uploads. It works on my dev and staging sites. When comparing them, the only difference that I can find is that my production site is running PHP 7.2, whereas dev and staging are running PHP 7.3. I have the imagick extension installed on all of them.

Thumbnails are being generated for image files - it's only PDF files that aren't working. The iMagick PHP extension should be all that's needed, right? I've turned on WordPress debug logging and looked for errors there and in the Apache error logs, but have found nothing.

Any suggestions?

Share Improve this question asked Jul 12, 2021 at 17:09 eljefejbeljefejb 6512 gold badges7 silver badges16 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

I found a solution! I hope this helps save some time and frustration for others that might encounter this problem. It turns out that it isn't WordPress or PHP.

After a lot of digging, I came across this discussion by some members of the WordPress Core team: https://core.trac.wordpress.org/ticket/48853. It says that there is some kind of issue in Ghostscript 8.70 and below that prevents the thumbnails from being generated for PDFs. So, I checked the installed version of Ghostscript. Sure enough, it's 8.70. I looked for a yum update, but 8.70 is the latest available for the server OS (CentOS 6).

I saw several posts that described installing a newer version from a tar.gz file, so I tried that using the defaults. WordPress still would not generate PDF thumbnails. Rats. Even though the command line reported the newer version of Ghostscript, it was like WordPress didn't see it. Then I saw a post somewhere that seemed to indicate that WordPress was looking in /usr/bin for the Ghostscript executable. The default ./configure command (with no arguments) installed GS in /usr/local/bin. After installing GS into /usr/bin instead, WordPress was finally able to generate PDF thumbnails!

Here are the steps for CentOS 6:

  1. wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs919/ghostscript-9.19.tar.gz (I saw somewhere that if you go higher than that version with CentOS 6, you'll have to mess with updating compilers and linkers and whatnot.)
  2. tar -zxvf ghostscript-9.19.tar.gz
  3. cd ghostscript-9.19
  4. ./configure --prefix=/usr (To install where WordPress expects to find GS)
  5. make
  6. sudo make install

That's it! I also bounced Apache for good measure, but I'm not sure that's necessary. Hope this helps!

Another possible cause if images are producing thumbnails but PDFs are not is the security policy in ImageMagick. (This may have been relevant to @omega33's comment.) If so, PDF thumbnail creation fails silently even with WP_DEBUG on, but wp media regenerate may show the error. See https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion After editing /etc/ImageMagick-6/policy.xml you may need to restart PHP-FPM or the web server.

If it's only affecting some images and not all PDFs, it may instead be some kind of timeout or conceivably a quota problem.

本文标签: Why are thumbnails not being generated for PDF files