Skip to content

Instantly share code, notes, and snippets.

@yakreved
Created August 24, 2014 04:40
Show Gist options
  • Save yakreved/00e1fea10a00ad3af3c6 to your computer and use it in GitHub Desktop.
Save yakreved/00e1fea10a00ad3af3c6 to your computer and use it in GitHub Desktop.
рисуем картинку текстовыми символами
require 'mini_magick'
require 'chunky_png'
def color_to_s(i)
dict = [' ', '.','`', ',', '^', '"',':','-','|','/','+','c','a','w','4','A','%','$','#','@']
dict.reverse!
curr =dict.length
curr = (i/(4294967040/(dict.length-1))).floor if i!=0
dict[curr]
end
#img = MiniMagick::Image.open("C:/minami-ke6.png")
img = MiniMagick::Image.open("C:/3.jpg")
img.resize "256x256"
img.format('png')
p = ChunkyPNG::Image.from_io(StringIO.new(img.to_blob))
p.grayscale!
output = ""
p.height.times do |y|
p.width.times do |x|
output+= color_to_s(p[x, y]) if(y%2!=0)
color_to_s(p[x, y])
end
output+= "\n" if(y%2!=0)
end
puts output
File.open('result.txt', "w") do |file|
file.write(output)
end
img.write("origin.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment