Thumbnail Macro

<llubnek AT gmail DOT com>

Displays a thumbnail of an image. Should work for SVG, EPS, text, HTML, PDF, etc as well. Uses ImageMagick. The version of ImageMagick that comes with Ubuntu is buggy, so it doesn't center properly and you may get an error if you use the Thumbnail action with a height but no width. I'll upload a workaround soon. The latest version of ImageMagick for Windows has none of these problems.

Set convert in data/plugins/action/Thumbnail.py to the actual location of convert or simply "convert = 'convert'" if it's in your path.


0.1: Thumbnail.zip

0.2: Thumbnail_0-2.zip

0.3: Thumbnail_0-3.zip

    MoinMoin - Thumbnail Action
    Version 0.2

    ?action=Thumbnail&w=<width>&h=<height>&target=<attachment>
    ?action=Thumbnail&h=<height>&target=<attachment>
    ?action=Thumbnail&w=<width>&target=<attachment>
    ?action=Thumbnail&target=<attachment>

    Displays a thumbnail of an image attachment.
    If height or width are missing, the missing dimension is calculated using the image's aspect ratio.
    If both height and width are missing, they default to 64x64.

    @copyright: 2007 by Kenneth Bull
    @license: GNU GPL, see COPYING for details.

    MoinMoin - Thumbnail Macro
    Version 0.2

    [[Thumbnail(file)]]
    Displays a thumbnail of an image attachment

    @copyright: 2007 by Kenneth Bull
    @license: GNU GPL, see COPYING for details.


Discussion

Couple of limitations: Always makes png files (no jpg!). width or height cannot be "auto" to keep aspect ratio. Remember to change hardcoded C:/program files/... path to convert before use. (bug: code in 0.3 zip file says it's version 0.2)

MoinMoin 1.7 breaks Thumbnail 0.3. The following is needed to fix it (action/Thumbnail.py):

--- th0.3.py    2008-07-04 12:18:30.000000000 +0300
+++ Thumbnail.py        2008-07-04 12:20:00.000000000 +0300
@@ -60,12 +60,12 @@
         error_msg(pagename, request, _('You are not allowed to view thumbnails 
of attachments from this page.'))
         return
         
-    filename, fpath = _access_file(pagename, request)
+    pagename, filename, fpath = _access_file(pagename, request)
     if not filename: return # error msg already sent in _access_file
 
     timestamp = timefuncs.formathttpdate(int(os.path.getmtime(fpath)))
     if request.if_modified_since == timestamp:
-        request.http_headers(["Status: 304 Not modified"])
+        request.emit_http_headers(["Status: 304 Not modified"])
         request.setResponseCode(304)
 
     else:
@@ -93,7 +93,7 @@
                     return
                 pipe.stderr.close();
             
-            request.http_headers([
+            request.emit_http_headers([
                 'Content-Type: image/jpg',
                 'Last-Modified: %s' % timestamp,
                 'Content-Length: %d' % os.path.getsize(thumbpath),
@@ -115,7 +115,7 @@
                 error_msg(pagename, request, _("Unable to generate thumbnail.")
)
                 return
                 
-            request.http_headers([
+            request.emit_http_headers([
                 'Content-Type: image/jpg',
                 'Last-Modified: %s' % timestamp,
                 'Content-Length: %d' % len(buf),


The above patch works for 1.8 as well, but you also need to remove the following string: request.setResponseCode(304). Not sure about the consequences or possible replacement for that line, but I stopped getting occasional errors on refresh that this method does not exist - I found it in the twisted formatter only. -- AlexanderAgibalov 2010-06-23 13:56:54

MoinMoin: MacroMarket/Thumbnail (last edited 2010-06-23 13:56:55 by AlexanderAgibalov)