Advertisement
CaptainSpaceCat

Image Viewer

May 27th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. local tArgs = {...}
  2. if #tArgs < 1 then
  3.   error("Usage: view <image filename>")
  4. end
  5. if not fs.exists(tArgs[1]) then
  6.   error("Not an image file")
  7. end
  8. image = paintutils.loadImage(tArgs[1])
  9. local w, h = term.getSize()
  10. local imgW = 0
  11. local imgH = 0
  12. local imgWMax = 0
  13. for i, v in pairs(image) do
  14.   imgH = imgH + 1
  15.   imgW = 0
  16.   for k, e in pairs(v) do
  17.     imgW = imgW + 1
  18.     if imgW < imgWMax then
  19.       imgWMax = imgW
  20.     end
  21.   end
  22. end
  23. imgW = imgWMax
  24. term.setBackgroundColor(colors.black)
  25. term.clear()
  26. paintutils.drawImage(image, w / 2 - imgW / 2, h / 2 - imgH / 2 + 1)
  27. term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement