Module: CarrierwaveDimensions::Processor::InstanceMethods

Defined in:
lib/carrierwave_dimensions/processor.rb

Instance Method Summary collapse

Instance Method Details

#store_dimensions(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/carrierwave_dimensions/processor.rb', line 17

def store_dimensions(*args)
	options = args.inject({}) do |result,arr|
		result.merge(arr[0] => arr[1])
	end

	width_column = options[:width_column] ||
		(options[:columns] && "#{options[:columns]}_width") ||
		"#{mounted_as}_#{version_name || "default"}_width"
	height_column = options[:height_column] ||
	  (options[:columns] && "#{options[:columns]}_height") ||
	  "#{mounted_as}_#{version_name || "default"}_height"

	if model
		width, height = `identify -format "%wx%h" #{file.path}`.split(/x/)
		model.send("#{width_column}=", width.strip.to_i)
		model.send("#{height_column}=", height.strip.to_i)
	end
end