Project Icon Generator

This has been pretty useful to me, so I figured I might as well post it:

I made a function to generate a clean-looking icon for a project -

function makeIcon(name, description, col, mfont)
    local size = 120
    local im = image(size, size)
    setContext(im)
    
    background(255)
    
    stroke(0)
    fill(col or color(127, 127, 127, 255))
    
    strokeWidth(1)
    noSmooth()
    
    textMode(CORNER)
    
    font(mfont or "HelveticaNeue-Bold")
    fontSize(32 * size / 256)
    
    textWrapWidth(size - 10)
    
    local w, h = textSize(name)
    
    text(name, 5, size - 5 - h)
    
    if description then
        if description == "LIBRARY" then
            fill(127,127,255)
        else
            fill(255, 127, 127)
        end
        text(description, 5, 5)
    end
    
    setContext()
    
    return im
end

To use it, just add this line to your program:

saveImage( "Project:Icon", makeIcon("Title", "DESCRIPTION") )

You can also alter the color and font of the image, by adding more arguments.

saveImage( "Project:Icon", makeIcon("Title", "DESCRIPTION", TITLE_COLOR, "Font-Name") )

It results in icons like these

@FLCode thanks for the share - style not to my taste but like the concept

Thanks for sharing this. The real magic is just one line:

saveImage( "Project:Icon", icon )

Thanks! I’ll be posting a new version pretty soon, that makes it look a bit better.

Alright, here’s the newest version:

function makeIcon(name, description, col, ext)
    if ext then
        mfont = ext.font
        desctype = (tostring(ext.type)):upper()
        bgcol = ext.background
    end
    local size = 122
    local im = image(size, size)
    setContext(im)
    
    noSmooth()
    
    strokeWidth(1/ ContentScaleFactor)
    stroke(255, 255, 255, 255)
    fill(bgcol or color(255,255,255))
    local rmode = rectMode()
    rectMode(CORNER)
    rect(0, 0, size, size)
    
    --background(255)
    
    stroke(0)
    fill(col or color(127, 127, 127, 255))
    
    strokeWidth(1)
    
    local tmode = textMode()
    
    textMode(CORNER)
    
    font(mfont or "HelveticaNeue-Bold")
    fontSize(42 * size / 256)
    
    local tWrap = textWrapWidth()
    
    textWrapWidth(size - 10)
    
    local w, h = textSize(name)
    
    text(name, 5, size - 5 - h)
    
    if description then
        if description:find("LIBRARY") or desctype == "LIBRARY" then --Library File
            fill(0, 0, 255, 127)
        elseif description:find("TESTING") or desctype == "TESTING" then --Testing File
            fill(255, 128, 0, 127)
        elseif description:find("UTILITY") or desctype == "UTILITY" then --Utility Program
            fill(255, 0, 0, 127)
        elseif description:find("OBSOLETE") or desctype == "OBSOLETE" then --Utility Program
            fill(113, 31, 31, 127)
        elseif description:find("FORUM") or desctype == "FORUM" then --Utility Program
            fill(26, 151, 26, 127)
        elseif description:upper() ~= description then --General Description
            fill(0, 0, 0, 127)
        else
            fill(255, 0, 0, 127) --Specs
        end
        fontSize(32 * size / 256)
        text(description, 5, 5)
    end
    
    setContext()
    
    textWrapWidth(tWrap)
    
    textMode(tmode)
    
    rectMode(rmode)
    
    return im
end

ADDED:
Larger title size
Control of background color
PRETTY COLORS!

The new syntax is:

makeIcon ( "Title" , "DESCRIPTION" , (Title) )

If you want to be really fancy, you can add an extended styles table:

{ 
     ["font"] = "Name-Of-Font",
     ["background"] = (Background Color),
     ["type"] = ("LIBRARY" or "TESTING" or "UTILITY" or "OBSOLETE" or "FORUM") 
}