Module:InfoboxImage
-- Inputs:
 --    image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link
 --    page - page to display for multipage images (DjVu)
 --    size - size to display the image
 --    maxsize - maximum size for image
 --    sizedefault - default size to display the image if size param is blank
 --    alt - alt text for image
 --    title - title text for image
 --    border - set to yes if border
 --    center - set to yes, if the image has to be centered
 --    upright - upright image param
 --    suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
 --    link - page to visit when clicking on image
 --    class - HTML classes to add to the image
 -- Outputs:
 --    Formatted image.
 -- More details available at the &quot;Module:InfoboxImage/doc&quot; page
 
 local i = {};
 
 local placeholder_image = {
     &quot;Blue - Replace this image female.svg&quot;,
     &quot;Blue - Replace this image male.svg&quot;,
     &quot;Female no free image yet.png&quot;,
     &quot;Flag of None (square).svg&quot;,
     &quot;Flag of None.svg&quot;,
     &quot;Flag of.svg&quot;,
     &quot;Green - Replace this image female.svg&quot;,
     &quot;Green - Replace this image male.svg&quot;,
     &quot;Image is needed female.svg&quot;,
     &quot;Image is needed male.svg&quot;,
     &quot;Location map of None.svg&quot;,
     &quot;Male no free image yet.png&quot;,
     &quot;Missing flag.png&quot;,
     &quot;No flag.svg&quot;,
     &quot;No free portrait.svg&quot;,
     &quot;No portrait (female).svg&quot;,
     &quot;No portrait (male).svg&quot;,
     &quot;Red - Replace this image female.svg&quot;,
     &quot;Red - Replace this image male.svg&quot;,
     &quot;Replace this image female (blue).svg&quot;,
     &quot;Replace this image female.svg&quot;,
     &quot;Replace this image male (blue).svg&quot;,
     &quot;Replace this image male.svg&quot;,
     &quot;Silver - Replace this image female.svg&quot;,
     &quot;Silver - Replace this image male.svg&quot;,
     &quot;Replace this image.svg&quot;,
 	&quot;Cricket no pic.png&quot;,
 	&quot;CarersLogo.gif&quot;,
 	&quot;Diagram Needed.svg&quot;,
 	&quot;Example.jpg&quot;,
 	&quot;Image placeholder.png&quot;,
 	&quot;No male portrait.svg&quot;,
 	&quot;Nocover-upload.png&quot;,
 	&quot;NoDVDcover copy.png&quot;,
 	&quot;Noribbon.svg&quot;,
 	&quot;No portrait-BFD-test.svg&quot;,
 	&quot;Placeholder barnstar ribbon.png&quot;,
 	&quot;Project Trains no image.png&quot;,
 	&quot;Image-request.png&quot;,
 	&quot;Sin bandera.svg&quot;,
 	&quot;Sin escudo.svg&quot;,
 	&quot;Replace this image - temple.png&quot;,
 	&quot;Replace this image butterfly.png&quot;,
 	&quot;Replace this image.svg&quot;,
 	&quot;Replace this image1.svg&quot;,
 	&quot;Resolution angle.png&quot;,
 	&quot;Image-No portrait-text-BFD-test.svg&quot;,
 	&quot;Insert image here.svg&quot;,
 	&quot;No image available.png&quot;,
 	&quot;NO IMAGE YET square.png&quot;,
 	&quot;NO IMAGE YET.png&quot;,
 	&quot;No Photo Available.svg&quot;,
 	&quot;No Screenshot.svg&quot;,
 	&quot;No-image-available.jpg&quot;,
 	&quot;Null.png&quot;,
 	&quot;PictureNeeded.gif&quot;,
 	&quot;Place holder.jpg&quot;,
 	&quot;Unbenannt.JPG&quot;,
 	&quot;UploadACopyrightFreeImage.svg&quot;,
 	&quot;UploadAnImage.gif&quot;,
 	&quot;UploadAnImage.svg&quot;,
 	&quot;UploadAnImageShort.svg&quot;,
 	&quot;CarersLogo.gif&quot;,
 	&quot;Diagram Needed.svg&quot;,
 	&quot;No male portrait.svg&quot;,
 	&quot;NoDVDcover copy.png&quot;,
 	&quot;Placeholder barnstar ribbon.png&quot;,
 	&quot;Project Trains no image.png&quot;,
 	&quot;Image-request.png&quot;,
 	&quot;Noimage.gif&quot;,
 }
 
 function i.IsPlaceholder(image)
     -- change underscores to spaces
     image = mw.ustring.gsub(image, &quot;_&quot;, &quot; &quot;);
     assert(image ~= nil, 'mw.ustring.gsub(image, &quot;_&quot;, &quot; &quot;) must not return nil')
     -- if image starts with [[ then remove that and anything after |
     if mw.ustring.sub(image,1,2) == &quot;[[&quot; then
         image = mw.ustring.sub(image,3);
         image = mw.ustring.gsub(image, &quot;([^|]*)|.*&quot;, &quot;%1&quot;);
         assert(image ~= nil, 'mw.ustring.gsub(image, &quot;([^|]*)|.*&quot;, &quot;%1&quot;) must not return nil')
     end
     -- Trim spaces
     image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
     assert(image ~= nil, &quot;mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil&quot;)
     -- remove prefix if exists
     local allNames = mw.site.namespaces[6].aliases
     allNames[#allNames + 1] = mw.site.namespaces[6].name
     allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
     for i, name in ipairs(allNames) do
         if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. &quot;:&quot;) then
             image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
             break
         end
     end
     -- Trim spaces
     image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
     -- capitalise first letter
     image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);
 
     for i,j in pairs(placeholder_image) do
         if image == j then
             return true
         end
     end
     return false
 end
 
 function i.InfoboxImage(frame)
     local image = frame.args[&quot;image&quot;];
     
     if image == &quot;&quot; or image == nil then
         return &quot;&quot;;
     end
     if image == &quot;&amp;nbsp;&quot; then
         return image;
     end
     if frame.args[&quot;suppressplaceholder&quot;] ~= &quot;no&quot; then
         if i.IsPlaceholder(image) == true then
             return &quot;&quot;;
         end
     end
 
     if mw.ustring.lower(mw.ustring.sub(image,1,5)) == &quot;http:&quot; then
         return &quot;&quot;;
     end
     if mw.ustring.lower(mw.ustring.sub(image,1,6)) == &quot;[http:&quot; then
         return &quot;&quot;;
     end
     if mw.ustring.lower(mw.ustring.sub(image,1,7)) == &quot;[[http:&quot; then
         return &quot;&quot;;
     end
     if mw.ustring.lower(mw.ustring.sub(image,1,6)) == &quot;https:&quot; then
         return &quot;&quot;;
     end
     if mw.ustring.lower(mw.ustring.sub(image,1,7)) == &quot;[https:&quot; then
         return &quot;&quot;;
     end
     if mw.ustring.lower(mw.ustring.sub(image,1,8)) == &quot;[[https:&quot; then
         return &quot;&quot;;
     end
 
     if mw.ustring.sub(image,1,2) == &quot;[[&quot; then
         -- search for thumbnail images and add to tracking cat if found
         local cat = &quot;&quot;;
         if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, &quot;|%s*thumb%s*[|%]]&quot;) or mw.ustring.find(image, &quot;|%s*thumbnail%s*[|%]]&quot;)) then
             cat = &quot;[[Category:Pages using infoboxes with thumbnail images]]&quot;;
         end
         return image .. cat;
     elseif mw.ustring.sub(image,1,2) == &quot;{{&quot; and mw.ustring.sub(image,1,3) ~= &quot;{{{&quot; then
         return image;
     elseif mw.ustring.sub(image,1,1) == &quot;&lt;&quot; then
         return image;
     elseif mw.ustring.sub(image,1,8) == mw.ustring.char(127)..&quot;'\&quot;`UNIQ&quot; then
         -- Found strip marker at begining, so pass don't process at all
         return image;
     else
         local result = &quot;&quot;;
         local page = frame.args[&quot;page&quot;];
         local size = frame.args[&quot;size&quot;];
         local maxsize = frame.args[&quot;maxsize&quot;];
         local sizedefault = frame.args[&quot;sizedefault&quot;];
         local alt = frame.args[&quot;alt&quot;];
         local link = frame.args[&quot;link&quot;];
         local title = frame.args[&quot;title&quot;];
         local border = frame.args[&quot;border&quot;];
         local upright = frame.args[&quot;upright&quot;] or &quot;&quot;;
         local thumbtime = frame.args[&quot;thumbtime&quot;] or &quot;&quot;;
         local center = frame.args[&quot;center&quot;];
         local class = frame.args[&quot;class&quot;];
         
         -- remove prefix if exists
         local allNames = mw.site.namespaces[6].aliases
         allNames[#allNames + 1] = mw.site.namespaces[6].name
         allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
         for i, name in ipairs(allNames) do
             if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. &quot;:&quot;) then
                 image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
                 break
             end
         end
         
         if maxsize ~= &quot;&quot; and maxsize ~= nil then
             -- if no sizedefault then set to maxsize
             if sizedefault == &quot;&quot; or sizedefault == nil then
                 sizedefault = maxsize
             end
             -- check to see if size bigger than maxsize
             if size ~= &quot;&quot; and size ~= nil then
                 local sizenumber = tonumber(mw.ustring.match(size,&quot;%d*&quot;)) or 0;
                 local maxsizenumber = tonumber(mw.ustring.match(maxsize,&quot;%d*&quot;)) or 0;
                 if sizenumber&gt;maxsizenumber and maxsizenumber&gt;0 then
                     size = maxsize;
                 end
             end
         end
         -- add px to size if just a number
         if (tonumber(size) or 0) &gt; 0 then
             size = size .. &quot;px&quot;;
         end
         -- add px to sizedefault if just a number
         if (tonumber(sizedefault) or 0) &gt; 0 then
             sizedefault = sizedefault .. &quot;px&quot;;
         end
         
         result = &quot;[[File:&quot; .. image;
         if page ~= &quot;&quot; and page ~= nil then
             result = result .. &quot;|page=&quot; .. page;
         end
         if size ~= &quot;&quot; and size ~= nil then
             result = result .. &quot;|&quot; .. size;
         elseif sizedefault ~= &quot;&quot; and sizedefault ~= nil then
             result = result .. &quot;|&quot; .. sizedefault;
         else
             result = result .. &quot;|frameless&quot;;
         end
         if center == &quot;yes&quot; then
             result = result .. &quot;|center&quot;
         end
         if alt ~= &quot;&quot; and alt ~= nil then
             result = result .. &quot;|alt=&quot; .. alt;
         end
         if link ~= &quot;&quot; and link ~= nil then
             result = result .. &quot;|link=&quot; .. link;
         end
         if border == &quot;yes&quot; then
             result = result .. &quot;|border&quot;;
         end
         if upright == &quot;yes&quot; then
             result = result .. &quot;|upright&quot;;
         elseif upright ~= &quot;&quot; then
             result = result .. &quot;|upright=&quot; .. upright;
         end
         if thumbtime ~= &quot;&quot; then
             result = result .. &quot;|thumbtime=&quot; .. thumbtime;
         end
         if class ~= nil and class ~= &quot;&quot; then
             result = result .. &quot;|class=&quot; .. class;
         end
         -- if alt value is a keyword then do not use as a description
         if alt == &quot;thumbnail&quot; or alt == &quot;thumb&quot; or alt == &quot;frameless&quot; or alt == &quot;left&quot; or alt == &quot;center&quot; or alt == &quot;right&quot; or alt == &quot;upright&quot; or alt == &quot;border&quot; or mw.ustring.match(alt or &quot;&quot;, '^[0-9]*px$', 1) ~= nil then
             alt = nil;
         end
         if title ~= &quot;&quot; and title ~= nil then
             -- does title param contain any templatestyles? If yes then set to blank.
             if mw.ustring.match(frame:preprocess(title), 'UNIQ%-%-templatestyles', 1) ~= nil then
                 title = nil;
             end
         end
         if title ~= &quot;&quot; and title ~= nil then
             result = result .. &quot;|&quot; .. title;
         end
         result = result .. &quot;]]&quot;;
         
         return result;
     end
 end