Skip to content

Instantly share code, notes, and snippets.

@jasmarc
Created June 13, 2012 20:09
Show Gist options
  • Save jasmarc/2926224 to your computer and use it in GitHub Desktop.
Save jasmarc/2926224 to your computer and use it in GitHub Desktop.
Creates a photo gallery from a folder full of images, somewhat per this request: http://www.idiotking.org/archives/2012/05/exercise-in-futility/
#! /usr/bin/env ruby
# 1. Save this file as "make_webpages.command"
# 2. chmod a+x+r make_webpages.command
# 3. Place make_webpages.command in folder full of pictures
# 4. Double-click make_webpages.command
extensions = "png,PNG,jpg,JPG,gif"
working_dir = File.dirname($0)
pictures = Dir.glob("#{working_dir}/*.{#{extensions}}")
pictures.each_with_index do |img_name, index|
current_file = "index#{index == 0 ? nil : index}.html"
next_index = (index + 1) % pictures.size
next_file = "index#{next_index == 0 ? nil : next_index}.html"
File.open("#{working_dir}/#{current_file}", "w").write <<-EOF
<html>
<a href="#{next_file}"><img src="#{img_name}" /></a>
</html>
EOF
end
system "cd '#{working_dir}'; open index.html"
@bdgn
Copy link

bdgn commented Jun 14, 2012

Nice! So if I wanted to enclose the image itself with the "next" link, how would I do that? (essentially, remove the "next / back" links at the top, and make the images themselves the link).
Also, is there a way to make the script point the last page to the first page (so that it would loop in a circle)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment