40 lines
781 B
Ruby
Executable File
40 lines
781 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require "open3"
|
|
|
|
file = ARGV.pop || raise("please supply a filename")
|
|
|
|
raise("file '#{file}' does not exist") unless File.exist?(file)
|
|
|
|
%x(
|
|
openssl \
|
|
aes-256-cbc \
|
|
-in #{file} \
|
|
-out #{file}.enc \
|
|
-pass file:secret.key \
|
|
-iter 1000000
|
|
)
|
|
|
|
caption_cmd = ["codex", "exec", "caption this image: #{file}"]
|
|
caption_output, status = Open3.capture2e(*caption_cmd)
|
|
|
|
unless status.success?
|
|
warn "Caption generation failed:\n#{caption_output}"
|
|
exit 1
|
|
end
|
|
|
|
caption = caption_output.split("\n").last.to_s.strip
|
|
|
|
if caption.empty?
|
|
warn "Caption output was empty."
|
|
exit 1
|
|
end
|
|
|
|
output = %[{{<dither #{ File.basename(file) } "782x600">}}#{ caption }{{</dither>}}]
|
|
|
|
IO.popen("pbcopy", "w") { |pb| pb.write(output) }
|
|
|
|
puts output
|
|
|
|
File.delete(file)
|