forked from newrelic/futurestack14_badge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.rb
More file actions
executable file
·50 lines (38 loc) · 1.1 KB
/
robot.rb
File metadata and controls
executable file
·50 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
###########################################
# FUTURESTACK 14 BADGE DEMO #
# (c) 2014 New Relic #
# #
# For more information, see: #
# github.com/newrelic/futurestack14_badge #
###########################################
require 'RMagick'
require 'httparty'
WIDTH = 264
HEIGHT = 176
BLACK = 1
WHITE = 0
# You'll want to insert your agent URL here
# Grey link
AGENT_URL = "https://agent.electricimp.com/KFAXR65RRAx_/image"
# Black link
#AGENT_URL = "https://agent.electricimp.com/IRI175o3HuWI/image"
image = Magick::Image.read("robot.png") {
self.colorspace = Magick::GRAYColorspace
self.image_type = Magick::BilevelType
self.antialias = false
}.first
image.rotate!(180)
pixels = image.export_pixels(0, 0, WIDTH, HEIGHT, 'I')
def interlace(pixels)
image = ""
pixels.each_slice(WIDTH) do |row|
binned_pixels = row.map{|x| x > 0 ? WHITE : BLACK}
image << [binned_pixels.join].pack("B*")
end
return image
end
options = {
:body => interlace(pixels)
}
HTTParty.post(AGENT_URL, options)