Skip to content

Instantly share code, notes, and snippets.

@bdgn
Forked from jasmarc/create_webpages.command
Last active October 8, 2015 00:18
Show Gist options
  • Select an option

  • Save bdgn/3248032 to your computer and use it in GitHub Desktop.

Select an option

Save bdgn/3248032 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
# Original version written by Jason Marcell: https://github.com/jasmarc
# Edits made by Bill Dugan https://gist.github.com/bdgn
# Github: https://gist.github.com/bdgn/3248032
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
<!--
body {
margin: 0px;
width: 100%;
text-align: center;
}
div#container {
display: inline-block;
}
-->
</style></head>
<body>
<div ID="container"><a href="#{next_file}"><img src="#{File.basename(img_name)}" /></a></div>
</body>
</html>
EOF
end
system "cd '#{working_dir}'; open index.html"
@bdgn
Copy link
Author

bdgn commented Aug 3, 2012

Fixed the basename so that the IMG tag wasn't writing the location all the way back to root.

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