Module: Miniatura
- Defined in:
- lib/miniatura.rb,
lib/miniatura/logger.rb,
lib/miniatura/options.rb,
lib/miniatura/version.rb,
lib/miniatura/generate_command.rb
Defined Under Namespace
Classes: GenerateCommand, Logger, Options
Constant Summary collapse
- VERSION =
'0.3.4'
Instance Method Summary collapse
Instance Method Details
#generate_thumb(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/miniatura.rb', line 8 def generate_thumb( = {}) [:file_extension] ||= 'jpeg' [:logger] = Rails.logger size = [:size] [:rotate] = 0 video = MiniExiftool.new(current_path) orientation = video.rotation image_width, image_height = video_dimension(orientation, video.imagewidth, video.imageheight, size) [:size] = "#{image_width.to_i}" + "x" + "#{image_height.to_i}" tmp_path = File.join(File.dirname(current_path), "tmpfile.#{options[:file_extension]}") thumbnail = GenerateCommand.new(current_path, tmp_path) cmd = thumbnail.generate_command() logger = Miniatura::Logger.new().logger logger.info("Running command: #{cmd}") exit_code, error = nil raise Errno::ENOENT unless File.exist?(current_path) Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| error = stderr.read exit_code = wait_thr.value end handle_exit_code(exit_code, error, logger) File.rename tmp_path, current_path end |