Skip to content

Instantly share code, notes, and snippets.

@riocampos
Created November 8, 2014 18:35
Show Gist options
  • Save riocampos/495d31b96a07357751cb to your computer and use it in GitHub Desktop.
Save riocampos/495d31b96a07357751cb to your computer and use it in GitHub Desktop.
image encoding to text by Base64 (refer: http://d.hatena.ne.jp/yuheiomori0718/20111209/1323432840 )
#!/usr/bin/env ruby
require 'base64'
print "image filename: "
image_name = gets.chomp
filename = image_name.sub(/\.(\w+)$/) { "_base64_#{$1}.txt" }
open(filename, 'w') { |f| f.write(Base64.encode64(open(image_name).read).tr("\n", "")) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment