EWICS

showscript

Nov 3rd, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. -- Usage: show_img <nfp_url> [monitor_side_or_name]
  2. -- Example: show_img https://example.com/picture.nfp right
  3.  
  4. local args = {...}
  5. if #args < 1 then
  6. print("Usage: show_img <nfp_url> [monitor_side_or_name]")
  7. return
  8. end
  9.  
  10. local url = args[1]
  11. local monId = args[2] -- optional: side ("right") or peripheral name
  12.  
  13. if not http then
  14. error("HTTP API is disabled. Enable http.enabled=true in the config.")
  15. end
  16.  
  17. -- Find monitor
  18. local mon
  19. if monId then
  20. if peripheral.isPresent(monId) and peripheral.getType(monId) == "monitor" then
  21. mon = peripheral.wrap(monId)
  22. else
  23. error("Monitor not found at '"..monId.."'")
  24. end
  25. else
  26. mon = peripheral.find("monitor")
  27. if not mon then error("No monitor connected.") end
  28. end
  29.  
  30. -- Download the NFP image to a temp file
  31. local tmpPath = "/.dl_image.nfp"
  32. local function download(url, path)
  33. local h = http.get(url, {["Cache-Control"]="no-cache"})
  34. if not h then error("HTTP GET failed for URL: "..url) end
  35. local data = h.readAll()
  36. h.close()
  37. local f = fs.open(path, "w")
  38. f.write(data)
  39. f.close()
  40. end
  41.  
  42. local function drawNfp(path, monitor)
  43. local img = paintutils.loadImage(path)
  44. if not img then error("Could not parse NFP image.") end
  45.  
  46. monitor.setBackgroundColor(colors.black)
  47. monitor.clear()
  48. -- smallest text makes the “pixels” as fine as possible
  49. monitor.setTextScale(0.5)
  50.  
  51. local old = term.redirect(monitor)
  52. -- Draw at top-left (1,1). No scaling is possible with NFP.
  53. paintutils.drawImage(img, 1, 1)
  54. term.redirect(old)
  55. end
  56.  
  57. -- Main
  58. download(url, tmpPath)
  59. local ok, err = pcall(drawNfp, tmpPath, mon)
  60. if not ok then
  61. print("Error: "..tostring(err))
  62. else
  63. print("Image drawn on monitor.")
  64. end
  65. -- Optional: clean up the temp file
  66. -- pcall(fs.delete, tmpPath)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment