1====== mediathumbnails Plugin ====== 2 3---- plugin ---- 4description: Extracts a thumbnail from media files (ODT, DOCX, PPTX, PDF, JPG, etc.) in a media library and shows it on the wiki page. 5author : Thomas Schäfer 6email : thomas@hilbershome.de 7type : syntax 8lastupdate : 2025-10-11 9compatible : Hogfather, Igor, Jack Jackrum, Kaos, Librarian 10depends : 11conflicts : 12similar : 13tags : images, media, mediamanager, thumbnail, odt, pdf 14 15downloadurl: https://github.com/ternite/dokuwiki-plugin-mediathumbnails/archive/v0.94.zip 16bugtracker : hhttps://github.com/ternite/dokuwiki-plugin-mediathumbnails/issues 17sourcerepo : https://github.com/ternite/dokuwiki-plugin-mediathumbnails 18donationurl: 19 20screenshot_img : 21---- 22 23===== What's it for? ===== 24 25This plugin will show thumbnail images for supported media files (ODT, DOCX, PPTX, PDF, JPG, etc.) within your wiki pages. 26 27In default settings, a click in the thumbnail will have your browser download the media file. 28 29And an error message will be shown by default in case a referenced media file does not contain a thumbnail (office files) or is an unsupported file type (see dependencies on how you might work around that). 30 31===== Installation and Dependencies ===== 32 33Install the plugin using the [[plugin:plugin|Plugin Manager]] and the download URL above, which points to latest version of the plugin. Refer to [[:Plugins]] on how to install plugins manually. 34 35:!: **External requirements:** Office files (ODT, DOCX, PPTX, etc.) are supported natively. If you need image or PDF support, this plugin requires the following additional components that must be installed and integrated into your PHP environment separately: 36 37 * Support for Office file thumbnails: 38 * [[https://www.php.net/manual/de/book.zip.php|zip]] PHP extension 39 * libzip-dev (needed by zip) - your installation might already have this installed, or not. 40 * Support for PDF and image thumbnails: 41 * [[https://imagemagick.org|ImageMagick]] 42 * [[https://github.com/Imagick/imagick|Imagick]] (PHP extension for ImageMagick integration) 43 * [[https://www.ghostscript.com/index.html|GhostScript]] //(obligatory only for PDF support)// 44 45Hints: 46 * ImageMagick installation might be troublesome. At least it was for me. My installation routine on Windows 10 x64 in detail: 47 * Install ''Ghostscript 9.56.1'' ([[https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs9561/gs9561w64.exe|gs9561w64.exe]]). 48 * Ascertain that GS's ''bin'' folder was added to the System PATH variable. 49 * Install ''ImageMagick 7.1.0'' for x64 ([[https://windows.php.net/downloads/pecl/deps/ImageMagick-7.1.0-18-vc15-x64.zip|ImageMagick-7.1.0-18-vc15-x64.zip]]) by executing the following steps: 50 * Extract the ZIP's content to ''C:\Program Files\ImageMagick-7.1.0-18-vc15-x64''. 51 * Add ''C:\Program Files\ImageMagick-7.1.0-18-vc15-x64\bin'' to the System PATH variable manually. 52 * Open ''C:\Program Files\ImageMagick-7.1.0-18-vc15-x64\bin\policy.xml'' and either add the following line within ''<policymap>..</policymap>'': ''<policy domain="coder" rights="read|write" pattern="PDF" />''. If a similar line containing domain ''coder'' and pattern ''PDF'' already exists, change it accordingly. 53 * Install ''ImageMagick PHP extension'' ([[https://windows.php.net/downloads/pecl/releases/imagick/3.7.0/php_imagick-3.7.0-7.4-ts-vc15-x64.zip|php_imagick-3.7.0-7.4-ts-vc15-x64.zip]]) by executing the following steps: 54 * Extract all ''CORE_RL_*'', ''FILTER_*'' and ''IM_MOD_RL_*'' from the ZIP's content to ''C:\Program Files\ImageMagick-7.1.0-18-vc15-x64\bin''. Accept overwriting all files that may already be present there. Yes, that's the binaries folder of the ImageMagick installation. 55 * Extract ''php_imagick.dll'' to ''{PATH_TO}\php\ext''. 56 * Open ''{PATH_TO}\php\php.ini'' and add a line ''extension=imagick''. If using earlier versions of the software involved, you may have to try a combination like ''php_imagick'', ''imagick.dll'', ''php_imagick.dll''. 57 * Don't forget to restart the webserver. 58 * If you want or have to install another version, this might be a useful resource: [[https://mlocati.github.io/articles/php-windows-imagick.html|Install the ImageMagick PHP extension in Windows]] by [[https://github.com/mlocati|Michele Locati]]. It helps you identify the correct version of php_imagick in relation to your PHP installation. Formerly, you also got a download link for the appropriate version of ImageMagick, but the version of this page I visited today appears to not do that anymore. 59 * I also wrote a Dockerfile (for an earlier installation / version constellation) that takes care of the modules to be installed, and makes config adjustments within ImageMagick (only works if the policy domain ''coder'' is predefined in ''policy.xml'' - it's not in the recent versions I came accross). It may help you nevertheless, in case you're using Docker: 60 61<code> 62FROM php:7-fpm 63 64RUN apt-get update && apt-get install -y \ 65 imagemagick libmagickwand-dev \ 66 libzip-dev \ 67 libgs-dev \ 68 ghostscript --no-install-recommends \ 69 && pecl install imagick \ 70 && docker-php-ext-enable imagick \ 71 && pecl install zip \ 72 && docker-php-ext-enable zip 73 74# Adjust ImageMagick security policy to allow PDF conversion 75ARG imagemagic_config=/etc/ImageMagick-*/policy.xml 76 77RUN if [ -f $imagemagic_config ] ; then sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' $imagemagic_config ; else echo did not see file $imagemagic_config ; fi 78</code> 79 80===== Syntax ===== 81 82<code>{{thumbnail>media_path_and_filename}}</code> 83 84or: 85 86<code>{{thumbnail>media_path_and_filename|caption}}</code> 87 88Shows a thumbnail of the media file given via the string `media_path_and_filename` (standard file path for the [[:media_manager|Media Manager]]). In case of an office file (ODT, DOCX, PPTX, etc.), this will only work, if a thumbnail image already has been saved within the file (which nowadays should be very common). 89 90If a caption is provided, this text will be used as 'title' of the resulting <img> element. 91 92In order to be able to show the thumbnail image, the image itself is stored within the media library alongside the media file (see [[#Implementation Details|Implementation Details]]). 93 94The plugin watches file changes at the moment a wiki page is rendered. You might need to watch out for page caching! 95 96In case a media file is replaced by another file (with the same name), this will be noticed by timestamp comparison - the original thumbnail will be overwritten. 97 98**Example:** <code>{{thumbnail>main:media_namespace:presentation.pptx}}</code> 99 100This will show a thumbnail of the Powerpoint presentation in your wiki page. The thumbnail image will be stored within the media library as `main:media_namespace:presentation.pptx.thumb100.jpeg` (with default settings, and because JPEG appears to be the format of thumbnail images within a PPTX file). 101 102===== Implementation Details ===== 103 104In all cases where a file format is supported by the plugin, it will add a thumbnail image into the [[:media_manager|Media Manager]]. In case you decide later on that you don't want these images within your media, your only option is to remove them manually. 105 106The name of the thumbnail will be: <code>{original_filename}.thumb{thumb_max_dimension}.{image_suffix}</code> 107 108The following examples assume the default value of 100 for `thumb_max_dimension`. 109 110**Example 1:** my_dog.jpg => my_dog.jpg.thumb100.jpg 111 112**Example 2:** presentation.pdf => presentation.pdf.thumb100.jpg 113 114The file format for PDF thumbnails will always be JPG. 115 116**Example 3:** presentation.pptx => presentation.pptx.thumb100.png 117 118Note that the file format of the thumbnail in office files might theoretically be any image file format. It depends on the format found within the office file. If you use office files with differing file formats, you might need to adjust the config setting `thumb_paths`. If you have such an office file, I'd like to hear about that so I can add the format to the default value of that config option. 119 120==== Office files ==== 121 122When looking for thumbnails of office files (ODT, DOCX, etc.), the plugin essentially assumes these files to be ZIP files containing a thumbnail image at a specific path (see config setting `thumb_paths`). It will not generate any images for office files, but look for an already embedded thumbnail within the document file, then show the thumbnail on your wiki page. 123 124==== Image files ==== 125 126The plugin will need a properly installed and integrated **ImageMagick** and **Imagick** suite (see [[#Installation and Dependencies]]). Then it will load the image into ImageMagick and transform it into a thumbnail image. 127 128==== PDF files ==== 129 130In order to create thumbnails for PDF files, in addition to a requirement of **ImageMagick** and **Imagick**, you will also need a properly installed and configured **GhostScript** (see [[#Installation and Dependencies]]). The plugin will then transform the first page of the PDF file to a JPG thumbnail. 131 132===== Configuration and Settings ===== 133 134//(compare: [[:devel:configuration#configuration_metadata|Configuration metadata]] for configuration classes)// 135 136^ **thumb_max_dimension** | Default dimension to set for a thumbnail (in pixels, enter without units). The thumbnail will fit into a quadratic box of this size - in case the image is not quadratic, the other dimension will be reduced per aspect ratio. || 137| ::: | numeric, default: | **"100"** | 138^ **thumb_paths** | Paths within media files (format: ZIP) to look at for thumbnail images (comma-separated list, use slashes as directory delimiters). //Is defaulted for paths within ODT files and MS Office files, but can be extended in case of other formats.// || 139| ::: | array, default: | **array("Thumbnails/thumbnail.png", "docProps/thumbnail.jpeg")** | 140^ **link_to_media_file** | Should a click on the thumbnail start the media file download? || 141| ::: | onoff, default: | **true** | 142^ **show_no_thumb_error** | In case no thumbnail was found, do you want an error message be shown? || 143| ::: | onoff, default: | **true** | 144^ **no_thumb_error_message** | Error message to be shown when no thumbnail was found, and 'show_no_thumb_error' is set. Media path will automatically be appended! || 145| ::: | string, default: | **"No thumbnail in "** \\ //note: media path will automatically be appended// | 146 147If your PDF and/or image thumbnails don't show up, consider activating the `allowdebug` option in the DokuWiki base configuratoin. I added some checks that should output information on dependency status. 148 149===== Development ===== 150 151[[https://github.com/ternite/dokuwiki-plugin-mediathumbnails|Sources]] on github. 152 153=== Change Log === 154 155 * **2021-03-29** 156 * v0.81 (Initial release) 157 * **2021-04-02** 158 * v0.91 (added image and PDF support) 159 * config option `thumb_width` was dropped, so you might want to delete that entry from `conf/local.php` if you upgraded from v0.81 and had altered that value 160 * **2021-05-24** 161 * v0.92 (Added checks for ImageMagick security policy issues) 162 * **2025-09-03** 163 * v0.93 (Added compatibility with pipe syntax - so setting a caption will show a popup title for the image) 164 165=== Known Bugs and Issues === 166 167See [[https://github.com/ternite/dokuwiki-plugin-mediathumbnails/issues|issue tracker]] on github. 168 169===== FAQ ===== 170 171None, yet. 172 173===== Discussion ===== 174 175//Thomas Schäfer (2021-03-29):// I wasn't able to locate a proper specification indicating the exact file locations for thumbnails within both OpenOffice/LibreOffice files, or MS Office files. In case you point me to such a specification, I might enhance the config settings for properly identifying thumbnails in more instances of such office documents.