Created
October 19, 2017 19:52
-
-
Save ufo2mstar/6a80a7aaa2f5058966dd7c4ff731e614 to your computer and use it in GitHub Desktop.
HTML Base64 image Encoder
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 'base64' | |
class EncodeHtml | |
def initialize() | |
end | |
def img64(path) | |
ext = File.extname(path).strip.downcase[1..-1] | |
# enc = Base64.encode64(File.open(path, "rb").read) # gives pretty output | |
enc = Base64.strict_encode64(File.open(path, "rb").read) | |
"data:image/#{ext};base64," + enc | |
end | |
def html ary | |
out = ['<!doctype html><html lang="en"><head> </head><body>',] | |
ary.each {|path| out << "<img alt='#{path}' \ntitle='#{File.basename path}'\n src='#{img64 path}'\n>\n</br>"} | |
out << '</body></html>' | |
File.open("based64.html", 'w') {|f| out.each {|line| f.write line}} | |
end | |
end | |
ary = if ARGV.length > 0 | |
ARGV | |
else | |
%w[ | |
kod.png | |
] | |
end | |
puts EncodeHtml.new.html ary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment