MediaWiki: Improving thumbnail quality

Anybody who's using MediaWiki might discover that the automatically created thumbnails are of low (if not really bad) quality. This might be a less pressing problem when using SVGs, but many of my JPEGs looked really really bad. The MediaWiki documentation suggest using ImageMagick instead of of GD (see http://www.mediawiki.org/wiki/Manual:Image_Administration#Image_thumbnailing). However, that's what I'm using.

Improving Quality

I've done two steps to improve the quality of the thumbnails. Both might or might not be applicable to your images - it often depends on the type of content you present, the quality and size of the images you upload and their content (images of nature, computer-generated graphs, etc.).

JPEG quality

MediaWiki uses an JPEG quality of "80%". This compresses the thumbnails (they are smaller and can be downloaded faster by the users). However, the quality suffers with that lower number, as more artifacts can be seen. I tried setting the quality to 95 %, resulting in significantly better images. Again, note that this results in larger image files and might not be applicable to your kind of images.

There doesn't seem to be any configuration setting in MediaWiki to set this compression quality in a nice way (like in LocalSettings.php). The value of 80% for JPGs seems to be hardcoded in ./includes/media/Bitmap.php. In Version 1.15, the value is set in line 109 of the file, in the more recent version 1.18, the code is in line 272. I just changed the value of  80 to 95, and newly uploaded images got better thumbnails. Note that changing the sourcecode of MediaWiki like this might be a bad idea if you don't know exactly what you are doing. For instance, after an update, you are likely to lose this change, or you might even corrupt your MediaWiki installation.

Older thumbnails are not automatically recreated (see below for a solution to that).

Sharpening

Sharpening the image can improve the quality; however, when applied with wrong parameters or applied on certain images, it can decrease the images quality as well. For my images, if found less sharpening then the standard value of "0x0.4" better; I'm currently using a value of "0x0.4". This value can be set in LocalSettings.php by setting the variable $wgSharpenParameter (e.g. $wgSharpenParameter = "0x0.2"; ). Again, note that different values might be better for different applications.

Recreating the older thumbnails

Changing the values as suggested above only influences newly created thumbnails. Thumbnails already created are not automatically rerendered just by changing those parameters. The official way to recreate older thumbnails is to set the variable $wgThumbnailEpoch to the current date; any older Thumbnails are recreated when they are read the next time. See http://www.mediawiki.org/wiki/Manual:$wgThumbnailEpoch

In my current installation, there seems to be a bug that causes the wgThumbnailEpoch to be ignored (I guess it is https://bugzilla.wikimedia.org/show_bug.cgi?id=20159). The bug should already be resolved in the current release of MediaWiki. The workaround I used was to delete the thumbnail directory at ./images/thumbs/ - this results in all  thumbnails accessed to be recreated automatically. Be sure to backup the thumbs directory before deleting it; certain configuration settings of your MediaWiki might prevent an automatic recreation of the thumbnails. In that case, you might still favor the low-quality thumbs over non at all.

Kommentare

Beliebte Posts aus diesem Blog

Microsoft Word: Neuen Querverweis-Typ anlegen

Klassentreffen Volksschule Doppl

Burschenschafterturm in Linz