Plugin: wvdsimage
Version: 1.1.0
Namespace: lib/plugins/wvdsimage/
Author: Wolfgang van der Stille zeljko.petrusic@outlook.de
License: GPL 2
The wvdsimage plugin enables base64-encoded images as Data-URI directly in the src attribute of <img> tags.
DokuWiki has no built-in mechanism for base64 inline images. By default, images are always embedded as URL references:
<!-- Standard DokuWiki --> <img src="/lib/exe/fetch.php?media=wiki:logo.png" /> <!-- With wvdsimage --> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA..." />
The plugin solves this problem through server-side rendering with intelligent caching.
Core Features:
{{wvds:image>mediaId|parameter1=value1|parameter2=value2}}
{{wvds:image>wiki:logo.png}}
{{wvds:image>wiki:logo.png|width=100%|maxwidth=600|quality=85|format=webp|cache=1w|alt=Company Logo|class=logo-responsive|lazy=1}}
| Parameter | Type | Description |
|---|---|---|
| mediaId | string | DokuWiki media ID of the source image. Format: namespace:filename.ext |
| Parameter | Type | Default | Description |
|---|---|---|---|
width | string | auto | CSS width. Supports px, %, em, vw. Example: width=100% |
height | string | auto | CSS height. Supports px, %, em, vh. Example: height=200px |
maxwidth | integer | 1200 | Maximum pixel width for resizing. Image will never be scaled larger than this value. |
maxheight | integer | null | Maximum pixel height for resizing. Optional, maintains aspect ratio. |
maxwidth × maxheight pixels while maintaining aspect ratio. The width/height parameters are pure CSS values and do not affect actual image dimensions.
| Parameter | Type | Default | Valid Values | Description |
|---|---|---|---|---|
quality | integer | 85 | 10-100 | JPEG/WebP compression quality. Higher = better quality but larger size. |
format | string | auto | jpeg, png, gif, webp | Output format. With auto, source format is preserved. |
| Parameter | Type | Default | Valid Values | Description |
|---|---|---|---|---|
cache | string | 1d | 1h, 6h, 1d, 1w, 1m | Cache duration for processed image. |
| Abbreviation | Meaning |
|---|---|
h | Hours |
d | Days |
w | Weeks |
m | Months (30 days) |
| Parameter | Type | Default | Description |
|---|---|---|---|
alt | string | (empty) | Alternative text for accessibility. Should always be set! |
class | string | wvdsimage | Additional CSS classes. Separate multiple with spaces. |
lazy | boolean | 1 | Enable lazy loading. 1 = enabled, 0 = disabled. |
inline | boolean | 1 | Base64 inline output. 1 = data URI, 0 = external URL (future). |
Requirement: Logo should adapt to container width but never exceed 300px.
{{wvds:image>wiki:logo_hires.png|width=100%|maxwidth=300|alt=WvdS Logo}}
Result:
width: 100% makes it responsivemax-width: 300px prevents enlargement beyond 300pxRequirement: Optimize JPEG photo for faster loading.
{{wvds:image>photos:team.jpg|maxwidth=800|quality=80|format=webp|alt=Our Team}}
Result:
Requirement: Uniform thumbnails for image gallery.
| {{wvds:image>gallery:image1.jpg|maxwidth=150|maxheight=150|alt=Image 1}} | {{wvds:image>gallery:image2.jpg|maxwidth=150|maxheight=150|alt=Image 2}} |
Requirement: Large banner image that rarely changes.
{{wvds:image>design:hero-banner.png|width=100%|maxwidth=1920|quality=90|cache=1m|alt=Welcome}}
1. Syntax Parsing
└── Extracts mediaId and parameters from {{wvds:image>...}}
2. Load Source Image
└── Reads file from data/media/{namespace}/{file}
└── Validates image format (PNG, JPEG, GIF, WebP)
3. Cache Check
└── Generates hash: MD5(path + mtime + width + height + quality + format)
└── Checks data/cache/wvdsimage/{hash}.{format}
└── On cache hit: Loads cached image
4. Image Processing (on cache miss)
└── imagecreatefrom{format}() - Loads source image
└── imagecreatetruecolor() - Creates target image
└── imagecopyresampled() - High-quality scaling
└── image{format}() - Saves in target format
5. Cache Storage
└── Writes processed image to data/cache/wvdsimage/
6. HTML Output
└── Generates <img src="data:image/{mime};base64,{data}" .../>
Cached images are stored in:
data/cache/wvdsimage/
Filename format: {MD5-hash}.{format}
Via Admin → Configuration → wvdsimage:
| Setting | Type | Default | Description |
|---|---|---|---|
defaultQuality | Number | 85 | Default quality when not specified |
defaultCache | Text | 1d | Default cache duration |
defaultMaxWidth | Number | 1200 | Default maximum width |
enableWebp | On/Off | On | Enable WebP support |
lazyLoad | On/Off | On | Enable lazy loading by default |
| Error | Cause | Solution |
|---|---|---|
Image not found: {mediaId} | Media file does not exist | Check path, upload file |
Invalid image: {mediaId} | File is not a valid image | Check image format, re-upload |
Image processing failed | GD library error | Check PHP GD extension, increase memory |
format=webp (PHP 7.1+ with libwebp)data/cache/wvdsimage/| Scenario | Recommended Settings |
| Logos, Icons | maxwidth=300, format=png, cache=1w |
| Photos | maxwidth=800, quality=80, format=webp, cache=1d |
| Hero Banners | maxwidth=1920, quality=85, cache=1m |
| Thumbnails | maxwidth=150, quality=75, cache=1w |
For memory issues, increase memory_limit in php.ini.
The plugin is thread-safe. Parallel requests for the same image may temporarily trigger duplicate processing, but the cache is written atomically.
| Version | Date | Changes |
|---|---|---|
| 1.1.0 | 2026-01-08 | Helper API for programmatic access from templates and plugins |
| 1.0.0 | 2026-01-06 | Initial release |
File: lib/plugins/wvdsimage/syntax.php
| Method | Description |
|---|---|
getType() | Returns substition |
getSort() | Returns 319 (priority) |
connectTo($mode) | Registers pattern \{\{wvds:image>[^}]+\}\} |
handle($match, …) | Parses syntax, extracts parameters |
render($mode, …) | Generates HTML output |
| Method | Parameters | Return | Description |
|---|---|---|---|
calculateDimensions() | $origW, $origH, $opts | array | Calculates target size |
processImage() | $file, $mime, $w, $h, $q, $fmt | string | Processes image |
getCacheKey() | $file, $w, $h, $q, $fmt | string | Generates cache hash |
buildHtml() | $data, $fmt, $opts, $w, $h | string | Creates HTML output |
File: lib/plugins/wvdsimage/helper.php
The helper provides programmatic access to image processing for templates and plugins.
// Load helper $wvdsimage = plugin_load('helper', 'wvdsimage'); // Render image from wiki media $html = $wvdsimage->renderImage('wiki', 'wiki:logo.png', array( 'maxwidth' => 300, 'quality' => 90, 'alt' => 'Logo', 'class' => 'my-logo', )); // Render image from template directory $html = $wvdsimage->renderImage('template', 'logo.png', array( 'maxwidth' => 300, )); // Render image from absolute file path $html = $wvdsimage->renderImage('file', '/path/to/image.jpg', array( 'maxwidth' => 800, 'format' => 'webp', ));
| Parameter | Type | Description |
|---|---|---|
$source | string | Source: wiki, template, file |
$path | string | Path depending on source |
$options | array | Optional rendering parameters |
| Option | Type | Default | Description |
|---|---|---|---|
maxwidth | int | 300 | Maximum width in pixels |
maxheight | int | null | Maximum height in pixels |
quality | int | 85 | Image quality (10-100) |
format | string | auto | Output format (jpeg, png, webp) |
class | string | | CSS classes |
| alt | string | | Alt text |
style | string |
<img src="data:image/png;base64,iVBORw0KGgoAAAA..." width="300" height="120" alt="Logo" class="my-logo"/>
On errors, an HTML comment is returned:
<!-- wvdsimage: file not found: wiki:missing.png -->
The Flat Template uses the helper for logo rendering:
// In lib/tpl/flat/lang_helper.php function tpl_renderLogo() { $wvdsimage = plugin_load('helper', 'wvdsimage'); if ($wvdsimage) { return $wvdsimage->renderImage('wiki', $logoPath, array( 'maxwidth' => $maxWidth, 'quality' => $quality, 'alt' => $siteTitle, 'class' => 'logo-img', )); } // Fallback without wvdsimage return '<img src="..." />'; }