Thorsten Staerk
Thorsten Staerk

Reputation: 1156

How do I scale an image's width to a percentage of the window with MediaWiki?

With html I can scale an image's width to a percentage of the available window like this:

<img src=whatever.png width=50% />

With mediawiki this seems to be impossible (if you do not allow html injections). Is it really? Don't tell me I have to write a mediawiki extension ;)

Note the CSS answer from Is there a way automatically to resize MediaWiki images depending on screen size? is not a solution. I want to have different images in one page with different percentages.

Upvotes: 6

Views: 3638

Answers (2)

Thorsten Staerk
Thorsten Staerk

Reputation: 1156

To make it easier for myself I wrote a mediawiki extension that allows

  • alignment
  • relative size
  • links under images
  • captions like for thumbnails

It's here: https://github.com/tstaerk/adaptivethumb

Upvotes: 1

Ilmari Karonen
Ilmari Karonen

Reputation: 50368

It should be possible to apply the CSS solution to specific images by tagging them with a custom class name. That is, you'd add something like the following to your MediaWiki:Common.css page:

img.halfwidth {
    width: 50%;
    height: auto;
}

and then use wiki markup like this:

[[File:Myimage.jpg|class=halfwidth]]

(Note that specifying a class name on an image like this requires MediaWiki 1.20+. If, for some reason, you need to do this on an older MediaWiki version, you can instead change the CSS selector to e.g. .halfwidth img, and the wiki syntax to <div class="halfwidth">[[File:Myimage.png]]</div>.)

Upvotes: 4

Related Questions