If you appreciate the work done within the wiki, please consider supporting The Cutting Room Floor on Patreon. Thanks for all your support!

Template:Imgcolor

From The Cutting Room Floor
Jump to navigation Jump to search

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
Needs-bgcolor.png
Needs-bgcolor.png

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=200px or width=max if you want a wider background for whatever reason.
  • 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, or right.
  • 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. 300px or max.
    • 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.

Needs-bgcolor.png

{{imgcolor|[[File:Needs-bgcolor.png]]}}


Color names like green can be used.

Needs-bgcolor.png

{{imgcolor|[[File:Needs-bgcolor.png]]|green}}


Hex colors like #f03 will also work.

Needs-bgcolor.png

{{imgcolor|[[File:Needs-bgcolor.png]]|#f03}}

align

Aligning an image to the left, right, or center:

Needs-bgcolor.png
Needs-bgcolor.png
Needs-bgcolor.png

{{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.

Needs-bgcolor.png

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...

Needs-bgcolor.png

...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:

KAKITORIKUN2 menuthing bg.png


With padding, it becomes clearer:

KAKITORIKUN2 menuthing bg.png

{{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:

Needs-bgcolor.png

{{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
Needs-bgcolor.png

{| class="wikitable" ! A very very very very long header row |- |{{imgcolor|[[File:Needs-bgcolor.png]]|width=max}} |}