local args = {...} function split(str, pat) local t = {} local fpat = "(.-)" .. pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end if #args == 0 then print("No link!") else http.request("http://goz3rr.kuubstudios.com/image2text.php?url=" .. table.concat(args, "%20")) local requesting = true while requesting do local event, url, sourceText = os.pullEvent() if event == "http_success" then local data = split(sourceText.readAll(),",") local status = tonumber(data[1]) if status == 1 then local width = tonumber(data[2]) local height = tonumber(data[3]) if width > 0 and height > 0 then print("Received image with resolution: " .. width .. "x" .. height) local oldx, oldy = term.getCursorPos() local screen = peripheral.wrap("left") screen.fill(255, 255, 255) local index = 4 local pixel = 0 for x = 1, width do for y = 1, height do local r = tonumber(data[index]) local g = tonumber(data[index+1]) local b = tonumber(data[index+2]) screen.setColorRGB(r, g, b, x, y) screen.setColorRGB(r, g, b, x, y) index = index + 3 pixel = pixel + 1 end if pixel > 65536 then pixel = 0 coroutine.yield() -- yield every now and then, 256x256 and lower images should load instantly end end end elseif status == 0 then print("Server returned error code 0x" .. data[2]) else print("An unknown error occured") end requesting = false elseif event == "http_failure" then print("Server didn't respond.") requesting = false end end end
The only arguments the program takes is the URL.