function setPixel(x, y, pix) if x >= 0 and y >= 0 and x < w and y < h then pixels[y*w+x+1] = pix end end i, j, x1, y1, x2, y2 = string.find(result, "(%d+),%s*(%d+),%s*(%d+),%s*(%d+)") -- copy image w, h = img.width, img.height pixels = {} for y = 0, h-1 do for x = 0, w-1 do pixels[y*w+x+1] = img.getInt(x, y) end end -- paint rectangle x1, y1 = x1-1, y1-1 -- paint AROUND the found image x2, y2 = tonumber(x2), tonumber(y2) for y = y1, y2 do setPixel(x1, y, 0xFF0000) setPixel(x2, y, 0xFF0000) end for x = x1, x2 do setPixel(x, y1, 0xFF0000) setPixel(x, y2, 0xFF0000) end