Left4Cake2

Imagedownloader

Sep 21st, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. local tArgs = { ... }
  2. if tArgs[2] then tArgs[2] = tArgs[2] + 0 end
  3. if tArgs[3] then tArgs[3] = tArgs[3] + 0 end
  4. if #tArgs > 0 then
  5.     if #tArgs == 2 then
  6.         scaleW = tArgs[2]
  7.         scaleH = tArgs[2]
  8.     elseif #tArgs > 2 then
  9.         scaleW = tArgs[2]
  10.         scaleH = tArgs[3]
  11.     else
  12.         scaleW = 1
  13.         scaleH = 1
  14.     end
  15.    
  16.     if scaleW <= 0 then
  17.         scaleW = 1
  18.     end
  19.  
  20.     if scaleH <= 0 then
  21.         scaleH = 1
  22.     end
  23.    
  24.    
  25.     local response = http.post("http://www.lozengia.com/tmas/Downloads/Minecraft/computercraft/CCimage.php", "image=" .. tArgs[1] .. "&scaleW=" .. scaleW .. "&scaleH=" .. scaleH)
  26.     if response then
  27.         while response do
  28.             local sResponse = response.readAll()
  29.             response.close()
  30.             shell.run( "clear" )
  31.             cache = shell.resolve( "image.nfp" )
  32.             local file = fs.open( cache, "w" )
  33.             file.write( sResponse )
  34.             file.close()
  35.             response = nil
  36.             term.redirect(peripheral.wrap("right"))
  37.             local image = paintutils.loadImage("image.nfp")
  38.             paintutils.drawImage(image, 0, 0)
  39.             term.restore()
  40.         end
  41.     else
  42.         -- if image is not reseved
  43.         print( "Error, Could not load image." )
  44.     end
  45.  
  46. else
  47.     print("syntex 1: httpimg url")
  48.     print("syntex 2: httpimg url scale")
  49.     print("syntex 3: httpimg url scaleW scaleH")
  50.  
  51. end
Add Comment
Please, Sign In to add comment