Created
October 4, 2013 12:52
-
-
Save zuf/6825447 to your computer and use it in GitHub Desktop.
Helps to create start trails from series of photos. It uses ImageMagick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'tmpdir' | |
@compose_method = 'LightenIntensity' | |
@processes_count = 4 | |
@intermediate_image_format = "tga" | |
class Numeric | |
def duration | |
secs = self.to_int | |
mins = secs / 60 | |
hours = mins / 60 | |
days = hours / 24 | |
if days > 0 | |
"#{days} days and #{hours % 24} hours" | |
elsif hours > 0 | |
"#{hours} hours and #{mins % 60} minutes" | |
elsif mins > 0 | |
"#{mins} minutes and #{secs % 60} seconds" | |
elsif secs >= 0 | |
"#{secs} seconds" | |
end | |
end | |
end | |
@start_time = Time.now | |
input_files=Dir.glob('*.jpg').sort.uniq | |
input_files_size = input_files.size | |
Dir.mktmpdir('startrails-tmp') do |tmp_dir| | |
@processes_count.times do |n| | |
`convert #{input_files[0]} -fill black -draw 'rectangle 0,0 8000,8000' #{tmp_dir}/out#{n}.#{@intermediate_image_format}` | |
end | |
puts | |
remain_str = '' | |
prev_string_size = 0 | |
s=0 | |
threads=[] | |
input_files.each_slice(@processes_count) do |files| | |
files.each_with_index do |file, n| | |
threads[n] = Thread.new{`convert #{tmp_dir}/out#{n}.#{@intermediate_image_format} #{file} -compose #{@compose_method} -composite #{tmp_dir}/out#{n}.#{@intermediate_image_format}`} | |
end | |
files.each_with_index do |file, n| | |
threads[n].join | |
end | |
s+=files.size | |
if s > 0 | |
elapsed_time = (Time.now - @start_time).to_f | |
time_per_one_file = elapsed_time / s.to_f | |
remain_files = input_files.size - s | |
remain_time = remain_files*time_per_one_file | |
end | |
remain_str = "| #{remain_time.round.duration} remains" if remain_time > 0 && s > @processes_count | |
print "\r#{' '*prev_string_size}" # clear prev status string in terminal | |
out_str = "\r#{(100.0*s.to_f/input_files_size).round(2)}% (#{s}/#{input_files_size}) #{remain_str}" # status string | |
print out_str | |
prev_string_size = out_str.length | |
end | |
puts | |
puts "Writing final output file..." | |
`convert #{input_files[0]} -fill black -draw 'rectangle 0,0 8000,8000' #{tmp_dir}/out.#{@intermediate_image_format}` | |
@processes_count.times do |n| | |
`convert #{tmp_dir}/out.#{@intermediate_image_format} #{tmp_dir}/out#{n}.#{@intermediate_image_format} -compose #{@compose_method} -composite #{tmp_dir}/out.#{@intermediate_image_format}` | |
end | |
`convert #{tmp_dir}/out.#{@intermediate_image_format} startrails_#{Time.now.strftime("%Y-%m-%d_%H-%M")}.png` | |
end | |
puts "Done" | |
duration = Time.now - @start_time | |
puts "Duration: #{duration.duration} (#{duration.to_f.round(2)}s)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment