stianlik
Forum Replies Created
-
Forum: Plugins
In reply to: [PDF Thumbnails] Plugin does not workIn short, no. You need imagick with ghostscript.
I don’t know the details of the builtin implementation in WordPress, but from what I can glance in the source code it looks like they use imagemagick with ghostwriter as well. To my knowledge, there are not any good alternatives to imagemagick with ghostscript for this feature in PHP.
Not sure why some hosts won’t enable this extension. It can be measure to avoid expensive computations so that they can serve more customers with less hardware. Or, they just want to keep things simple, less extensions and less libraries on their servers can be a good way to reduce maintenance work and avoid potential security issues.
You could use
exec
to call an external program likepdftoppm
to create a thumbnail, but that will require the host to have the given program installed. Alternatively, you could send the PDF from your site to a service (some external API) used for extracting a thumbnail (likely more expensive than switching to a more versatile host). However, the most straightforward solution is to use a host where imagick with ghostscript is available.Forum: Plugins
In reply to: [PDF Thumbnails] Plugin does not workThis plugin use imagemagick to extract the first page of the PDF, if you don’t have imagemagick available, you would have to replace that feature with an implementation in another library (I’m not sure if gd can read PDFs).
The main feature of this plugin, which is to generate an image of the first page in uploaded PDFs is a builtin feature of WordPress 4.7 (and newer version I assume):
WordPress 4.7 makes it easier to preview PDFs in the media library by generating image representations of the first page, which are now used throughout the media library and media attachment screens.
Enhanced PDF Support in WordPress 4.7See the comments in that thread for tips on how you can retrieve these thumbnails.
- This reply was modified 1 year, 8 months ago by stianlik.
Forum: Plugins
In reply to: [PDF Thumbnails] blur and featuredI’m glad you were able to solve the problem.
If you’d like to set the
alt
attribute of the thumbnail to the same as the post title for your attachment (PDF), you should be able to do it with something like the following code sample.The trick is to use
get_post_thumbnail_id($attachmentId)
to get the ID for the generated thumbnail. It is also important that you include the number11
as shown at the bottom, this is the priority of your filter, we use11
to make sure that it is executed after the the thumbnails are generated.add_filter('wp_generate_attachment_metadata', function ($metadata, $attachmentId) { if (get_post_mime_type($attachmentId) === 'application/pdf') { $thumbnailId = get_post_thumbnail_id($attachmentId); if ($thumbnailId) { $pdfAttachment = get_post($attachmentId); if ($pdfAttachment) { update_post_meta($thumbnailId, '_wp_attachment_image_alt', $pdfAttachment->post_title); } } } return $metadata; }, 11, 2);
Note that this code is not tested, you may need to tweak it a bit to make it work.
Forum: Plugins
In reply to: [PDF Thumbnails] blur and featuredYou can adjust thumbnail sizes as described in Post Thumbnails and you may be able to trim the black border using trimImage.
In any case, you may want to look at another plugin or try to use the built-in PDF thumbnail feature from WordPress. PDF Thumbnails is not maintained and was last updated 4 years ago.
Forum: Plugins
In reply to: [PDF Thumbnails] blur and featuredI haven’t tested this, but I think you have to rearrange the code so that
$imagic->blurImage
is placed after$imagic->setImageFormat
. I don’t think you can blur the image before we have selected an image to work with.$imagick = new Imagick($filename); $imagick->setIteratorIndex(0); $imagick->setImageFormat('jpg'); $imagick->blurImage(5,3); return $imagick->getImageBlob();
Forum: Reviews
In reply to: [PDF Thumbnails] No longer supportedYou’re right, this plugin is not actively maintained. WordPress introduced a built-in feature for generating PDF thumbnails in version 4.7, making this plugin obsolete, see https://core.trac.www.ads-software.com/ticket/31050 . As far as I know, it has not been tested in WordPress 5.
The next time you find yourself struggling to figure out how to use a free plugin that someone created so that you could spend more time drinking coffee and munching cookies, I suggest posting a friendly support request in the support thread to figure out where the problem is located.
Forum: Plugins
In reply to: [PDF Thumbnails] Shortcode drops an empty link into the page…Actually, this plugin was created before WordPress supported PDF thumbnails, the main purpose was to generate these thumbnails. Now that WordPress has enhanced PDF Support, this plugin is no longer necessary.
Forum: Plugins
In reply to: [PDF Thumbnails] Shortcode drops an empty link into the page…You’re suppose to get a linked image of the PDF. For the thumbnails to be generated, the PDF must be uploaded after you enable the plugin*, otherwise, you’ll not get an image in the link (i.e. the thumbnail does not exist). Does this apply to the PDF you’re using to test this plugin? Can you try to upload a new PDF and see if that changes anything?
This is not a known issue, however, I have not tested the plugin for the latest version of WordPress. Please let me know if this resolves your issue.
* You can generate thumbnails for all existing PDFs by following the instructions in this support ticket.
Forum: Plugins
In reply to: [PDF Thumbnails] Black areas on thumbnailsI haven’t tested this, but you may be able to disable the alpha channel using setImageAlphaChannel with imagick::ALPHACHANNEL_DEACTIVATE. Also, see related StackOverflow answer.
- This reply was modified 7 years, 7 months ago by stianlik.
Forum: Plugins
In reply to: [PDF Thumbnails] Program to create thumbnailSorry for the late response, I thought I had answered this one already.
You are correct, the plugin attaches to the
wp_generate_attachment_metadata
event, which is triggered on file uploads. Using a third-party plugin like ACF, may require some custom code to trigger the generator.I have not implemented a public API for this, but it is possible to trigger the process manually by calling
pdf_thumbnails_generate_attachment_metadata(null, $attach_id)
, see source code.You may also get some useful information from the thread Regenerate Thumbnails.
- This reply was modified 7 years, 11 months ago by stianlik.
Forum: Plugins
In reply to: [PDF Thumbnails] Fatal error: Uncaught ImagickExceptionNo activity in two months, marking as resolved.
Forum: Plugins
In reply to: [PDF Thumbnails] Regenerate ThumbsYou can use the code posted in this support thread.
Unfortunately, the regenerate thumbs plugin only regenerate thumbnails for images. I tried contacting the author to see if we could make it work with PDFs as well, but I never received a response.
Forum: Plugins
In reply to: [PDF Thumbnails] No php ext imagemagickHi,
I did not have plans to implement fallback to the command line tool, but it looks like it can be done without too much of an effort. I will look into this and come back to you.
Forum: Plugins
In reply to: [PDF Thumbnails] Fatal error: Uncaught ImagickExceptionCould you try to upload the same file without period a in the filename? I’m not sure, but there may be some issues with the file name sanitazion used in WordPress.
Forum: Plugins
In reply to: [PDF Thumbnails] ImageMagick & 1and1It seems strange that you need to know the path for ImageMagick in a PHP script, those details are handled by the ImageMagick PHP extension. The plugin relies on the following components:
– Ghostscript
– ImageMagick
– PHP extension for ImageMagickYou can check your environment by saving the following to a php-file and inspecting the results in your web browser:
<?php phpinfo();
You should find an entry for ImageMagick with PDF as a supported format. See also the installation instructions, that’s a list of tasks that the hosting provider needs to perform to prepare for the plugin.
- This reply was modified 8 years, 3 months ago by stianlik.