前言介紹
- 這款 WordPress 外掛「PDF Thumbnails」是 2014-04-06 上架。
- 目前有 1000 個安裝啟用數。
- 上一次更新是 2016-10-24,距離現在已有 3113 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 有 9 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
內容簡介
此外掛在媒體管理員中加入 hook,每當上傳 PDF 時就會產生縮圖。所產生的縮圖為所上傳文件中的第一頁圖像,並以 PDFNAME-thumbnail 命名,其中 PDFNAME 會被替換為所上傳文件名稱。
產生的縮圖等同於 特色圖像,因此可以使用常見的縮圖函數,例如 get_post_thumbnail_id(),而這些函數也可以用於 PDF 附件。有關如何有效使用縮圖的資訊,請參閱 推薦圖片功能。
目前尚未整合 JavaScript 媒體 API,因此上傳後可能需要重新載入頁面,才能看到產生的縮圖。
Shortcodes
使用 [pdf_thumbnails_link] shortcode 可以顯示連結到上傳 PDF 的縮圖。以下支援的屬性:
id – 附件 ID(必填)
size – 縮略圖尺寸(可選)
title – 錨點標題屬性(選用)
target – 錨點目標屬性(選用)
download – 下載屬性(選用)
範例 1:使用預設縮圖尺寸顯示 ID = 172 的 PDF 連結
[pdf_thumbnails_link id="172"]
範例 2:使用縮圖尺寸(預設值為 150x150)顯示 ID = 172 的 PDF 連結
[pdf_thumbnails_link id="172" size="thumbnail"]
感謝 mirgcire 提供第一個 [pdf_thumbnails_link] shortcode。
Developer API
在大多數情況下,使用 WordPress API 的內建縮圖函數(例如 get_post_thumbnail 和類似函數)即可滿足需求。如果需要更改縮圖生成方式,可以使用 pdf_thumbnails_generate_image_blob filter 覆寫圖像生成。
範例 1:增加所有生成 PDF 縮圖的解析度
// $blob 為目前的圖像 blob(預設為 null,可用於串連)
// $filename 為 PDF 檔案名稱
add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
$imagick = new Imagick();
$imagick->setResolution(200,200);
$imagick->readImage($filename);
$imagick->setIteratorIndex(0);
$imagick->setImageFormat('jpg');
return $imagick->getImageBlob();
}, 10, 2);
也可以使用 pdf_thumbnails_link_shortcode filter 修改產生的縮圖連結,以下是可用的屬性:
$html – 生成的 HTML 代碼以顯示
$attachmentId – 已清理的 PDF 附件 ID
$size – 使用的縮略圖尺寸
原文外掛簡介
This plugin hooks into the media manager and generates a thumbnail everytime a
PDF is uploaded. Generated thumbnail is an image of the first page in the
uploaded document and is named PDFNAME-thumbnail, where PDFNAME is replaced
by uploaded document filename.
Generated thumbnails are equivalent to featured
images so that common thumbnail
functions like get_post_thumbnail_id() can be used for PDF attachments. See
Post Thumbnails for information
on how you can use thumbnails efficiently.
Integration with the javascript media API is not yet implemented, therefore, you
may need to reload the page before you can see generated thumbnail after an
upload.
Shortcodes
It is possible to display a thumbnail linking to an uploaded PDF using the [pdf_thumbnails_link]
shortcode. The following attributes are supported:
id – Attachment ID (required)
size – Thumbnail size (optional)
title – Anchor title attribute (optional)
target – Anchor target attribute (optional)
download – Anchor download attribute (optional)
Example 1: Display link to PDF with ID = 172 using default thumbnail size
[pdf_thumbnails_link id="172"]
Example 2: Display link to PDF with ID = 172 using thumbnail size (default 150×150)
[pdf_thumbnails_link id="172" size="thumbnail"]
Thanks to mirgcire for providing the first
version of the [pdf_thumbnails_link] shortcode.
Developer API
In most cases it should be sufficient to use built-in thumbnail functions from
the WordPress API (get_post_thumbnail and similar). If you need to modify the
way thumbnails are generated, you can override image generation with
the pdf_thumbnails_generate_image_blob filter.
Example 1: Increase resolution for all generated PDF thumbnails
// $blob is the current image blob (defaults to null, can be used for chaining)
// $filename is the PDF filename
add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
$imagick = new Imagick();
$imagick->setResolution(200,200);
$imagick->readImage($filename);
$imagick->setIteratorIndex(0);
$imagick->setImageFormat('jpg');
return $imagick->getImageBlob();
}, 10, 2);
It is possible to modify generated thumbnail links using the pdf_thumbnails_link_shortcode
filter. The following attributes are available:
$html – Generated HTML code to be displayed
$attachmentId – Sanitized ID of the PDF attachment
$size – Sanitized thumbnail size
$atts – Shortcode attributes (not sanitized)
$content – Shortcode content (not sanitized)
Example 2: Wrap thumbnail link in figure and append caption
add_filter('pdf_thumbnails_link_shortcode', function ($html, $attachmentId, $size, $atts, $content) {
return "
";
}, 10, 5);
TODO
Add generated image to media browser after upload.
Outline of an implementation based on the javascript media API:
// New uploads
wp.Uploader.queue.on('add', function (attachment) {
if (attachment.subtype !== 'pdf') {
return;
}
findThumbnailFor(attachment.ID).then(function (data) {
// Add attachment thumbnail to browser
var attachment = wp.media.model.Attachment.get(id)
attachment.fetch().done(function () {
wp.media.editor.open().state().get('library').add(generated attachment)
});
});
});
Filter: ajax_query_attachments_args
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「PDF Thumbnails」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
0.0.2 | 0.0.3 | 0.0.4 | 0.0.5 | 0.0.6 | 1.0.0 | 1.0.1 | 1.0.2 | 2.0.0 | 2.1.0 | 2.2.0 | trunk |
延伸相關外掛(你可能也想知道)
WP Sitemap Page 》透過這個 WordPress 外掛,您現在可以輕鬆將站點地圖加入到任何一個頁面中。只需要在您的頁面上使用簡碼 [wp_sitemap_page] 即可。這會自動生成您所有網頁和...。
FakerPress 》當您創建新的主題或外掛時,您總是需要創建自訂數據以測試您的外掛是否正常運作,作為開發人員,我們自己也遇到過這個問題。, 我們這個外掛的目標是填補這個...。
SMK Sidebar Generator 》這個外掛可以生成任意數量的側邊欄,然後讓你將它們放置在你想要的任何頁面。, , 特色:, , 無限數量的側邊欄。, 使用條件替換預設主題側邊欄,或全局替換只...。
Child Theme Wizard 》Child Theme Wizard 讓你在 WordPress 的管理介面中輕鬆創建子佈景主題,不需額外的工具。啟用後,你可以在「工具」-「Child Theme Wizard」中找到它。, 指定...。
WPS Child Theme Generator 》中文, WPS Child Theme Generator 是一款高級工具,可以輕鬆創建所需的子佈景主題。它提供許多選項,可以添加到 functions.php 中,而無需修改它。您也可以將...。
Heroic Favicon Generator 》“最佳的網站圖示外掛程式” ★★★★★ - WordPress.org 使用者評論。, 簡單強大的 WordPress 網站圖示外掛程式。, 使用 Heroic Favicon Generator 快...。
Simple XML Sitemap Generator 》XML Sitemap外掛可建立符合Google、Yahoo(以及Bing)要求的XML檔案。, , 只要安裝此外掛程式至WordPress,它便會自動運作。您只需要創建或更新任何文章或頁...。
Browser Screenshots 》使用 [browser-shot] 短代碼來自動化網站截圖的過程。一個圖示也會被加入 TinyMCE 編輯器中,以方便製作短代碼。, 外掛使用從 WordPress.com 取得的「mshots...。
AI WP Writer – best AI content generator, ChatGPT, GPT-4.1, Dalle 3, FLUX 》網站內容創作外掛使用 ChatGPT、GPT-4 及最佳神經網絡進行圖像生成,可快速有效填充網站。透過 AI WP Writer 外掛,您能輕鬆創建獨特、高品質和 SEO 最佳化的...。
Featured Image Generator 》您曾經為網站尋找特色圖片而感到困難嗎?這個外掛可以在 unsplash.com 等免費授權的優秀照片中搜尋,並在一個按鈕中將其導入到您的網站。該外掛包括圖層、色...。
PDF Thumbnail Generator 》his plugin automatically generates a thumbnail for PDF files when they are uploaded to the WordPress Media library. It can also generate missing th...。
EZ Form Calculator 》ez Form Calculator是一個直覺式的WordPress表單建立工具。輕鬆地建立表單計算器、進階成本估算器或全面的聯繫表單,讓你的網站更易獲取商機。利用ez Form Ca...。
Bulk Page Generator 》Bulk Page Generator 可以幫助您減少工作量並節省寶貴的時間。使用此外掛,用戶可以使用最簡單的用戶界面輕鬆創建頁面/文章,該界面提供了創建頁面/文章時必...。
QR Code Creator 》這是一個 WordPress 外掛,可幫助您建立 QR 碼。, 使用條款, 此外掛使用第三方服務(goqr.me)來建立 QR 碼。根據它的服務條款,它不會在任何給定的時間儲存...。
Remove Meta Generators 》這個外掛可以移除所有 Meta Generator HTML 標籤,包括 WordPress 核心自帶的 generator 標籤。安裝、啟用即可輕鬆使用,而後您的 HTML/源代碼中不再包含 Met...。