Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simonhildebrandt/a386609dd97209cf7cb019ffc389ae7e to your computer and use it in GitHub Desktop.
Save simonhildebrandt/a386609dd97209cf7cb019ffc389ae7e to your computer and use it in GitHub Desktop.
Use HammerSpoon to capture screenshots, then ImageMagick to compile
require 'mini_magick'
# HammerSpoon config
# function takeScreenshot(window)
# window:snapshot():saveToFile(os.getenv("HOME") .. "/Desktop/chrome-images/" .. os.time() .. ".png")
# end
#
# local wf=hs.window.filter
# wf_chrome = wf.new{'Google Chrome'}
# wf_chrome:subscribe(wf.windowFocused,takeScreenshot)
#MiniMagick.logger.level = Logger::DEBUG
images = Dir['/users/simon.hildebrandt/Desktop/chrome-images/*']
output = File.expand_path('../output', __FILE__)
images.each do |path|
image = MiniMagick::Image.open(path)
image.crop "x36+0"
pieces = path.match /\/(\d+.png)\Z/
image.write File.join(output, pieces[1])
end
images = Dir['output/*']
x = ""
images.each_slice(10).with_index do |slice, i|
MiniMagick::Tool::Montage.new do |out|
slice.each do |image|
out << image
end
out.geometry '+0+0'
out.tile '1x'
out << "out#{i}.png"
x << "<img src='out#{i}.png'>"
end
end
File.open("x.html", 'w') { |f| f.write x }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment