Guest User

Untitled

a guest
Oct 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. require 'base64'
  2.  
  3. class EncodeHtml
  4. def initialize()
  5. end
  6.  
  7. def img64(path)
  8.  
  9. ext = File.extname(path).strip.downcase[1..-1]
  10. # enc = Base64.encode64(File.open(path, "rb").read) # gives pretty output
  11. enc = Base64.strict_encode64(File.open(path, "rb").read)
  12. "data:image/#{ext};base64," + enc
  13. end
  14.  
  15. def html ary
  16. out = ['<!doctype html><html lang="en"><head> </head><body>',]
  17. ary.each {|path| out << "<img alt='#{path}' \ntitle='#{File.basename path}'\n src='#{img64 path}'\n>\n</br>"}
  18. out << '</body></html>'
  19. File.open("based64.html", 'w') {|f| out.each {|line| f.write line}}
  20. end
  21.  
  22. end
  23.  
  24. ary = if ARGV.length > 0
  25. ARGV
  26. else
  27. %w[
  28. kod.png
  29. ]
  30. end
  31.  
  32. puts EncodeHtml.new.html ary
Add Comment
Please, Sign In to add comment