Jump to content

Module:Multiple image: Difference between revisions

From Fifth Empire Wiki
eh max of course
m 103 revisions imported from wikipedia:Module:Multiple_image
 
(48 intermediate revisions by 17 users not shown)
Line 1: Line 1:
-- implements [[template:multiple image]]
-- implements [[template:multiple image]]
local p = {}
local p = {}
local autoscaledimages
local nonautoscaledimages


local function isnotempty(s)
local function isnotempty(s)
Line 6: Line 9:
end
end


local function renderImageCell(image, width, height, link, alt, caption, textalign)  
local function removepx(s)
return tostring(s or ''):match('^(.*)[Pp][Xx]%s*$') or s
end
 
local function getdimensions(s, w, h)
if tonumber(w) and tonumber(h) then
nonautoscaledimages = true
return tonumber(w), tonumber(h)
end
local file = s and mw.title.new('File:' .. mw.uri.decode(mw.ustring.gsub(s,'%|.*$',''), 'WIKI'))
file = file and file.file or {width = 0, height = 0}
w = tonumber(file.width) or 0
h = tonumber(file.height) or 0
autoscaledimages = true
return w, h
end
 
local function renderImageCell(image, width, height, link, alt, thumbtime, caption, class, textalign, istyle, border)
local root = mw.html.create('')
local root = mw.html.create('')
local altstr = ''
local altstr = '|alt=' .. (alt or '')
local classstr = class and ('|class=' .. class) or ''
local linkstr = link and ('|link=' .. link) or ''
local linkstr = link and ('|link=' .. link) or ''
local widthstr = '|' .. tostring(width) .. 'px'
local widthstr = '|' .. tostring(width) .. 'px'
local thumbtimestr = ''
if isnotempty( alt ) then
altstr = '|alt=' .. alt
end
if widthstr == '|-nanpx' then
widthstr = ''
end
if isnotempty( thumbtime ) then
thumbtimestr = '|thumbtime=' .. thumbtime
end
 
local imagediv = root:tag('div')
local imagediv = root:tag('div')
imagediv:addClass('thumbimage')
imagediv:addClass((border ~= 'infobox') and 'thumbimage' or nil)
imagediv:cssText(istyle)
if( height ) then
if( height ) then
imagediv:css('height', tostring(height) .. 'px')
imagediv:css('height', tostring(height) .. 'px')
imagediv:css('overflow', 'hidden')
imagediv:css('overflow', 'hidden')
end
end
imagediv:wikitext('[[file:' .. image .. widthstr .. linkstr .. altstr .. ']]')
imagediv:wikitext('[[file:' .. image .. classstr .. widthstr .. linkstr .. altstr .. thumbtimestr .. ']]')
if isnotempty(caption) then
if isnotempty(caption) then
local captiondiv = root:tag('div')
local captiondiv = root:tag('div')
captiondiv:addClass('thumbcaption')
captiondiv:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
captiondiv:css('clear', 'left')
if isnotempty(textalign) then
if isnotempty(textalign) then
captiondiv:css('text-align', textalign)
captiondiv:addClass('text-align-' .. textalign)
end
end
captiondiv:wikitext(caption)
captiondiv:wikitext(caption)
Line 33: Line 63:


local function getWidth(w1, w2)
local function getWidth(w1, w2)
local w = 0
local w
if isnotempty(w1) then
if isnotempty(w1) then
w = tonumber(w1)
w = tonumber(w1)
elseif isnotempty(w2) then
elseif isnotempty(w2) then
w = tonumber(w2)
w = tonumber(w2)
else
w = 200
end
end
return w
return w or 200
end
 
local function getPerRow(pstr, ic)
-- split string into array using any non-digit as a dilimiter
local pr = mw.text.split(pstr or '', '[^%d][^%d]*')
-- if split failed, assume a single row
if (#pr < 1) then
pr = {tostring(ic)}
end
-- convert the array of strings to an array of numbers,
-- adding any implied/missing numbers at the end of the array
local r = 1
local thisrow = tonumber(pr[1] or ic) or ic
local prownum = {}
while( ic > 0 ) do
prownum[r] = thisrow
ic = ic - thisrow
r = r + 1
-- use the previous if the next is missing and
-- make sure we don't overstep the number of images
thisrow = math.min(tonumber(pr[r] or thisrow) or ic, ic)
end
return prownum
end
end


local function renderMultipleImages(frame)
local function renderMultipleImages(frame)
local args = frame:getParent().args
local pargs = frame:getParent().args
local width = args['width'] or ''
local args = frame.args
local dir = args['direction'] or ''
local width = removepx(pargs['width'] or '')
local align = args['align'] or ''
local dir = pargs['direction'] or ''
local captionalign = args['caption_align'] or ''
local border = pargs['border'] or args['border'] or ''
local totalwidth = args['total_width'] or ''
local align = pargs['align'] or args['align'] or (border == 'infobox' and 'center' or '')
local height = nil
local capalign = pargs['caption_align'] or args['caption_align'] or ''
local header = args['header'] or args['title'] or ''
local totalwidth = removepx(pargs['total_width'] or args['total_width'] or '')
local footer = args['footer'] or ''
local imgstyle = pargs['image_style'] or args['image_style']
local header = pargs['header'] or pargs['title'] or ''
local footer = pargs['footer'] or ''
local imagegap = tonumber(pargs['image_gap'] or '1') or 1
local perrow = nil
local thumbclass = {
local thumbclass = {
["left"] = 'tleft',
["left"] = 'tleft',
Line 62: Line 117:
}
}


-- find all the nonempty images and corresponding widths
-- find all the nonempty images
-- also compute the sum of widths and maximum width
local imagenumbers = {}
local imagenumbers = {}
local widths = {}
local imagecount = 0
local imagecount = 0
local widthmax = 0
for k, v in pairs( pargs ) do
local widthsum = 0
for k, v in pairs( args ) do
local i = tonumber(tostring(k):match( '^%s*image([%d]+)%s*$' ) or '0')
local i = tonumber(tostring(k):match( '^%s*image([%d]+)%s*$' ) or '0')
if( i > 0 and isnotempty(v) ) then
if( i > 0 and isnotempty(v) ) then
table.insert( imagenumbers, i)
table.insert( imagenumbers, i)
imagecount = imagecount + 1
imagecount = imagecount + 1
local w = getWidth(width, args['width' .. i])
-- compute maximum width and width sum
widthmax = math.max(widthmax, w)
widthsum = widthsum + w
-- store the modified width
widths[i] = w
end
end
end
end
Line 85: Line 130:
-- sort the imagenumbers
-- sort the imagenumbers
table.sort(imagenumbers)
table.sort(imagenumbers)
 
-- create an array with the number of images per row
perrow = getPerRow(dir == 'vertical' and '1' or pargs['perrow'], imagecount)
 
-- compute the number of rows
local rowcount = #perrow
 
-- store the image widths and compute row widths and maximum row width
local heights = {}
local widths = {}
local widthmax = 0
local widthsum = {}
local k = 0
for r=1,rowcount do
widthsum[r] = 0
for c=1,perrow[r] do
k = k + 1
if( k <= imagecount ) then
local i = imagenumbers[k]
if( isnotempty(totalwidth) ) then
widths[k], heights[k] = getdimensions(pargs['image' .. i], pargs['width' .. i], pargs['height' .. i])
else
widths[k] = getWidth(width, pargs['width' .. i])
end
widthsum[r] = widthsum[r] + widths[k]
end
end
widthmax = math.max(widthmax, widthsum[r])
end
 
-- make sure the gap is non-negative
if imagegap < 0 then imagegap = 0 end
 
-- if total_width has been specified, rescale the image widths
-- if total_width has been specified, rescale the image widths
if( isnotempty(totalwidth) ) then
if( isnotempty(totalwidth) ) then
totalwidth = tonumber(totalwidth)
totalwidth = tonumber(totalwidth)
if( dir == 'vertical' ) then
widthmax = 0
width = totalwidth - 12
local k = 0
else
for r=1,rowcount do
local tw = totalwidth - 4 * (imagecount - 1) - 12
local koffset = k
local tw = totalwidth - (3 + imagegap) * (perrow[r] - 1) - 12
local ar = {}
local ar = {}
local arsum = 0
local arsum = 0
for k=1,imagecount do
for j=1,perrow[r] do
local i = imagenumbers[k]
k = k + 1
local h = tonumber( args['height' .. i] or '' ) or 0
if( k<= imagecount ) then
if (h > 0) then
local i = imagenumbers[k]
ar[i] = widths[i]/h
local h = heights[k] or 0
height = h
if (h > 0) then
else
ar[j] = widths[k]/h
ar[i] = widths[i]/100
heights[k] = h
else
ar[j] = widths[k]/100
end
arsum = arsum + ar[j]
end
end
arsum = arsum + ar[i]
end
end
local ht = tw/arsum
local ht = tw/arsum
local ws = 0
local ws = 0
for k=1,imagecount do
k = koffset
local i = imagenumbers[k]
for j=1,perrow[r] do
widths[i] = math.floor(ar[i]*ht + 0.5)
k = k + 1
ws = ws + widths[i]
if( k<= imagecount ) then
end
local i = imagenumbers[k]
widthsum = ws
widths[k] = math.floor(ar[j]*ht + 0.5)
if height then
ws = ws + widths[k]
height = math.floor(ht)
if heights[k] then
heights[k] = math.floor(ht)
end
end
end
end
widthsum[r] = ws
widthmax = math.max(widthmax, widthsum[r])
end
end
end
end


-- start building the array of images, if there are images
-- start building the array of images, if there are images
if( imagecount > 0 ) then
if( imagecount > 0 ) then
-- compute width of outer div
local bodywidth = 0
local bodywidth = 0
local bg = args['background color'] or ''
for r=1,rowcount do
if( widthmax == widthsum[r] ) then
bodywidth = widthmax + (3 + imagegap) * (perrow[r] - 1) + 12
end
end
-- The body has a min-width of 100, which needs to be taken into account on specific widths
bodywidth = math.max( 100, bodywidth - 8);
 
local bg = pargs['background color'] or ''
-- create the array of images
-- create the array of images
local root = mw.html.create('div')
local root = mw.html.create('div')
root:addClass('thumb')
root:addClass('thumb')
root:addClass('tmulti')
-- root:addClass('tmulti-sandbox')
root:addClass(thumbclass[align] or 'tright')
root:addClass(thumbclass[align] or 'tright')
if( dir == 'vertical') then
 
bodywidth = widthmax + 12
else
bodywidth = widthsum + 4 * (imagecount - 1) + 12
end
if( align == 'center' or align == 'centre' ) then
if( align == 'center' or align == 'centre' ) then
root:addClass('center')
root:addClass('center')
end
if( args['margin_top'] ) then
root:css('margin-top', args['margin_top'])
end
if( args['margin_bottom'] ) then
root:css('margin-bottom', args['margin_bottom'])
end
end
if( bg ~= '' ) then
if( bg ~= '' ) then
root:css('background-color', bg)
root:css('background-color', bg)
end
end
-- The body has a min-width of 100, which needs to be taken into account on specific widths
 
bodywidth = math.max( 100, bodywidth - 8);
local div = root:tag('div')
local div = root:tag('div')
div:addClass('thumbinner')
div:addClass((border ~= 'infobox') and 'thumbinner multiimageinner' or 'multiimageinner')
div:css('width', tostring(bodywidth) .. 'px')
div:css('width', tostring(bodywidth) .. 'px')
:css('max-width', tostring(bodywidth) .. 'px')
:css('max-width', tostring(bodywidth) .. 'px')
if( bg ~= '' ) then
if( bg ~= '' ) then
div:css('background-color', bg)
div:css('background-color', bg)
end
if( border == 'infobox' or border == 'none') then
div:css('border', 'none')
end
end
-- add the header
-- add the header
if( isnotempty(header) ) then
if( isnotempty(header) ) then
div:tag('div')
div:tag('div')
:css('clear', 'both')
:addClass('trow')
:css('font-weight', 'bold')
:tag('div')
:css('text-align', args['header_align'] or 'center')
:addClass('theader')
:css('background-color', args['header_background'] or 'transparent')
:css('text-align', pargs['header_align'])
:wikitext(header)
:css('background-color',  
(pargs['header_background'] ~= '') and pargs['header_background'] or nil)
:wikitext(header)
end
end
-- loop through the images
-- loop through the images
for k=1,imagecount do
local k = 0
imagediv = div:tag('div')
for r=1,rowcount do
if dir ~= 'vertical' then
local rowdiv = div:tag('div'):addClass('trow');
imagediv:css('float', 'left')
for j=1,perrow[r] do
end
k = k + 1
if bg ~= '' then
if( k <= imagecount ) then
imagediv:css('background-color', bg);
local imagediv = rowdiv:tag('div')
imagediv:addClass('tsingle')
if bg ~= '' then
imagediv:css('background-color', bg);
end
if imagegap > 1 and k < imagecount then
if dir == 'vertical' then
imagediv:css('margin-bottom', tostring(imagegap) .. 'px')
elseif j < perrow[r] then
imagediv:css('margin-right', tostring(imagegap) .. 'px')
end
end
local i = imagenumbers[k]
local img = pargs['image' .. i]
local w = widths[k]
imagediv:css('width', tostring(2 + w) .. 'px')
:css('max-width', tostring(2 + w) .. 'px')
imagediv:wikitext(renderImageCell(img, w, heights[k],
pargs['link' .. i], pargs['alt' .. i],
pargs['thumbtime' .. i], pargs['caption' .. i], pargs['class' .. i], capalign, imgstyle, border))
end
end
end
imagediv:css('margin', '1px')
local i = imagenumbers[k]
local img = args['image' .. i]
local w = widths[i]
imagediv:css('width', tostring(2 + w) .. 'px')
:css('max-width', tostring(2 + w) .. 'px')
imagediv:wikitext(renderImageCell(img, w, height,
args['link' .. i], args['alt' .. i], args['caption' .. i], captionalign))
end
end
-- only float content gives a parent height:0, so add a clearing div
div:tag('div')
:css('clear', 'left')
-- add the footer
-- add the footer
if( isnotempty(footer) ) then
if( isnotempty(footer) ) then
local falign = string.lower(pargs['footer_align'] or args['footer_align'] or '')
falign = (falign == 'centre') and 'center' or falign
div:tag('div')
div:tag('div')
:addClass('thumbcaption')
:addClass('trow')
:css('clear', 'left')
:css('display', (falign ~= '') and 'flow-root' or 'flex')
:css('text-align', args['footer_align'] or 'left')
:tag('div')
:css('background-color', args['footer_background'] or 'transparent')
:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
:wikitext(footer)
:css('text-align', (falign ~= '') and falign or nil)
:css('background-color',  
(pargs['footer_background'] ~= '') and pargs['footer_background'] or nil)
:wikitext(footer)
end
end
return tostring(root)
return tostring(root)
Line 199: Line 304:


function p.render( frame )
function p.render( frame )
    return renderMultipleImages( frame )
autoscaledimages = false
nonautoscaledimages = false
 
local check = require('Module:Check for unknown parameters')._check
local tracking = check({
['unknown'] = frame:expandTemplate{
title = 'main other',
args = {'[[Category:Pages using multiple image with unknown parameters|_VALUE_ ]]'}
},
['preview'] = 'Page using [[Template:Multiple image]] with unknown parameter "_VALUE_"',
['ignoreblank'] = 'y',
regexp1 = 'image%d+',
regexp2 = 'width%d+',
regexp3 = 'height%d+',
regexp4 = 'class%d+',
regexp5 = 'alt%d+',
regexp6 = 'link%d+',
regexp7 = 'thumbtime%d+',
regexp8 = 'caption%d+',
'align', 'direction', 'background color', 'header_background',
'header_align', 'header', 'width', 'total_width',
'caption_align', 'footer_background', 'footer_align', 'footer',
'perrow', 'title', 'image_gap', 'border', 'image_style'
}, frame:getParent().args)
return frame:extensionTag {name = 'templatestyles', args = {src = 'Multiple image/styles.css', wrapper = ".tmulti"}}
.. renderMultipleImages( frame )
.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')
.. tracking
end
end
 
p[''] = function( frame ) return p.render( frame:newChild{title = frame:getTitle()} ) end
 
return p
return p

Latest revision as of 15:59, 24 January 2026

Documentation for this module may be created at Module:Multiple image/doc

-- implements [[template:multiple image]]
local p = {}

local autoscaledimages
local nonautoscaledimages

local function isnotempty(s)
	return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end

local function removepx(s)
	return tostring(s or ''):match('^(.*)[Pp][Xx]%s*$') or s
end

local function getdimensions(s, w, h)
	if tonumber(w) and tonumber(h) then
		nonautoscaledimages = true
		return tonumber(w), tonumber(h)
	end
	local file = s and mw.title.new('File:' .. mw.uri.decode(mw.ustring.gsub(s,'%|.*$',''), 'WIKI'))
	file = file and file.file or {width = 0, height = 0}
	w = tonumber(file.width) or 0
	h = tonumber(file.height) or 0
	autoscaledimages = true
	return w, h
end

local function renderImageCell(image, width, height, link, alt, thumbtime, caption, class, textalign, istyle, border)
	local root = mw.html.create('')
	local altstr = ''
	local classstr = class and ('|class=' .. class) or ''
	local linkstr = link and ('|link=' .. link) or ''
	local widthstr = '|' .. tostring(width) .. 'px'
	local thumbtimestr = ''
	if isnotempty( alt ) then
		altstr = '|alt=' .. alt
	end
	if widthstr == '|-nanpx' then
		widthstr = ''
	end
	if isnotempty( thumbtime ) then
		thumbtimestr = '|thumbtime=' .. thumbtime
	end

	local imagediv = root:tag('div')
	imagediv:addClass((border ~= 'infobox') and 'thumbimage' or nil)
	imagediv:cssText(istyle)
	if( height ) then
		imagediv:css('height', tostring(height) .. 'px')
		imagediv:css('overflow', 'hidden')
	end
	imagediv:wikitext('[[file:' .. image .. classstr .. widthstr .. linkstr .. altstr .. thumbtimestr .. ']]')
	if isnotempty(caption) then
		local captiondiv = root:tag('div')
		captiondiv:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
		if isnotempty(textalign) then
			captiondiv:addClass('text-align-' .. textalign)
		end
		captiondiv:wikitext(caption)
	end
	return tostring(root)
end

local function getWidth(w1, w2)
	local w
	if isnotempty(w1) then
		w = tonumber(w1)
	elseif isnotempty(w2) then
		w = tonumber(w2)
	end
	return w or 200
end

local function getPerRow(pstr, ic)
	-- split string into array using any non-digit as a dilimiter
	local pr = mw.text.split(pstr or '', '[^%d][^%d]*')
	-- if split failed, assume a single row
	if (#pr < 1) then
		pr = {tostring(ic)}
	end
	-- convert the array of strings to an array of numbers,
	-- adding any implied/missing numbers at the end of the array
	local r = 1
	local thisrow = tonumber(pr[1] or ic) or ic
	local prownum = {}
	while( ic > 0 ) do
		prownum[r] = thisrow
		ic = ic - thisrow
		r = r + 1
		-- use the previous if the next is missing and
		-- make sure we don't overstep the number of images
		thisrow = math.min(tonumber(pr[r] or thisrow) or ic, ic)
	end
	return prownum
end

local function renderMultipleImages(frame)
	local pargs = frame:getParent().args
	local args = frame.args
	local width = removepx(pargs['width'] or '')
	local dir = pargs['direction'] or ''
	local border = pargs['border'] or args['border'] or ''
	local align = pargs['align'] or args['align'] or (border == 'infobox' and 'center' or '')
	local capalign = pargs['caption_align'] or args['caption_align'] or ''
	local totalwidth = removepx(pargs['total_width'] or args['total_width'] or '')
	local imgstyle = pargs['image_style'] or args['image_style']
	local header = pargs['header'] or pargs['title'] or ''
	local footer = pargs['footer'] or ''
	local imagegap = tonumber(pargs['image_gap'] or '1') or 1
	local perrow = nil
	local thumbclass = {
		["left"] = 'tleft',
		["none"] = 'tnone',
		["center"] = 'tnone',
		["centre"] = 'tnone',
		["right"] = 'tright'
		}

	-- find all the nonempty images
	local imagenumbers = {}
	local imagecount = 0
	for k, v in pairs( pargs ) do
		local i = tonumber(tostring(k):match( '^%s*image([%d]+)%s*$' ) or '0')
		if( i > 0 and isnotempty(v) ) then
			table.insert( imagenumbers, i)
			imagecount = imagecount + 1
		end
	end

	-- sort the imagenumbers
	table.sort(imagenumbers)

	-- create an array with the number of images per row
	perrow = getPerRow(dir == 'vertical' and '1' or pargs['perrow'], imagecount)

	-- compute the number of rows
	local rowcount = #perrow

	-- store the image widths and compute row widths and maximum row width
	local heights = {}
	local widths = {}
	local widthmax = 0
	local widthsum = {}
	local k = 0
	for r=1,rowcount do
		widthsum[r] = 0
		for c=1,perrow[r] do
			k = k + 1
			if( k <= imagecount ) then
				local i = imagenumbers[k]
				if( isnotempty(totalwidth) ) then
					widths[k], heights[k] = getdimensions(pargs['image' .. i], pargs['width' .. i], pargs['height' .. i])
				else
					widths[k] = getWidth(width, pargs['width' .. i])
				end
				widthsum[r] = widthsum[r] + widths[k]
			end
		end
		widthmax = math.max(widthmax, widthsum[r])
	end

	-- make sure the gap is non-negative
	if imagegap < 0 then imagegap = 0 end

	-- if total_width has been specified, rescale the image widths
	if( isnotempty(totalwidth) ) then
		totalwidth = tonumber(totalwidth)
		widthmax = 0
		local k = 0
		for r=1,rowcount do
			local koffset = k
			local tw = totalwidth - (3 + imagegap) * (perrow[r] - 1) - 12
			local ar = {}
			local arsum = 0
			for j=1,perrow[r] do
				k = k + 1
				if( k<= imagecount ) then
					local i = imagenumbers[k]
					local h = heights[k] or 0
					if (h > 0) then
						ar[j] = widths[k]/h
						heights[k] = h
					else
						ar[j] = widths[k]/100
					end
					arsum = arsum + ar[j]
				end
			end
			local ht = tw/arsum
			local ws = 0
			k = koffset
			for j=1,perrow[r] do
				k = k + 1
				if( k<= imagecount ) then
					local i = imagenumbers[k]
					widths[k] = math.floor(ar[j]*ht + 0.5)
					ws = ws + widths[k]
					if heights[k] then
						heights[k] = math.floor(ht)
					end
				end
			end
			widthsum[r] = ws
			widthmax = math.max(widthmax, widthsum[r])
		end
	end

	-- start building the array of images, if there are images
	if( imagecount > 0 ) then
		-- compute width of outer div
		local bodywidth = 0
		for r=1,rowcount do
			if( widthmax == widthsum[r] ) then
				bodywidth = widthmax + (3 + imagegap) * (perrow[r] - 1) + 12
			end
		end
		-- The body has a min-width of 100, which needs to be taken into account on specific widths
		bodywidth = math.max( 100, bodywidth - 8);

		local bg = pargs['background color'] or ''
		-- create the array of images
		local root = mw.html.create('div')
		root:addClass('thumb')
		root:addClass('tmulti')
		-- root:addClass('tmulti-sandbox')
		root:addClass(thumbclass[align] or 'tright')

		if( align == 'center' or align == 'centre' ) then
			root:addClass('center')
		end
		if( bg ~= '' ) then
			root:css('background-color', bg)
		end

		local div = root:tag('div')
		div:addClass((border ~= 'infobox') and 'thumbinner multiimageinner' or 'multiimageinner')
		div:css('width', tostring(bodywidth) .. 'px')
			:css('max-width', tostring(bodywidth) .. 'px')
		if( bg ~= '' ) then
			div:css('background-color', bg)
		end
		if( border == 'infobox' or border == 'none') then
			div:css('border', 'none')
		end
		-- add the header
		if( isnotempty(header) ) then
			div:tag('div')
				:addClass('trow')
				:tag('div')
					:addClass('theader')
					:css('text-align', pargs['header_align'])
					:css('background-color', 
						(pargs['header_background'] ~= '') and pargs['header_background'] or nil)
					:wikitext(header)
		end
		-- loop through the images
		local k = 0
		for r=1,rowcount do
			local rowdiv = div:tag('div'):addClass('trow');
			for j=1,perrow[r] do
				k = k + 1
				if( k <= imagecount ) then
					local imagediv = rowdiv:tag('div')
					imagediv:addClass('tsingle')
					if bg ~= '' then
						imagediv:css('background-color', bg);
					end
					if imagegap > 1 and k < imagecount then
						if dir == 'vertical' then
							imagediv:css('margin-bottom', tostring(imagegap) .. 'px')	
						elseif j < perrow[r] then
							imagediv:css('margin-right', tostring(imagegap) .. 'px')
						end
					end
					local i = imagenumbers[k]
					local img = pargs['image' .. i]
					local w = widths[k]
					imagediv:css('width', tostring(2 + w) .. 'px')
						:css('max-width', tostring(2 + w) .. 'px')
					imagediv:wikitext(renderImageCell(img, w, heights[k],
						pargs['link' .. i], pargs['alt' .. i],
						pargs['thumbtime' .. i], pargs['caption' .. i], pargs['class' .. i], capalign, imgstyle, border))
				end
			end
		end
		-- add the footer
		if( isnotempty(footer) ) then
			local falign = string.lower(pargs['footer_align'] or args['footer_align'] or '')
			falign = (falign == 'centre') and 'center' or falign
			div:tag('div')
				:addClass('trow')
				:css('display', (falign ~= '') and 'flow-root' or 'flex')
				:tag('div')
					:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
					:css('text-align', (falign ~= '') and falign or nil)
					:css('background-color', 
						(pargs['footer_background'] ~= '') and pargs['footer_background'] or nil)
					:wikitext(footer)
		end
		return tostring(root)
	end
	return ''
end

function p.render( frame )
	autoscaledimages = false
	nonautoscaledimages = false

	local check = require('Module:Check for unknown parameters')._check
	local tracking = check({
		['unknown'] = frame:expandTemplate{
			title = 'main other',
			args = {'[[Category:Pages using multiple image with unknown parameters|_VALUE_ ]]'}
		},
		['preview'] = 'Page using [[Template:Multiple image]] with unknown parameter "_VALUE_"',
		['ignoreblank'] = 'y',
		regexp1 = 'image%d+',
		regexp2 = 'width%d+',
		regexp3 = 'height%d+',
		regexp4 = 'class%d+',
		regexp5 = 'alt%d+',
		regexp6 = 'link%d+',
		regexp7 = 'thumbtime%d+',
		regexp8 = 'caption%d+',
		'align', 'direction', 'background color', 'header_background', 
		'header_align', 'header', 'width', 'total_width', 
		'caption_align', 'footer_background', 'footer_align', 'footer', 
		'perrow', 'title', 'image_gap', 'border', 'image_style' 
	}, frame:getParent().args)
	
	return frame:extensionTag {name = 'templatestyles', args = {src = 'Multiple image/styles.css', wrapper = ".tmulti"}}
		.. renderMultipleImages( frame )
		.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
		.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')
		.. tracking
end

p[''] = function( frame ) return p.render( frame:newChild{title = frame:getTitle()} ) end

return p