Template:Image frame: Difference between revisions
(Created page with "<includeonly>{{#lvardef: clip-path|{{#switch:{{{border-shape|diamond}}} | diamond = polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%) | rounded = xywh(0 0 100% 100% round 15%); | #default = {{{border-shape}}} }}}}<div style=" display: inline-block; height: calc({{{height|100px}}} + 2*{{{border-width|4px}}}); width: calc({{{height|100px}}} + 2*{{{border-width|4px}}}); clip-path: {{#lvar:clip-path}}; background: {{{border-color|black}}}; "> <div style=" position: a...") |
(Fixed incorrectly setting margin when border-width = 0) |
||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly>{{#lvardef: clip-path|{{#switch:{{{border-shape| | <includeonly><!-- | ||
Image width. Defaults to a square aspect ratio if only height is provided. | |||
-->{{#lvardef: width | {{#replace:{{{width|{{{w|{{{height|{{{h|100}}}}}}}}}}}}|px|}}}}<!-- | |||
Image height. Defaults to a square aspect ratio if only width is provided. | |||
-->{{#lvardef: height | {{#replace:{{{height|{{{h|{{{width|{{{w|100}}}}}}}}}}}}|px|}}}}<!-- | |||
Border width. If this is 0, the outer div used for the border will not be created. | |||
-->{{#lvardef: border-width | {{#replace:{{{border-width|{{{bw|4}}}}}}|px|}}}}<!-- | |||
Border frame shape. This can be either an arbitrary clip-path or one of the predefined values. | |||
-->{{#lvardef: clip-path|{{#switch:{{{border-shape|{{{bs|rounded}}}}}} | |||
| rounded = xywh(0 0 100% 100% round 15%) | |||
| diamond = polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%) | | diamond = polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%) | ||
| | | basic = none | ||
| #default = {{{border-shape}}} | | #default = {{{border-shape|{{{bs|}}}}}} | ||
}}}}<div style=" | }}}}{{#ifexpr: {{#lvar:border-width}} > 0 | ||
display: inline-block; | | <!--Case when the border width is > 0 which requires an outer div --> | ||
height: calc({{ | <div {{#if:{{{class|}}}|class="{{{class|}}}"}} style=" | ||
width: | display: inline-block; | ||
clip-path: {{#lvar:clip-path}}; | height: calc({{#lvar:height}}px + 2*{{#lvar:border-width}}px); | ||
background: {{{border-color|black}}}; | width: calc({{#lvar:width}}px + 2*{{#lvar:border-width}}px); | ||
"> | clip-path: {{#lvar:clip-path}}; | ||
background: {{{border-color|{{{bc|black}}}}}}; | |||
{{{style|}}}"> | |||
<div style=" | <div style=" | ||
margin: {{#lvar:border-width}}px; | |||
width: {{#lvar:width}}px; | |||
height: {{#lvar:height}}px; | |||
clip-path: {{#lvar:clip-path}}; | |||
height: {{ | ">[[File:{{{image|{{{1|}}}}}}|{{#lvar:width}}x{{#lvar:height}}px|link={{{link|{{{2|}}}}}}]]</div> | ||
clip-path: {{#lvar:clip-path}}; | </div> | ||
">[[File: | | <!--Case when the border width is 0 so omit the outer div --> | ||
<div {{#if:{{{class|}}}|class="{{{class|}}}"}} style=" | |||
width: {{#lvar:width}}px; | |||
height: {{#lvar:height}}px; | |||
clip-path: {{#lvar:clip-path}}; | |||
{{{style|}}}">[[File:{{{image|{{{1|}}}}}}|{{#lvar:width}}x{{#lvar:height}}px|link={{{link|{{{2|}}}}}}]]</div> | |||
}}</includeonly><noinclude>{{documentation|content= | |||
Render an image cropped into a frame of arbitrary shape. The shape of the border or frame is defined by a [https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path CSS clip-path] or can use one of the predefined shapes (rounded, diamond, basic). | |||
== Examples == | == Examples == | ||
{{Template demo | {{Template demo | ||
| <nowiki> | | <nowiki> | ||
{{ | {{Image frame | ||
| | | image = Portrait Lae'zel.png | ||
| link = Lae'zel | |||
| width = 120 | |||
| border-shape = diamond | | border-shape = diamond | ||
| border-width = | | border-width = 4 | ||
}} | }} | ||
</nowiki> | </nowiki> | ||
| <nowiki> | | <nowiki> | ||
{{ | {{Image frame | ||
| | | image = Portrait Lae'zel.png | ||
| | | link = Lae'zel | ||
| | | h = 120px | ||
| | | bs = rounded | ||
| bw = 2px | |||
| bc = red | |||
| class = bg3wiki-image-quote-image | |||
| style = margin:20px; | |||
}} | }} | ||
</nowiki> | </nowiki> | ||
| <nowiki> | | <nowiki> | ||
{{ | {{Image frame | ||
| height = | | image = Portrait Lae'zel.png | ||
| link = Lae'zel | |||
| height = 120 | |||
| border-shape = polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%); | | border-shape = polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%); | ||
| border-width = | | border-width = 2 | ||
| border-color = #3d3d3d | | border-color = #3d3d3d | ||
}} | |||
</nowiki> | |||
| <nowiki> | |||
{{Image frame|Portrait Lae'zel.png|Lae'zel|h=120|bw=0}} | |||
</nowiki> | |||
| <nowiki> | |||
{{Image frame | |||
| image = Portrait Lae'zel.png | |||
| link = Lae'zel | |||
| h = 120px | |||
| bs = rounded | |||
| bw = 0 | |||
| class = bg3wiki-image-quote-image | |||
| style = transform: rotate(180deg); | |||
}} | }} | ||
</nowiki> | </nowiki> | ||
}} | }} | ||
== Template data == | |||
<templatedata> | |||
{ | |||
"description": "Render an image cropped into a frame of arbitrary shape.", | |||
"params": { | |||
"1": { | |||
"label": "Image", | |||
"description": "The image file to display.", | |||
"aliases": ["image"], | |||
"type": "wiki-file-name", | |||
"required": true | |||
}, | |||
"2": { | |||
"label": "Link", | |||
"description": "Clicking the image redirects to this link instead of the image file.", | |||
"aliases": ["link"], | |||
"type": "wiki-page-name", | |||
"suggested": true, | |||
"required": false | |||
}, | |||
"height": { | |||
"label": "Height", | |||
"aliases": ["h"], | |||
"description": "The height of the image in pixels (does not include any additional height from the border size).", | |||
"type": "number", | |||
"default": "Same value as width, if defined. 100 otherwise.", | |||
"suggested": true, | |||
"required": false | |||
}, | |||
"width": { | |||
"label": "Width", | |||
"aliases": ["w"], | |||
"description": "The width of the image in pixels (does not include any additional width from the border size).", | |||
"type": "number", | |||
"default": "Same value as height, if defined. 100 otherwise.", | |||
"required": false | |||
}, | |||
"border-shape": { | |||
"label": "Border shape", | |||
"aliases": ["bs"], | |||
"description": "The shape of the border frame. It can be an arbitrary CSS clip path or use one of the predefined values.", | |||
"type": "string", | |||
"default": "rounded", | |||
"suggestedvalues": ["rounded", "diamond", "basic"], | |||
"example": "polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)", | |||
"suggested": true, | |||
"required": false | |||
}, | |||
"border-color": { | |||
"label": "Border color", | |||
"aliases": ["bc"], | |||
"description": "The color of the border frame. This can be any CSS color descriptor.", | |||
"type": "string", | |||
"default": "black", | |||
"required": false | |||
}, | |||
"border-width": { | |||
"label": "Border width", | |||
"aliases": ["bw"], | |||
"description": "The thickness of the border frame in pixels. Set this to 0 to disable the border entirely.", | |||
"type": "number", | |||
"default": "4", | |||
"required": false | |||
}, | |||
"class": { | |||
"label": "Class", | |||
"description": "A CSS class to apply to the image div.", | |||
"type": "string", | |||
"required": false | |||
}, | |||
"style": { | |||
"label": "Style", | |||
"description": "Any additional CSS style properties to apply to the image div.", | |||
"type": "string", | |||
"required": false | |||
} | |||
} | |||
} | |||
</templatedata>}} | |||
[[Category:Templates]] | |||
</noinclude> | </noinclude> |
Revision as of 22:44, 20 July 2024
Render an image cropped into a frame of arbitrary shape. The shape of the border or frame is defined by a CSS clip-path or can use one of the predefined shapes (rounded, diamond, basic).
Examples
Markup | Renders as |
---|---|
{{Image frame | image = Portrait Lae'zel.png | link = Lae'zel | width = 120 | border-shape = diamond | border-width = 4 }} | |
{{Image frame | image = Portrait Lae'zel.png | link = Lae'zel | h = 120px | bs = rounded | bw = 2px | bc = red | class = bg3wiki-image-quote-image | style = margin:20px; }} | |
{{Image frame | image = Portrait Lae'zel.png | link = Lae'zel | height = 120 | border-shape = polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%); | border-width = 2 | border-color = #3d3d3d }} | |
{{Image frame|Portrait Lae'zel.png|Lae'zel|h=120|bw=0}} | |
{{Image frame | image = Portrait Lae'zel.png | link = Lae'zel | h = 120px | bs = rounded | bw = 0 | class = bg3wiki-image-quote-image | style = transform: rotate(180deg); }} |
Template data
Render an image cropped into a frame of arbitrary shape.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Image | 1 image | The image file to display. | File | required |
Link | 2 link | Clicking the image redirects to this link instead of the image file. | Page name | suggested |
Height | height h | The height of the image in pixels (does not include any additional height from the border size).
| Number | suggested |
Width | width w | The width of the image in pixels (does not include any additional width from the border size).
| Number | optional |
Border shape | border-shape bs | The shape of the border frame. It can be an arbitrary CSS clip path or use one of the predefined values.
| String | suggested |
Border color | border-color bc | The color of the border frame. This can be any CSS color descriptor.
| String | optional |
Border width | border-width bw | The thickness of the border frame in pixels. Set this to 0 to disable the border entirely.
| Number | optional |
Class | class | A CSS class to apply to the image div. | String | optional |
Style | style | Any additional CSS style properties to apply to the image div. | String | optional |