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.0"
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/miniatura.rb', line 8 def generate_thumb = {} [:file_extension] ||= 'jpeg' [:logger] = Rails.logger size = [:size] video = MiniExiftool.new(current_path) orientation = video.rotation case orientation when 0 [:rotate] = 0 when 90 [:rotate] = 90 when 180 [:rotate] = 180 when 270 [:rotate] = 270 end video_width, video_height = video.imagewidth, video.imageheight case orientation when 0,180 image_width = size ratio = size.to_f/video_width image_height = video_height * ratio else image_width = size ratio = size.to_f/video_height image_height = video_width * ratio end [: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 |