davideisinger.com

My personal website
Log | Files | Refs | README

encrypt (582B)


      1 #!/usr/bin/env ruby
      2 
      3 require "open3"
      4 require_relative "lib/image_alt_text"
      5 
      6 file = ARGV.pop || raise("please supply a filename")
      7 
      8 raise("file '#{file}' does not exist") unless File.exist?(file)
      9 
     10 %x(
     11   openssl \
     12     aes-256-cbc \
     13     -in #{file} \
     14     -out #{file}.enc \
     15     -pass file:secret.key \
     16     -iter 1000000
     17 )
     18 
     19 begin
     20   alt = ImageAltText.generate(file)
     21 rescue StandardError => error
     22   abort error.message
     23 end
     24 
     25 output = %[{{<dither #{ File.basename(file) } "782x600">}}#{ alt }{{</dither>}}]
     26 
     27 IO.popen("pbcopy", "w") { |pb| pb.write(output) }
     28 
     29 puts output
     30 
     31 File.delete(file)