Skip to content

Commit

Permalink
add day_to_day finished script
Browse files Browse the repository at this point in the history
  • Loading branch information
alx committed Nov 26, 2011
1 parent fa6ba39 commit 4f98dc2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
data
calendar/pixel-days*
day_to_day/*
.DS_Store
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -19,3 +19,13 @@ Run:

ruby calendar.rb
open calendar/index.html

## Day to Day

Run to create montage files:

ruby day_to_day.rb

Create a movie from montage files with ffmpeg:

mpeg -r 10 -b 1800 -i montage_%03d.jpg test1800.mp4
36 changes: 24 additions & 12 deletions day_to_day.rb
Expand Up @@ -4,37 +4,49 @@

def create_blank_images(date)
color = "dark" # or white
dest_dir = File.join("day_to_day", "day-#{date.strftime("%j")}")
dest_dir = File.join("day_to_day", "day-#{date.strftime("%Y-%j")}")
unless File.exists?(dest_dir)
p dest_dir
FileUtils.mkdir_p(dest_dir)
288.times do |image_index|
f = File.join(dest_dir, "#{image_index}.jpg")
`convert blank_#{color}.jpg -resize 64x48 #{f}` unless File.exists? f
`convert blank_#{color}.jpg -resize 64x48\! #{f}` unless File.exists? f
end
end
end

def convert_to_day_images(dir)
Dir.glob(File.join(File.expand_path(dir), "*.jpeg")).each do |f|

# puts "file: #{f}"

color = `convert #{f} -resize 1x1\! txt:- | tail -1 | cut -f2 -d'#' | cut -f1 -d' '`

timestamp = File.basename(f).gsub("webcam_", "").gsub(".jpeg", "")
date = DateTime.parse(Time.at(timestamp.to_i).to_s)

create_blank_images(date)

image_index = date.hour * 12 + (date.min / 5).to_i
dest_image = File.join("day_to_day", "day-#{date.strftime("%j")}", "#{image_index}.jpg")

`convert #{f} -resize 64x48 #{dest_image}` unless File.exists? dest_image
dest_image = File.join("day_to_day", "day-#{date.strftime("%Y-%j")}", "#{image_index}.jpg")
p f + " - " + dest_image
`convert #{f} -resize 64x48\! #{dest_image}`
end
end

def convert_to_frame
days = Dir.glob(File.join(File.expand_path(dir), "day_to_day/*"))
days = Dir.glob("day_to_day/day-*")
288.times do |image_index|
p "montage #{image_index}"
images = days.map do |dir|
File.join(dir, "#{image_index}.jpg")
end

dest_image = "day_to_day/montage_#{image_index}.jpg"
if image_index < 10
dest_image = "day_to_day/montage_00#{image_index}.jpg"
elsif image_index < 100
dest_image = "day_to_day/montage_0#{image_index}.jpg"
end

`montage #{images.join(" ")} -mode Concatenate -tile x20 -background black #{dest_image}`
end
end

convert_to_day_images "data"
#convert_to_day_images "/Users/alx/lifestream/archives/"
convert_to_frame

0 comments on commit 4f98dc2

Please sign in to comment.