-- load image to recognize loadSnippet("#93")() -- actually 93 imgWidth, imgHeight, imgPixels = width, height, pixels -- load font loadSnippet("#92")() fontWidth, fontHeight, fontPixels = width, height, pixels cw, ch = 16, 16 -- size of chars -- original text otext = {"!\"#$%&'()*+,-./0123456789:;<=>?@", "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`", "abcdefghijklmnopqrstuvwxyz{|}~ " } function matchCharacter(x1, y1, xf, yf) for y = 0, ch-1 do for x = 0, cw-1 do local from = xf+x + (yf+y)*fontWidth + 1 local to = x1+x + (y1+y)*imgWidth + 1 if imgPixels[to] ~= fontPixels[from] then --print("from="..tostring(from)..", to="..tostring(to)) --print("fail at "..tostring(x).."/"..tostring(y).." "..tostring(imgPixels[to]).." "..tostring(fontPixels[from])) return false end end end return true end floor = math.floor len=floor(imgWidth/cw) result = {} for i=1, len do x1 = (i-1)*cw y1 = 0 for yf = 0, fontHeight-1, ch do for xf = 0, fontWidth-1, cw do if matchCharacter(x1, y1, xf, yf) then local fx = floor(xf/cw)+1 result[i] = otext[floor(yf/ch)+1]:sub(fx, fx) --print("found character: "..tostring(result[i])) break end end if result[i] then break end end end return table.concat(result, "")