Class: Paperclip::GMagick
- Inherits:
-
Object
- Object
- Paperclip::GMagick
- Defined in:
- lib/paperclip_processors/gmagick.rb
Instance Attribute Summary collapse
-
#convert_options ⇒ Object
Returns the value of attribute convert_options.
-
#source_file_options ⇒ Object
Returns the value of attribute source_file_options.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(arguments = "", local_options = {}) ⇒ Object
-
#convert_options? ⇒ Boolean
Returns true if the image is meant to make use of additional convert options.
- #crop? ⇒ Boolean
- #identify(arguments = "", local_options = {}) ⇒ Object
-
#initialize(file, options = {}, attachment = nil) ⇒ GMagick
constructor
A new instance of GMagick.
- #make ⇒ Object
-
#transformation_command ⇒ Object
Returns the command ImageMagick’s
convertneeds to transform the image into the thumbnail. - #transformation_to(geometry) ⇒ Object
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ GMagick
Returns a new instance of GMagick.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/paperclip_processors/gmagick.rb', line 6 def initialize(file, = {}, = nil) @geometry = [:geometry] @file = file @format = [:format] @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) @target_geometry = ([:string_geometry_parser] || Geometry).parse(@geometry) @current_geometry = ([:file_geometry_parser] || Geometry).from_file(@file) end |
Instance Attribute Details
#convert_options ⇒ Object
Returns the value of attribute convert_options.
4 5 6 |
# File 'lib/paperclip_processors/gmagick.rb', line 4 def @convert_options end |
#source_file_options ⇒ Object
Returns the value of attribute source_file_options.
4 5 6 |
# File 'lib/paperclip_processors/gmagick.rb', line 4 def @source_file_options end |
Class Method Details
.make(file, options = {}, attachment = nil) ⇒ Object
17 18 19 |
# File 'lib/paperclip_processors/gmagick.rb', line 17 def self.make(file, = {}, = nil) new(file, , ).make end |
Instance Method Details
#convert(arguments = "", local_options = {}) ⇒ Object
45 46 47 |
# File 'lib/paperclip_processors/gmagick.rb', line 45 def convert(arguments = "", = {}) Paperclip.run('gm convert', arguments, ) end |
#convert_options? ⇒ Boolean
Returns true if the image is meant to make use of additional convert options.
73 74 75 |
# File 'lib/paperclip_processors/gmagick.rb', line 73 def !@convert_options.nil? && !@convert_options.empty? end |
#crop? ⇒ Boolean
64 65 66 |
# File 'lib/paperclip_processors/gmagick.rb', line 64 def crop? @crop end |
#identify(arguments = "", local_options = {}) ⇒ Object
49 50 51 |
# File 'lib/paperclip_processors/gmagick.rb', line 49 def identify(arguments = "", = {}) Paperclip.run('gm identify', arguments, ) end |
#make ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/paperclip_processors/gmagick.rb', line 21 def make src = @file dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) begin parameters = [] parameters << parameters << ":source" parameters << transformation_command parameters << parameters << ":dest" parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") success = convert(parameters, :source => "#{File.(src.path)}#{'[0]'}", :dest => File.(dst.path)) rescue Cocaine::ExitStatusError => e raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny rescue Cocaine::CommandNotFoundError => e raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `gm convert` command. Please install GraphicsMagick.") end dst end |
#transformation_command ⇒ Object
Returns the command ImageMagick’s convert needs to transform the image into the thumbnail.
55 56 57 58 59 60 61 62 |
# File 'lib/paperclip_processors/gmagick.rb', line 55 def transformation_command scale = transformation_to(@geometry) trans = [] #trans << "-auto-orient" if auto_orient trans << "-resize" << %["#{scale}"] unless scale.nil? || scale.empty? #trans << "-crop" << %["#{crop}"] << "+repage" if crop trans end |
#transformation_to(geometry) ⇒ Object
68 69 70 |
# File 'lib/paperclip_processors/gmagick.rb', line 68 def transformation_to(geometry) geometry.gsub("#","") end |