auto-generate image captions
This commit is contained in:
19
bin/encrypt
19
bin/encrypt
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require "open3"
|
||||||
|
|
||||||
file = ARGV.pop || raise("please supply a filename")
|
file = ARGV.pop || raise("please supply a filename")
|
||||||
|
|
||||||
raise("file '#{file}' does not exist") unless File.exist?(file)
|
raise("file '#{file}' does not exist") unless File.exist?(file)
|
||||||
@@ -13,7 +15,22 @@ raise("file '#{file}' does not exist") unless File.exist?(file)
|
|||||||
-iter 1000000
|
-iter 1000000
|
||||||
)
|
)
|
||||||
|
|
||||||
output = %[{{<dither #{ File.basename(file) } "782x600" />}}]
|
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) }
|
IO.popen("pbcopy", "w") { |pb| pb.write(output) }
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
{{ $imgClass := .Get 2 }}
|
{{ $imgClass := .Get 2 }}
|
||||||
|
|
||||||
<a href="{{ $img.RelPermalink }}">
|
<a href="{{ $img.RelPermalink }}">
|
||||||
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" class="{{ $imgClass }}">
|
<img
|
||||||
{{ with .Inner }}
|
src="{{ $img.RelPermalink }}"
|
||||||
<figcaption>
|
width="{{ $img.Width }}"
|
||||||
{{ . }}
|
height="{{ $img.Height }}"
|
||||||
</figcaption>
|
{{ with $imgClass }}class="{{ $imgClass }}"{{ end }}
|
||||||
{{ end }}
|
{{ with .Inner }}alt="{{ . }}"{{ end }}
|
||||||
|
>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user