Index: src/wp-includes/class-wp-image-editor-imagick.php
===================================================================
--- src/wp-includes/class-wp-image-editor-imagick.php	(revision 47310)
+++ src/wp-includes/class-wp-image-editor-imagick.php	(working copy)
@@ -140,16 +140,17 @@
 		try {
 			$this->image    = new Imagick();
 			$file_extension = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );
-			$filename       = $this->file;
 
 			if ( 'pdf' === $file_extension ) {
-				$filename = $this->pdf_setup();
+				$pdf_loaded = $this->pdf_load_source();
+
+				if ( is_wp_error( $pdf_loaded ) ) {
+					return $pdf_loaded;
+				}
+			} else {
+				$this->image->readImage( $this->file );
 			}
 
-			// Reading image after Imagick instantiation because `setResolution`
-			// only applies correctly before the image is read.
-			$this->image->readImage( $filename );
-
 			if ( ! $this->image->valid() ) {
 				return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
 			}
@@ -165,6 +166,7 @@
 		}
 
 		$updated_size = $this->update_size();
+
 		if ( is_wp_error( $updated_size ) ) {
 			return $updated_size;
 		}
@@ -785,10 +787,13 @@
 	 * Increases rendering DPI and only loads first page.
 	 *
 	 * @since 4.7.0
+	 * @deprecated 5.5.0 use WP_Image_Editor_Imagick::pdf_load_source() that also loads the source.
 	 *
 	 * @return string|WP_Error File to load or WP_Error on failure.
 	 */
 	protected function pdf_setup() {
+		_deprecated_function( __FUNCTION__, '5.5.0', 'WP_Image_Editor_Imagick::pdf_load_source()' );
+
 		try {
 			// By default, PDFs are rendered in a very low resolution.
 			// We want the thumbnail to be readable, so increase the rendering DPI.
@@ -805,4 +810,40 @@
 		}
 	}
 
+	/**
+	 * Sets up Imagick for PDF processing and load the image outputted by `gs`.
+	 * Increases rendering DPI and only loads first page.
+	 *
+	 * @since 5.5.0
+	 *
+	 * @return true|WP_Error True on success, WP_Error on failure.
+	 */
+	protected function pdf_load_source() {
+		// By default, PDFs are rendered in a very low resolution.
+		// We want the thumbnail to be readable, so increase the rendering DPI.
+		// (`setResolution` has to be done before the image is loaded.)
+		$this->image->setResolution( 128, 128 );
+
+		try {
+			// When generating thumbnails from cropped PDF pages, Imagemagick uses the uncropped
+			// area (resulting in unnecessary whitespace) unless the following option is set.
+			$this->image->setOption( 'pdf:use-cropbox', true );
+
+			// Only load the first page.
+			$this->image->readImage( $this->file . '[0]' );
+		} catch ( Exception $e ) {
+			try {
+				// Attempt to run `gs` without the `use-cropbox` option.
+				// This is a workaround for a bug in GNU Ghostscript 8.7 (and possibly other old versions)
+				// that may prevent processing of some PDF files when `use-cropbox` is set. See #48853.
+				$this->image->setOption( 'pdf:use-cropbox', false );
+				$this->image->readImage( $this->file . '[0]' );
+			} catch ( Exception $ex ) {
+				return new WP_Error( 'pdf_setup_failed', $ex->getMessage(), $this->file );
+			}
+		}
+
+		return true;
+	}
+
 }
