class PhotoHelper::Generate

Public Instance Methods

jpeg(folder = nil) click to toggle source
# File lib/photo-helper/generate.rb, line 15
def jpeg(folder = nil)
  folder ||= options[:folder]
  puts folder

  search_path = File.expand_path(folder)
  jpeg_path = File.join(search_path, 'jpegs')

  Dir.mkdir(jpeg_path) unless File.exist?(jpeg_path)

  files = Dir["#{search_path}/*.{#{RAW_EXTENSIONS.join(',')}}"]

  files.each do |file|
    jpeg_file_name = "#{File.basename(file.to_s, ".*")}.#{JPEG_EXTENSION}"
    next if File.exist? File.join(search_path, jpeg_file_name)
    next if File.exist? "./jpegs/#{jpeg_file_name}"
    puts file

    `sips -s format jpeg #{file} -s dpiHeight #{options[:dpi]} -s dpiWidth #{options[:dpi]} --out "./jpegs/#{jpeg_file_name}"`
  end
end