[dokuwiki] image resizing based on DPI

  • From: Michiel Kamermans <pomax@xxxxxxxxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Fri, 10 Sep 2010 14:12:09 -0700

Hi,

I'm currently using a custom plugin to resize on-page images so that their screen dimensions match their print dimensions, by checking the image files for their dpi value and determining what the pixel size should be for a 72dpi device (which is 99% of all monitors). For instance, I use almost exclusively 300dpi images because my dokuwiki gets compiled to pdf form, but a 4"x2" image at 300 dpi is 1200x600 pixels, which is immense on a webpage. Instead, my plugin simply sticks width="..." and height="..." attributes in the img tag, with corrected value. A 1200x600px image at 300dpi should be on-screen resized to 288x144px, so while the image itself is left untouched, it'll get a tag that looks like <img src="..." width="288" height="244" alt="some alt text">.

However, I do this by parsing the actual files, and assuming they're JPG: the file is loaded using ImageCreateFromJpeg() to find out the physical dimensions, and the dpi value for jpg images is always located on bytes 14~17 (two bytes for horizontal dpi, two bytes for vertical dpi) so I read in the first 20 bytes and then just look at the values of bytes 14-17 in the resulting byte array.

Long story short: should this be something that dokuwiki does natively, so that images aren't shown on-page based on their pixel size, but on their "how big they should look" size?

For PNG the trick is similar to JPG, but is a bit more work because the dpi value is actually a 'pixels per unit' value, with an additional 'which unit is being used' byte that needs to be read before sensible computation can be done (it's either '1' for meters, or '0' for unspecified). For GIF things are simple: there is no "dpi" setting, all GIF images are 72 dpi. Other image formats aren't particularly common or even supported across all browsers, so that should cover the majority of image files used...

Keep as plugin, or recommend as dokuwiki built-in functionality?

- Mike "Pomax" Kamermans
nihongoresources.com
--
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: