Difference between revisions of "Template:CSS image crop"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
m (Can we just copy in the docs like that?)
(Removed many things that mean nothing on *this* Wiki, that had been copied from (presumably) big-mama Wikipedia itself. Unless implementing image frames/etc, no reason to mention them. The "Hatnote" could be emulated by another infobox/notice, if needed.)
 
Line 23: Line 23:
 
</div>{{#switch:{{{Location|{{{Align|}}}}}}
 
</div>{{#switch:{{{Location|{{{Align|}}}}}}
 
| center | centre = </div>}}{{#ifeq:1|{{ifnumber|{{{cWidth|}}}{{{cHeight|}}}{{{oTop|}}}{{{oLeft|}}}{{{bSize|}}}}}||[[Category:CSS image crop using invalid parameters]]}}}}<noinclude>
 
| center | centre = </div>}}{{#ifeq:1|{{ifnumber|{{{cWidth|}}}{{{cHeight|}}}{{{oTop|}}}{{{oLeft|}}}{{{bSize|}}}}}||[[Category:CSS image crop using invalid parameters]]}}}}<noinclude>
{{Documentation subpage}}
+
<!-- THIS PROBABLY NOT NEEDED, BUT CHANGE TO HATNOTE-EQUIVALENT IF STILL WANTED {{hatnote|See also [[Template:Easy CSS image crop]], which simplifies the interface for this template a bit.}} -->
{{High-use|demo={{ROOTPAGENAME}}}}
 
 
 
{{hatnote|See also [[Template:Easy CSS image crop]], which simplifies the interface for this template a bit.}}
 
  
 
{{tl|{{BASEPAGENAME}}}} creates a crop of an image inline for previewing the look and feel of a page, or for linking to full images when a slight crop is preferred in an article, but the full image is more encyclopaedic in general. Where only a small section of the image is used after the crop, it's best to upload the crop as a new file, to avoid sending the extra image data to users.  
 
{{tl|{{BASEPAGENAME}}}} creates a crop of an image inline for previewing the look and feel of a page, or for linking to full images when a slight crop is preferred in an article, but the full image is more encyclopaedic in general. Where only a small section of the image is used after the crop, it's best to upload the crop as a new file, to avoid sending the extra image data to users.  
Line 33: Line 30:
  
 
==Usage==
 
==Usage==
<syntaxhighlight lang="wikitext">
+
Can be given the following named parameters:
{{CSS image crop
+
*Image        = The Name of the image file<!--, or may accept {{Annotated image}}-->.
|Image        = The Name of the image file, or may accept {{Annotated image}}.
+
*bSize        = The Base Image width in pixels (the image we are cropping on)
|bSize        = The Base Image width in pixels (the image we are cropping on)
+
*cWidth        = Crop Image Width in pixels
|cWidth        = Crop Image Width in pixels
+
*cHeight      = Crop image Height in pixels
|cHeight      = Crop image Height in pixels
+
*oTop          = Offset Top in pixels, optional and defaults to 0 when omitted
|oTop          = Offset Top in pixels, optional and defaults to 0 when omitted
+
*oLeft        = Offset Left in pixels, optional and defaults to 0 when omitted
|oLeft        = Offset Left in pixels, optional and defaults to 0 when omitted
+
*Location      = 'right', 'left', 'center' or 'none'. Determines placement of the image on the page. Defaults to 'right' when description is provided (as is default for thumb images) When description is blank, location on left (as is default for non-thumbs)
|Location      = 'right', 'left', 'center' or 'none'. Determines placement of the image on the page
+
*Description  = Description (will render out using thumbnail class)
                Defaults to 'right' when description is provided (as is default for thumb images)
+
*Link          = Name of an article to be linked by clicking on the image (omit unless there is a good reason to link to an article instead of the image).
                When description is blank, location on left (as is default for non-thumbs)
+
*Alt          = The alt text for the image.
|Description  = Description (will render out using thumbnail class)
+
*Page          = The page of the file, if there are multiple pages (such as pdf files).
|Link          = Name of an article to be linked by clicking on the image (omit unless there is a
+
*Class        = The MediaWiki class, if needed. Useful for adding skin-invert for dark mode.
                good reason to link to an article instead of the image).
+
*magnify-link  = The image to be linked by the magnify icon (Use if <!--the Image parameter is set to
|Alt          = The alt text for the image.
+
                 {{Annotated image}} or--> the Link parameter leads to something other than the image).
|Page          = The page of the file, if there are multiple pages (such as pdf files).
+
 
|Class        = The MediaWiki class, if needed. Useful for adding skin-invert for dark mode.
 
|magnify-link  = The image to be linked by the magnify icon (Use if the Image parameter is set to
 
                 {{Annotated image}} or the Link parameter leads to something other than the image).
 
}}
 
</syntaxhighlight>
 
  
 
==Examples==
 
==Examples==
Line 79: Line 71:
 
{{clear}}
 
{{clear}}
  
<syntaxhighlight lang="wikitext">{{CSS image crop
+
{{CSS image crop
 
|Image = Dew on grass Luc Viatour.jpg
 
|Image = Dew on grass Luc Viatour.jpg
 
|bSize = 400
 
|bSize = 400
Line 86: Line 78:
 
|oTop = 180
 
|oTop = 180
 
|oLeft = 60
 
|oLeft = 60
}}</syntaxhighlight>
+
}}
  
 
In addition, the cropped image can have a caption-text and be positioned on the page:
 
In addition, the cropped image can have a caption-text and be positioned on the page:
Line 101: Line 93:
 
|Description = A drop of dew on grass (focus on the drop)
 
|Description = A drop of dew on grass (focus on the drop)
 
}}
 
}}
<syntaxhighlight lang="wikitext">{{CSS image crop
+
{{CSS image crop
 
|Image = Dew on grass Luc Viatour.jpg
 
|Image = Dew on grass Luc Viatour.jpg
 
|bSize = 400
 
|bSize = 400
Line 110: Line 102:
 
|Location = center
 
|Location = center
 
|Description = A drop of dew on grass (focus on the drop)
 
|Description = A drop of dew on grass (focus on the drop)
}}</syntaxhighlight>
 
 
Groups of cropped images can be arranged in an [[Template:Image frame|image frame]]:
 
{{Image frame|align=center|border=no|caption=Cropped images in a frame|content=
 
{{stack
 
|{{CSS image crop
 
|Image = Aaron_Burden_2017-05-03_(Unsplash).jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
|{{CSS image crop
 
|Image = Dew on Lemon Grass - Shola Gardens - Kotagiri.jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
}}
 
{{stack
 
|{{CSS image crop
 
|Image = Dew on grass Luc Viatour.jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
|{{CSS image crop
 
|Image = Dew and grass - Flickr - Stiller Beobachter.jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
}}
 
}}
 
<syntaxhighlight lang="wikitext">
 
{{Image frame|align=center|border=no|caption=Cropped images in a frame|content=
 
{{stack
 
|{{CSS image crop
 
|Image = Aaron_Burden_2017-05-03_(Unsplash).jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
|{{CSS image crop
 
|Image = Dew on Lemon Grass - Shola Gardens - Kotagiri.jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
}}
 
{{stack
 
|{{CSS image crop
 
|Image = Dew on grass Luc Viatour.jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
 
}}
 
}}
|{{CSS image crop
 
|Image = Dew and grass - Flickr - Stiller Beobachter.jpg
 
|bSize = 400
 
|cWidth = 100
 
|cHeight = 100
 
|oTop = 180
 
|oLeft = 60
 
}}
 
}}
 
}}
 
</syntaxhighlight>
 
 
==Tracking categories==
 
* {{Category link with count|CSS image crop using invalid parameters}} - Uses of this template with invalid parameters
 
 
==Scripts==
 
The user script [[User:BrandonXLF/CSSImageCrop]] can be used to generate code to use this template with an interactive UI.
 
 
==See also==
 
* {{tl|Easy CSS image crop}}, which simplifies the interface for this template a bit
 
* {{tl|Show SVG}}, which display SVG files from source, including animations
 
* {{tl|Annotated image}}
 
** [[Template:Annotated image/doc/Samples#Cropping an image|with empty "annotations" parameter]]
 
** {{tl|IrinotecanPathway WP229}} (as used in article [[Multidrug resistance-associated protein 2]]), an example of how CSS Image Crop can combine with Annotated Image.
 
 
<includeonly>{{Sandbox other|
 
| <!-- CATEGORIES BELOW THIS LINE, PLEASE: -->
 
[[Category:Image formatting and function templates]]
 
}}</includeonly>
 
 
 
</noinclude>
 
</noinclude>

Latest revision as of 19:49, 13 January 2026


{{CSS image crop}} creates a crop of an image inline for previewing the look and feel of a page, or for linking to full images when a slight crop is preferred in an article, but the full image is more encyclopaedic in general. Where only a small section of the image is used after the crop, it's best to upload the crop as a new file, to avoid sending the extra image data to users.

Note: There was a previous glitch for which some people had to use "tleft" "tright" etc. as a workaround because "left" and "right" did not work. As a result, to avoid having to fix all those pages that used the workaround, the template has been designed to function properly regardless of whether tright or right is used. See template talk for details.

Usage[edit]

Can be given the following named parameters:

  • Image = The Name of the image file.
  • bSize = The Base Image width in pixels (the image we are cropping on)
  • cWidth = Crop Image Width in pixels
  • cHeight = Crop image Height in pixels
  • oTop = Offset Top in pixels, optional and defaults to 0 when omitted
  • oLeft = Offset Left in pixels, optional and defaults to 0 when omitted
  • Location = 'right', 'left', 'center' or 'none'. Determines placement of the image on the page. Defaults to 'right' when description is provided (as is default for thumb images) When description is blank, location on left (as is default for non-thumbs)
  • Description = Description (will render out using thumbnail class)
  • Link = Name of an article to be linked by clicking on the image (omit unless there is a good reason to link to an article instead of the image).
  • Alt = The alt text for the image.
  • Page = The page of the file, if there are multiple pages (such as pdf files).
  • Class = The MediaWiki class, if needed. Useful for adding skin-invert for dark mode.
  • magnify-link = The image to be linked by the magnify icon (Use if the Link parameter leads to something other than the image).


Examples[edit]

Create a cropped image of a single water drop:

Thumbnail of the original file
Dew on grass Luc Viatour.jpg
  • Offset: oTop and oLeft define the upper left corner of the cropped image
  • Crop: cWidth and cHeight define the size of the cropped image
  • Base Size: Offset and Crop are calculated as if the original file had the width bSize
Dew on grass Luc Viatour.jpg

In addition, the cropped image can have a caption-text and be positioned on the page:

  • Location= to position (center, right, left, none)
  • Description= to add a text to the caption
Dew on grass Luc Viatour.jpg
A drop of dew on grass (focus on the drop)
Dew on grass Luc Viatour.jpg
A drop of dew on grass (focus on the drop)