Template:Clean image/doc: Difference between revisions

(Created page with "{{Documentation}} Cleans and formats an input image. This removes the following things if present: * <code><nowiki>[[File:</nowiki></code> * <code><nowiki>]]</nowiki></code> * <code><nowiki>|</nowiki></code> and <code><nowiki>{{!}}</nowiki></code>, and everything following the first of these until the end Then it re-packages the image into a new file container, with specified height, width, and link. The <code>frameless</code> modifier is used, which prevents the image...")
 
No edit summary
 
(One intermediate revision by one other user not shown)
Line 17: Line 17:


===Examples===
===Examples===
To be practical the results will be as if <code><nowiki>|image=[[File:Basic bacon.png|100px|link=abyssal whip]]</nowiki></code> as the input.
To be practical the results will be as if <code><nowiki>|image=[[File:Bucket.png|100px|link=abyssal whip]]</nowiki></code> as the input.


{| class="wikitable"
{| class="wikitable"
Line 28: Line 28:
| Just clean
| Just clean
| <pre>{{clean image|file={{{image}}}}}</pre>
| <pre>{{clean image|file={{{image}}}}}</pre>
| {{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]}}
| {{clean image|file=[[File:Bucket.png|100px|link=pirate]]}}
| Should result in
| Should result in
<pre>[[File:{FILENAME}]]</pre>
<pre>[[File:{FILENAME}]]</pre>
Line 35: Line 35:
| Clean + width
| Clean + width
| <pre>{{clean image|file={{{image}}}|width=50}}</pre>
| <pre>{{clean image|file={{{image}}}|width=50}}</pre>
| {{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|width=50}}
| {{clean image|file=[[File:Bucket.png|100px|link=pirate]]|width=50}}
| Should result in
| Should result in
<pre>[[File:{FILENAME}|{WIDTH}px]]</pre>
<pre>[[File:{FILENAME}|{WIDTH}px]]</pre>
Line 41: Line 41:
| Clean + height
| Clean + height
| <pre>{{clean image|file={{{image}}}|height=20}}</pre>
| <pre>{{clean image|file={{{image}}}|height=20}}</pre>
| {{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|height=20}}
| {{clean image|file=[[File:Bucket.png|100px|link=pirate]]|height=20}}
| Should result in
| Should result in
<pre>[[File:{FILENAME}|x{HEIGHT}px]]</pre>
<pre>[[File:{FILENAME}|x{HEIGHT}px]]</pre>
Line 50: Line 50:
{{clean image|file={{{image}}}|width=11|height=50}}
{{clean image|file={{{image}}}|width=11|height=50}}
{{clean image|file={{{image}}}|width=66|height=66}}</pre>
{{clean image|file={{{image}}}|width=66|height=66}}</pre>
|<poem>{{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|width=44|height=20}}
|<poem>{{clean image|file=[[File:Bucket.png|100px|link=pirate]]|width=44|height=20}}
{{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|width=11|height=50}}
{{clean image|file=[[File:Bucket.png|100px|link=pirate]]|width=11|height=50}}
{{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|width=66|height=60}}</poem>
{{clean image|file=[[File:Bucket.png|100px|link=pirate]]|width=66|height=60}}</poem>
| Should result in
| Should result in
<pre>[[File:{FILENAME}|{WIDTH}x{HEIGHT}px]]</pre>
<pre>[[File:{FILENAME}|{WIDTH}x{HEIGHT}px]]</pre>
Remember that height is still a maximum limit here. The size will be {WIDTH}px wide unless this makes the height more than {HEIGHT}px, in which case it is sized down to {HEIGHT}px tall. Aspect ratio is always kept.
Remember that height is still a maximum limit here. The size will be {WIDTH}px wide unless this makes the height more than {HEIGHT}px, in which case it is sized down to {HEIGHT}px tall. Aspect ratio is always kept.


Basic bacon.png is 22px wide and 30px tall. In the first use it is trying to resize to twice as wide but the maximum height of 20px forces it to resize down to 15x20px. The second use it successfully resizes down to half as wide, 11x15px. The third use is trying to go thrice as wide but the height limit only allows it to go twice as tall, so is 44x60px.
Bucket.png is 22px wide and 30px tall. In the first use it is trying to resize to twice as wide but the maximum height of 20px forces it to resize down to 15x20px. The second use it successfully resizes down to half as wide, 11x15px. The third use is trying to go thrice as wide but the height limit only allows it to go twice as tall, so is 44x60px.
|-
|-
| Clean + link
| Clean + link
| <pre>{{clean image|file={{{image}}}|link=Weird gloop}}</pre>
| <pre>{{clean image|file={{{image}}}|link=Sturlet}}</pre>
| {{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|link=Weird gloop}}
| {{clean image|file=[[File:Bucket.png|100px|link=pirate]]|link=Sturlet}}
| Should result in
| Should result in
<pre>[[File:{FILENAME}|link={LINK}]]</pre>
<pre>[[File:{FILENAME}|link={LINK}]]</pre>
Line 67: Line 67:
| Clean + link suppress
| Clean + link suppress
| <pre>{{clean image|file={{{image}}}|link=no}}</pre>
| <pre>{{clean image|file={{{image}}}|link=no}}</pre>
| {{clean image|file=[[File:Basic bacon.png|100px|link=abyssal whip]]|link=no}}
| {{clean image|file=[[File:Bucket.png|100px|link=pirate]]|link=no}}
| Should result in
| Should result in
<pre>[[File:{FILENAME}|link=]]</pre>
<pre>[[File:{FILENAME}|link=]]</pre>
Line 73: Line 73:
| Clean + alignment
| Clean + alignment
| <pre>{{clean image|file={{{image}}}|align=right}}</pre>
| <pre>{{clean image|file={{{image}}}|align=right}}</pre>
| {{clean image|file=[[File:Basic bacon.png]]|align=right}}
| {{clean image|file=[[File:Bucket.png]]|align=right}}
| Should result in
| Should result in
<pre>[[File:{FILENAME}|align=right]]</pre>
<pre>[[File:{FILENAME}|align=right]]</pre>

Latest revision as of 17:39, 18 November 2024

This is a documentation subpage for Template:Clean image.
It contains usage information, categories, and other content that is not part of the original template page.
Template:Clean image invokes function main in Module:Clean image using Lua.

Cleans and formats an input image. This removes the following things if present:

  • [[File:
  • ]]
  • | and {{!}}, and everything following the first of these until the end

Then it re-packages the image into a new file container, with specified height, width, and link. The frameless modifier is used, which prevents the image being resized larger than its actual dimensions.

Usage

{{clean image
|file = wikitext to be cleaned; this should usually be a template parameter (e.g. |file={{{image}}}); required
|width = width of image; no default; exclude 'px'
|height = height of image; no default; exclude 'px'; can be combined with width
|link = link to apply to image; no default (will link to file page); setting to no will suppress normal link
|align = alignment of image; left, center, right; no default
}}

Examples

To be practical the results will be as if |image=[[File:Bucket.png|100px|link=abyssal whip]] as the input.

Example Code Result Notes
Just clean
{{clean image|file={{{image}}}}}
Should result in
[[File:{FILENAME}]]

Note that it links to the file page as a normal image does.

Clean + width
{{clean image|file={{{image}}}|width=50}}
Should result in
[[File:{FILENAME}|{WIDTH}px]]
Clean + height
{{clean image|file={{{image}}}|height=20}}
Should result in
[[File:{FILENAME}|x{HEIGHT}px]]

Remember that height parameters on images are maximum height limits and won't make an image bigger (without a width set).

Clean + width + height
{{clean image|file={{{image}}}|width=44|height=20}}
{{clean image|file={{{image}}}|width=11|height=50}}
{{clean image|file={{{image}}}|width=66|height=66}}



Should result in
[[File:{FILENAME}|{WIDTH}x{HEIGHT}px]]

Remember that height is still a maximum limit here. The size will be {WIDTH}px wide unless this makes the height more than {HEIGHT}px, in which case it is sized down to {HEIGHT}px tall. Aspect ratio is always kept.

Bucket.png is 22px wide and 30px tall. In the first use it is trying to resize to twice as wide but the maximum height of 20px forces it to resize down to 15x20px. The second use it successfully resizes down to half as wide, 11x15px. The third use is trying to go thrice as wide but the height limit only allows it to go twice as tall, so is 44x60px.

Clean + link
{{clean image|file={{{image}}}|link=Sturlet}}
Should result in
[[File:{FILENAME}|link={LINK}]]
Clean + link suppress
{{clean image|file={{{image}}}|link=no}}
Should result in
[[File:{FILENAME}|link=]]
Clean + alignment
{{clean image|file={{{image}}}|align=right}}
Should result in
[[File:{FILENAME}|align=right]]