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
|
# File 'lib/barf.rb', line 11
def self.print(path)
image = MiniMagick::Image.open(path)
terminal_width = `tput cols`.to_i
new_height = [2, (image.height * (0.5 * terminal_width / image.width)).to_i * 2].max
image.combine_options do |tmp|
tmp.alpha 'remove'
tmp.flatten
tmp.resize "#{terminal_width}x#{new_height}!"
tmp.dither 'FloydSteinberg'
tmp.remap @palette
end
image.get_pixels.each_slice(2) do |top, bottom|
out = Parallel.map_with_index(top) do |pixel, index|
"\u2584".bg(pixel).fg(bottom[index])
end.join
puts out
end
return nil
end
|