Created
August 24, 2014 04:40
-
-
Save yakreved/00e1fea10a00ad3af3c6 to your computer and use it in GitHub Desktop.
рисуем картинку текстовыми символами
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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