Re: Image with link to attached file

Petko Yotov <[email protected]> Mon, 09 Sep 2024 06:07:19 +0200
Newsgroups gmane.comp.web.wiki.pmwiki.user
Message-ID <[email protected]>
On 08/09/2024 23:24, Michael Eager wrote:
> On 9/8/24 12:36 AM, Petko Yotov wrote;
>> It may be possible to write a PmWiki recipe/extension to extract an 
>> existing thumbnail from a PPTX file, and display it. It is not yet 
>> written, but would require the PPTX file to be saved with a thumbnail 
>> from the menus or the ribbon "File" -> "Info" or "Properties/Summary" 
>> -> "Save preview picture".
> 
> I created the PDFThumb extension a few years ago to do this for PDFs.
> Maybe I can adapt it to work with PPTX, if they have thumbnails.

PPTX files are fact zip files, and recent PHP versions can easily read 
from zip files.

Here is one way to extract the preview thumbnail of the first slide from 
such a file:

   $fname = "uploads/MyGroup/myfile.pptx";
   $tname = "$fname.jpg";
   # for files without embedded thumbnail, use an existing icon
   $nothumbpic = "/path/to/icon-pptx.jpg";

   if (!file_exists($tname) || filemtime($tname)<filemtime($fname)) {
     $storedthumb = "phar://$fname/docProps/thumbnail.jpeg";

     if (file_exists($thumb)) {
       copy($storedthumb,$tname);
       touch($tname);
     }
     else {
       # to not check again for the same file, add a default thumbnail
       copy($nothumbpic,$tname);
       touch($tname);
     }
   }

To simplify your in-page markup with the link and picture, you can add a 
markup rule.

Petko