If you'd like to support our preservation efforts (and this wasn't cheap), please consider donating or supporting us on Patreon. Thank you!
Template:Imgcolor
This template gives a transparent image a solid-color background. This is useful when the image has details that don't show up against the page background.
| Code: | {{imgcolor|[[File:Needs-bgcolor.png]]}} |
| Before | After |
|---|---|
![]() |
Introduction
{{imgcolor}} is an upgrade from templates like {{gray2}} that TCRF previously used to add a background color to transparent images.
Compared to {{gray2}} and such, this template adds some new features:
- Use any color. You can specify your own color instead of having to make a new template for each one.
- Matches the image's width automatically. No need to type in the image's width anymore, and it will still match if the image's width changes.
- You can still use
width=200pxorwidth=maxif you want a wider background for whatever reason.
- You can still use
- Horizontal alignment: Allows an image to be aligned to the left, right, or center.
- Inline with text: If enabled, the image can appear inline with other text and images.
- Padding: The background color can extend around the image like a margin.
Usage
{{imgcolor|contents|color|options}}
- contents: The image, e.g.
[[File:Image.png]] - color: The background color, e.g.
blue,#00f, and so on. If you leave it out, the default color is gray.
Values for options:
- align=direction: Horizontal alignment. Can be
left,center, orright. - inline=
yes: Normally, the image will always be on a line by itself. If this is used, the image can appear in the same line as other text and images. - padding=amount: Makes the background color extend like a margin around the image by this amount, e.g.
10px. This is useful for hard-to-see details along the edge of an image. - width=amount: Width of the background color for rare cases where you want it wider than the image, e.g.
300pxormax.- Normally you don't need this because by default, it will automatically match the width of the image.
Examples
color
If you don't specify a color, it defaults to gray.
{{imgcolor|[[File:Needs-bgcolor.png]]}}
Color names like green can be used.
{{imgcolor|[[File:Needs-bgcolor.png]]|green}}
Hex colors like #f03 will also work.
{{imgcolor|[[File:Needs-bgcolor.png]]|#f03}}
align
Aligning an image to the left, right, or center:
{{imgcolor|[[File:Needs-bgcolor.png]]|purple|align=left}}
{{imgcolor|[[File:Needs-bgcolor.png]]|limegreen|align=right}}
{{imgcolor|[[File:Needs-bgcolor.png]]|orange|align=center}}
inline
To put an image in the same line as other text, use inline=yes:
Here is some text before the image.
Here is some text after the image.
Here is some text before the image. {{imgcolor|[[File:Needs-bgcolor.png]]|olive|inline=yes}} Here is some text after the image.
You can also change the image's vertical alignment by using the usual method for images:
The image is vertically aligned...
...at the bottom instead of the middle.
The image is vertically aligned... {{imgcolor|[[File:Needs-bgcolor.png|bottom]]|darkblue|inline=yes}} ...at the bottom instead of the middle.
padding
Without padding, it's not immediately clear whether the triangles at either end are transparent or not:
With padding, it becomes clearer:
{{imgcolor|[[File:KAKITORIKUN2_menuthing_bg.png]]|padding=10px}}
width
There is normally no need to use width because by default, the background color automatically matches the width of the image. You can still use a different width if desired:
{{imgcolor|[[File:Needs-bgcolor.png]]|width=200px}}
You can also use width=max to fill up all available space, such as inside a wide table cell:
| A very very very very long header row |
|---|
{| class="wikitable"
! A very very very very long header row
|-
|{{imgcolor|[[File:Needs-bgcolor.png]]|width=max}}
|}
