Template:Image frame: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(Added link param)
(Fixed incorrectly setting margin when border-width = 0)
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly><!--
<includeonly><!--
Image width. Defaults to a square aspect ratio if only height is provided.
Image width. Defaults to a square aspect ratio if only height is provided.
-->{{#lvardef: width | {{{width|{{{w|{{{height|{{{h|100}}}}}}}}}}}}}}<!--
-->{{#lvardef: width | {{#replace:{{{width|{{{w|{{{height|{{{h|100}}}}}}}}}}}}|px|}}}}<!--
Image height. Defaults to a square aspect ratio if only width is provided.
Image height. Defaults to a square aspect ratio if only width is provided.
-->{{#lvardef: height | {{{height|{{{h|{{{width|{{{w|100}}}}}}}}}}}}}}<!--
-->{{#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.
Border width. If this is 0, the outer div used for the border will not be created.
-->{{#lvardef: border-width | {{{border-width|{{{bw|4}}}}}}}}<!--
-->{{#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.
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}}}}}}
-->{{#lvardef: clip-path|{{#switch:{{{border-shape|{{{bs|rounded}}}}}}
Line 12: Line 12:
| basic  = none
| basic  = none
| #default = {{{border-shape|{{{bs|}}}}}}
| #default = {{{border-shape|{{{bs|}}}}}}
}}}}{{#ifexpr: {{#lvar:border-width}} > 0|<div style="
}}}}{{#ifexpr: {{#lvar:border-width}} > 0
| <!--Case when the border width is > 0 which requires an outer div -->
<div {{#if:{{{class|}}}|class="{{{class|}}}"}} style="
   display:    inline-block;  
   display:    inline-block;  
   height:    calc({{#lvar:height}}px + 2*{{#lvar:border-width}}px);
   height:    calc({{#lvar:height}}px + 2*{{#lvar:border-width}}px);
Line 18: Line 20:
   clip-path:  {{#lvar:clip-path}};
   clip-path:  {{#lvar:clip-path}};
   background: {{{border-color|{{{bc|black}}}}}};
   background: {{{border-color|{{{bc|black}}}}}};
">|}}<div style="
{{{style|}}}">
   margin-top:  {{#lvar:border-width}}px;
<div style="
  margin-left: {{#lvar:border-width}}px;
   margin:     {{#lvar:border-width}}px;
   width:      {{#lvar:width}}px;
   width:      {{#lvar:width}}px;
   height:      {{#lvar:height}}px;
   height:      {{#lvar:height}}px;
   clip-path:  {{#lvar:clip-path}};
   clip-path:  {{#lvar:clip-path}};
">[[File:{{{image|{{{1|}}}}}}|{{#lvar:width}}x{{#lvar:height}}px|link={{{link|{{{2|}}}}}}]]</div>
">[[File:{{{image|{{{1|}}}}}}|{{#lvar:width}}x{{#lvar:height}}px|link={{{link|{{{2|}}}}}}]]</div>
{{#ifexpr: {{#lvar:border-width}} > 0|</div>|}}</includeonly><noinclude>
</div>
| <!--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 ==
{{Template demo
| <nowiki>
{{Image frame
| image = Portrait Lae'zel.png
| link = Lae'zel
| width = 120
| border-shape = diamond
| border-width = 4
}}
</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>
{{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
}}
</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>
}}
 
== Template data ==
== Template data ==
<templatedata>
<templatedata>
Line 88: Line 148:
             "type": "number",
             "type": "number",
             "default": "4",
             "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
             "required": false
         }
         }
     }
     }
}
}
</templatedata>
</templatedata>}}
 
[[Category:Templates]]
== Examples ==
{{Template demo
| <nowiki>
{{User:NtCarlson/Template:Foo
| image = Portrait Lae'zel.png
| link = Lae'zel
| width = 120
| border-shape = diamond
| border-width = 4
}}
</nowiki>
| <nowiki>
{{User:NtCarlson/Template:Foo
| image = Portrait Lae'zel.png
| link = Lae'zel
| h  = 120
| bs = rounded
| bw = 2
| bc = red
}}
</nowiki>
| <nowiki>
{{User:NtCarlson/Template:Foo
| 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
}}
</nowiki>
| <nowiki>
{{User:NtCarlson/Template:Foo|Portrait Lae'zel.png|Lae'zel|h=120|bw=0}}
</nowiki>
}}
</noinclude>
</noinclude>

Revision as of 22:44, 20 July 2024

Template documentation

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
}}
Portrait Lae'zel.png
{{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;
}}
Portrait Lae'zel.png
{{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
}}
Portrait Lae'zel.png
{{Image frame|Portrait Lae'zel.png|Lae'zel|h=120|bw=0}}
Portrait Lae'zel.png
{{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);
}}
Portrait Lae'zel.png

Template data

Render an image cropped into a frame of arbitrary shape.

Template parameters

ParameterDescriptionTypeStatus
Image1 image

The image file to display.

Filerequired
Link2 link

Clicking the image redirects to this link instead of the image file.

Page namesuggested
Heightheight h

The height of the image in pixels (does not include any additional height from the border size).

Default
Same value as width, if defined. 100 otherwise.
Numbersuggested
Widthwidth w

The width of the image in pixels (does not include any additional width from the border size).

Default
Same value as height, if defined. 100 otherwise.
Numberoptional
Border shapeborder-shape bs

The shape of the border frame. It can be an arbitrary CSS clip path or use one of the predefined values.

Suggested values
rounded diamond basic
Default
rounded
Example
polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)
Stringsuggested
Border colorborder-color bc

The color of the border frame. This can be any CSS color descriptor.

Default
black
Stringoptional
Border widthborder-width bw

The thickness of the border frame in pixels. Set this to 0 to disable the border entirely.

Default
4
Numberoptional
Classclass

A CSS class to apply to the image div.

Stringoptional
Stylestyle

Any additional CSS style properties to apply to the image div.

Stringoptional