[dokuwiki] Re: Request for an improvement - allow % sizes for images - please!

  • From: "Mike \"Pomax\" Kamermans" <pomax@xxxxxxxxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Thu, 17 Feb 2011 10:14:48 -0800

Looks like this thread is veering way off track..

Chris, if I understand things correctly you want to be able to be able to use a syntax that lets you specify image dimensions in terms of page width. Using plain HTML and CSS, this cannot be done. It's that simple. The reason for this is that something like "<image src="..." style="width: 50%"/>" does NOT make the image as wide as 50% of the page.

Instead, the browser will load the image, sees that it's, say, 25000 pixels by 10000 pixels, sees the CSS "width: 50%" rule, and proceeds to resize the image as you instruct, downsizing it to 12500 x 5000 pixels. This is not what you want, from what I can tell.

What you want is for images to be resized to a certain percentage of the page the image is on. This requires a LOT more work. In order to resize an image element to fit a certain percentage of the page, you will need to know the following things:

- how wide is the current browser window, in pixels. treat this as 100%
- how many pixels is ...% of that?
- how many pixels wide is element X?
- given that element X currently "A"px wide, and needs to become "B"px wide, it must be scaled by B/A% - set the CSS "style.width" and "style.height" for element X so that width and height are that percentage

(and of course note that the percentage value is potentially different for every image)

This is perfectly doable; you'll just need to write an action plugin for it yourself, with a script.js that performs the just-described steps, and a content replacement that ensures your script gets called either during page load whenever an img DOM element is done, or when the entire DOM has been created.

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

Other related posts: