I’m using Laravel Herd for my local WordPress development, and yesterday I ran into an issue where PDF thumbnails were not being generated in the media library—despite Imagick being installed and active.
Trying to generate the thumbnails with WP-CLI surfaced the issue:
❯ wp media regenerate 2326
Found 1 image to regenerate.
sh: gs: command not found
sh: gs: command not found
Warning: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r128x128' -dPrinted=false -dFirstPage=1 -dLastPage=1 '-sOutputFile=/var/folders/6s/yrvd3kg525q_n3ywvhl4rzgw0000gn/T/magick-n5CqEYIrCJPU1kYNi0ToLxniFH9yNsSg%d' '-f/var/folders/6s/yrvd3kg525q_n3ywvhl4rzgw0000gn/T/magick-MqapqAJec0zih_qRP_6AZGLwl92dCGVp' '-f/var/folders/6s/yrvd3kg525q_n3ywvhl4rzgw0000gn/T/magick-lNEuu5q0irGpKT9nphKngGLC2c7PckxC'' (32512) @ error/ghostscript-private.h/ExecuteGhostscriptCommand/75 (ID 2326)
As it turns out, PHP couldn’t find the Ghostscript command, which is required for reading and interpreting PDF files.
The solution was to install Imagick and Ghostscript through Homebrew, and point my PHP configuration to those installations. First, install the required packages through Homebrew:
brew install imagemagick
brew install ghostscript
Then, add the following line to your PHP FPM configuration:
env[PATH] = /opt/homebrew/bin
The path to your configuration file depends on which tool you’re using for your local installation. For Laravel Herd, the path is ~/Library/Application Support/Herd/config/fpm/8.3-fpm.conf
, where 8.3
is the PHP version you’re using.
You should now be able to generate thumbnails for your PDF files. Use this handy command to automatically regenerate thumbnails for all existing PDF files:
wp media regenerate $(wp post list --post_type=attachment --post_mime_type=application/pdf --format=ids)
Leave a Reply