in Blog

The dw2pdf DokuWiki plug-in cannot handle RGBA

I was happily using the dw2pdf plug-in for the DokuWiki installation at work when users began reporting broken images in the exported PDFs. One page in particular featured two images – one worked, the other did not. The only difference I found was in the palette used:

$ file deps.png 
deps.png: PNG image data, 361 x 256, 8-bit/color RGBA, non-interlaced
$ file deps-legend.png 
deps-legend.png: PNG image data, 3476 x 800, 8-bit/color RGB, non-interlaced

The first one was missing in the exported PDF. Apparently dw2pdf cannot handle an alpha channel. Since my theme has a white background, I simply replaced it with white:

$ convert deps.png -background white -alpha remove deps.png && convert deps.png -alpha off deps.png

Be careful, like written here the command replaces the original file. The last file is now in RGB with a white background:

$ file deps.png
deps.png: PNG image data, 361 x 256, 8-bit/color RGB, non-interlaced

Note: convert is a tool of the ImageMagick suite (sudo apt-get install imagemagick).

For files that are 8-bit gray+alpha, the following command does the trick:

$ convert file.png -background white -type Palette file.png

These tricks are mere workarounds, but time restraints did not permit further investigation into the inner workings of the plug-in.