--- The purpose of this module is to show pieces of an image file instead of the whole image. --- One intended use is within other templates, such as a template to return flags of many --- countries, so that you need to load only ONE image to produce all the flags on the page --- This should produce - but is not actually known to - some increase in performance. --- It might also be useful for pulling out entries from very large tables of graphics, such --- as one character from a font.
--- This module accepts a filename, and uses Template:Sprite/filename (or parameter spritedefs) --- to identify sprites within the image at filename. --- it locates a given name for a sprite within the file and scales it to the desired width
local p=
function spritedraw(left,right,top,bottom,name,imagewidth,spritewidth,scalewidth,float) if (left
nil or top
nil or name
nil or spritewidth
nil) then return tostring(left) .. tostring(right)..tostring(top)..tostring(bottom)..tostring(name)..tostring(imagewidth)..tostring(spritewidth)..tostring(scalewidth) end if float then float="float:"..float..";" else float="" end local scale=scalewidth/spritewidth top=math.floor(top*scale) bottom=math.floor(bottom*scale) left=math.floor(left*scale) right=math.floor(right*scale) local scalestring="" if scalewidth~=spritewidth then scalestring=math.floor(imagewidth*scale)..'px|' end output='
' return outputend
function p.sprite(frame) local args=frame.args local parent=frame.getParent(frame) local pargs=parent.args local imagewidth=args.imagewidth or pargs.imagewidth or 360 local spritewidth=args.spritewidth or pargs.spritewidth or 120 local scalewidth=args.width or pargs.width or 120 local leftcol=0;local midcol=120;local rightcol=240 local filename=args.filename or pargs.filename or "" if filename
name or count
return p