Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more fixes to make it work on the Raspi again #7

Merged
merged 11 commits into from
Jun 29, 2018
Merged
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ gem 'angular_rails_csrf'
gem 'haml'

source 'https://rails-assets.org' do
gem 'rails-assets-angular'
gem 'rails-assets-angular-route'
gem 'rails-assets-lazysizes'
gem 'rails-assets-angular', '1.4.5'
gem 'rails-assets-angular-route', '1.4.5'
gem 'rails-assets-lazysizes', '4.0.4'
end

gem 'uglifier', '>= 1.3.0'
Expand Down
2 changes: 1 addition & 1 deletion config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
worker_processes 3
timeout 60
preload_app true
listen '0.0.0.0:3000', tcp_nopush: true
listen '0.0.0.0', tcp_nopush: true
60 changes: 60 additions & 0 deletions lib/tasks/picture_set.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'fileutils'

namespace :picture_set do
COMBINED_SUFFIX = '_combined.jpg'.freeze

desc "Combine all images into one"
task :combine_images, [:path] => [:environment] do |task, args|
path = args[:path]
path = File.join(Rails.root, 'public', 'picture_sets') if path.blank?
puts "Using directory #{path}."
Dir.chdir(path) do
picture_sets = Dir.glob('*').select {|f| File.directory? f}
picture_sets.each do |date|
puts "Processing #{date}..."
combine_images(date, path)
end
end
end

desc "Remove combined images. Necessary before running combine_images task again."
task :clean_combine_images, [:path] => [:environment] do |task, args|
path = args[:path]
path = File.join(Rails.root, 'public', 'picture_sets') if path.blank?
puts "Using directory #{path}."
Dir.chdir(path) do
picture_sets = Dir.glob('*').select {|f| File.directory? f}
picture_sets.each do |date|
Dir.chdir(File.join(path, date)) do
FileUtils.rm("#{date}#{COMBINED_SUFFIX}", force: true)
end
end
end
end

desc "Copies all images into one directory (without the single polaroids)"
task :copy, [:path, :output] => [:environment] do |task, args|
path = args[:path]
path = File.join(Rails.root, 'public', 'picture_sets') if path.blank?
puts "Using directory #{path}."
Dir.chdir(path) do
picture_sets = Dir.glob('*').select {|f| File.directory?(f) && f != 'all'}
picture_sets.each do |date|
Syscall.execute("cp #{File.join(path, date, "*.jpg")} #{args[:output]}")
Syscall.execute("cp #{File.join(path, date, "*.gif")} #{args[:output]}")
rescue => e
puts e
end
end

def combine_images(date, path)
dir = File.join(path, date)
begin
Syscall.execute("time montage -geometry '25%x25%+25+25<' -background '#{OPTS.background_color}' " \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better only do it when #{date}#{COMBINED_SUFFIX} does not exist yet.

"-title '#{OPTS.image_caption}' -font '#{OPTS.font}' -fill '#{OPTS.font_color}' " \
"-pointsize #{OPTS.combined_image_fontsize} -gravity 'Center' #{date}_*.jpg #{date}#{COMBINED_SUFFIX}",
dir: dir)
rescue => e
puts "Can not process #{dir}: #{e}"
end
end