def call(app, opts={})
app.env[:convert_command] = opts[:convert_command] || 'convert'
app.env[:identify_command] = opts[:identify_command] || 'identify'
app.add_analyser :image_properties, ImageMagick::Analysers::ImageProperties.new
app.add_analyser :width do |content|
content.analyse(:image_properties)['width']
end
app.add_analyser :height do |content|
content.analyse(:image_properties)['height']
end
app.add_analyser :format do |content|
content.analyse(:image_properties)['format']
end
app.add_analyser :aspect_ratio do |content|
attrs = content.analyse(:image_properties)
attrs['width'].to_f / attrs['height']
end
app.add_analyser :portrait do |content|
attrs = content.analyse(:image_properties)
attrs['width'] <= attrs['height']
end
app.add_analyser :landscape do |content|
!content.analyse(:portrait)
end
app.add_analyser :image do |content|
begin
content.analyse(:image_properties)['format'] != 'pdf'
rescue Shell::CommandFailed
false
end
end
app.define(:portrait?) { portrait }
app.define(:landscape?) { landscape }
app.define(:image?) { image }
app.add_generator :convert, ImageMagick::Generators::Convert.new
app.add_generator :plain, ImageMagick::Generators::Plain.new
app.add_generator :plasma, ImageMagick::Generators::Plasma.new
app.add_generator :text, ImageMagick::Generators::Text.new
app.add_processor :convert, Processors::Convert.new
app.add_processor :encode, Processors::Encode.new
app.add_processor :thumb, Processors::Thumb.new
app.add_processor :rotate do |content, amount|
content.process!(:convert, "-rotate #{amount}")
end
app.define :identify do |cli_args=nil|
shell_eval do |path|
"#{app.env[:identify_command]} #{cli_args} #{path}"
end
end
end