Automattic/regenerate-thumbnails

PDF images don't regenerate in WordPress v5.3.2 (fix included)

Opened this issue · 2 comments

The PDF files were skipped and thumbnails weren't generating. Tracked down the issue to a function get_fullsizepath() on lines 130-135 in file class-regeneratethumbnails-regenerator.php. The function wp_get_original_image_path() will return false for PDF file.

The fix is to check for the false positive and fetch PDFs properly.

Code before:

		if ( function_exists( 'wp_get_original_image_path' ) ) {
			$this->fullsizepath = wp_get_original_image_path( $this->attachment->ID );
		} else {
			$this->fullsizepath = get_attached_file( $this->attachment->ID );
		}

Code with a fix:

		if ( function_exists( 'wp_get_original_image_path' ) ) {
			$this->fullsizepath = wp_get_original_image_path( $this->attachment->ID );
		} else {
			$this->fullsizepath = get_attached_file( $this->attachment->ID );
		}
		// If the function exists and the path is not set, then we likely have a PDF file, try getting the path from attached file funciton
		if ( function_exists( 'wp_get_original_image_path' ) && ! $this->fullsizepath ) {
			$this->fullsizepath = get_attached_file( $this->attachment->ID );
		}

The code indicated by @makbeta above seems to work for Regenerate Thumbnails version 3.1.5 as of 2022-06-01 (using WordPress version 6.0).

However, to regenerate a thumbnail for a PDF in the Media Library, you can only do that if you use the Bulk Actions in the Media Library and have selected a PDF using the checkbox. (That is, the option to regenerate a PDF thumbnail does NOT appear when editing the Media, nor does it appear below the title of the Media in the Media Library list view.)

docs pdfs do not allow thumbnail regneration
docs you must click a checkbox and choose Bulk Actions in order to regenerate PDF

Also, IMHO the thumbnail generated is very bitmappy, and yes, ImageMagick library is in PHP.

However, to regenerate a thumbnail for a PDF in the Media Library, you can only do that if you use the Bulk Actions in the Media Library and have selected a PDF using the checkbox. (That is, the option to regenerate a PDF thumbnail does NOT appear when editing the Media, nor does it appear below the title of the Media in the Media Library list view.)

This is true. However, if you do a bulk operation of attachments of various types, the error message is confusing ant unnecessary.
Skipped Attachment ID nnnn (filename): The fullsize image file cannot be found in your uploads directory at . Without it, new thumbnail images can't be generated.

Also, IMHO the thumbnail generated is very bitmappy, and yes, ImageMagick library is in PHP.

I know users who rely on the PDF bitmaps, and they are created in multiple resolutions from full-size, 1024 height and downwards, so I've not been seeing the poor image quality other people have reported.

I've submitted a merge request for commit 27c7083.