Created
July 4, 2019 18:59
-
-
Save havenwood/4d779ca0c920ed06d9021a64390222ac to your computer and use it in GitHub Desktop.
A quick spike to turn ascii art into a png
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
# frozen_string_literal: true | |
require 'chunky_png' | |
ascii = <<~ASCII | |
@@@@@@ @@@@@@ | |
@@@@@@@@@@ @@@@@@@@@@ | |
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@ @@@@@@@@@@@@ | |
@@@@@@@@@@ @@@@@@@@@@ | |
@@@@@@@@@@@ @@@@@@@@@@@ | |
@@@@@@@@@@@@ @@@@@@@@@@@@ | |
@@@@@@@@@@@@@ @@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@ @@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@@@@@ | |
@@@@@@@@@@@ | |
@@@@@@@ | |
@@@ | |
@ | |
ASCII | |
lines = ascii.lines | |
horizontal = lines.max_by(&:size).size | |
vertical = lines.size * 2 | |
red = [255, 0, 0] | |
alpha = 255 | |
filename = 'ruby.png' | |
png = ChunkyPNG::Image.new(horizontal, vertical, ChunkyPNG::Color::TRANSPARENT) | |
lines.flat_map { |line| [line, line] }.each_with_index do |line, y| | |
line.each_char.with_index do |char, x| | |
png[x, y] = ChunkyPNG::Color.rgba(*red, alpha) if char != ' ' | |
end | |
end | |
png.save(filename, interlace: true) |
Author
havenwood
commented
Jul 4, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment