@@ -9,11 +9,13 @@ class Transcoder < Processor
99 # set, the options will be appended to the convert command upon video transcoding.
1010 def initialize file , options = { } , attachment = nil
1111 log "Options: #{ options . to_s } "
12+ log "Attachment: #{ attachment . inspect } "
1213
1314 @file = file
1415 @current_format = File . extname ( @file . path )
1516 @basename = File . basename ( @file . path , @current_format )
1617 @cli = ::Av . cli
18+ @style = options [ :style ] || 'default'
1719 @meta = ::Av . cli . identify ( @file . path )
1820 @whiny = options [ :whiny ] . nil? ? true : options [ :whiny ]
1921
@@ -42,9 +44,15 @@ def initialize file, options = {}, attachment = nil
4244
4345 @convert_options [ :output ] [ :s ] = format_geometry ( @geometry ) if @geometry . present?
4446
45- json_meta = JSON . dump ( @meta )
46- log "JSON metadata: #{ json_meta } "
47- attachment . instance_write ( :meta , json_meta ) if attachment
47+ # todo: maybe clean this up? attachment model can handle the read/write
48+ # of metadata.
49+ if attachment
50+ attachment_meta = attachment . meta || { }
51+ attachment_meta [ @style . to_sym ] = @meta
52+ json_meta = JSON . dump ( attachment_meta )
53+ log "JSON metadata: #{ json_meta } "
54+ attachment . instance_write ( :meta , json_meta )
55+ end
4856 end
4957
5058 # Performs the transcoding of the +file+ into a thumbnail/video. Returns the Tempfile
@@ -100,6 +108,9 @@ def make
100108
101109 exif_data = MiniExiftool . new ( dst . path )
102110 log "Exif data: #{ exif_data . inspect } "
111+ @meta [ :output ] ||= { }
112+ @meta [ :output ] [ :width ] = exif_data . width
113+ @meta [ :output ] [ :height ] = exif_data . height
103114 rescue Cocaine ::ExitStatusError => e
104115 raise Paperclip ::Error , "error while transcoding #{ @basename } : #{ e } " if @whiny
105116 end
0 commit comments