Skip to content

Commit

Permalink
add configuration in day_to_day
Browse files Browse the repository at this point in the history
  • Loading branch information
alx committed Nov 26, 2011
1 parent 4f98dc2 commit f82a23d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -22,10 +22,23 @@ Run:

## Day to Day

Configure the script:

```
# Size of the mosaic to be generated in montage
tile_size = 20
# Source of webcam images
lifestream_archive = "/Users/alx/lifestream/archives/"
# Geometry of resized webcam images
geometry = "64x48"
```

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
mpeg -r 10 -b 1800 -i day_to_day/montage_%03d.jpg test1800.mp4
34 changes: 25 additions & 9 deletions day_to_day.rb
Expand Up @@ -2,34 +2,47 @@
require "date"
require "fileutils"

def create_blank_images(date)
## CONFIG

# Size of the mosaic to be generated in montage
tile_size = 20

# Source of webcam images
lifestream_archive = "/Users/alx/lifestream/archives/"

# Geometry of resized webcam images
geometry = "64x48"

## END CONFIG

def create_blank_images(date, geometry)
color = "dark" # or white
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 #{geometry}\! #{f}` unless File.exists? f
end
end
end

def convert_to_day_images(dir)
def convert_to_day_images(dir, geometry)
Dir.glob(File.join(File.expand_path(dir), "*.jpeg")).each do |f|
timestamp = File.basename(f).gsub("webcam_", "").gsub(".jpeg", "")
date = DateTime.parse(Time.at(timestamp.to_i).to_s)

create_blank_images(date)
create_blank_images date, geometry

image_index = date.hour * 12 + (date.min / 5).to_i
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}`
`convert #{f} -resize #{geometry}\! #{dest_image}`
end
end

def convert_to_frame
def convert_to_frame(tile_size)
days = Dir.glob("day_to_day/day-*")
288.times do |image_index|
p "montage #{image_index}"
Expand All @@ -44,9 +57,12 @@ def convert_to_frame
dest_image = "day_to_day/montage_0#{image_index}.jpg"
end

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

#convert_to_day_images "/Users/alx/lifestream/archives/"
convert_to_frame
# Create resized images for each day
convert_to_day_images lifestream_archive, geometry

# Create frames for movie with 20x20 mosaic
convert_to_frame tile_size

0 comments on commit f82a23d

Please sign in to comment.