class Paperclip::GeometryDetector

Public Class Methods

new(file) click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 3
def initialize(file)
  @file = file
  raise_if_blank_file
end

Public Instance Methods

make() click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 8
def make
  geometry = GeometryParser.new(geometry_string.strip).make
  geometry || raise(Errors::NotIdentifiedByImageMagickError.new)
end

Private Instance Methods

geometry_string() click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 15
def geometry_string
  begin
    orientation = Paperclip.options[:use_exif_orientation] ?
      "%[exif:orientation]" : "1"
    Paperclip.run(
      "identify",
      "-format '%wx%h,#{orientation}' :file", {
        :file => "#{path}[0]"
      }, {
        :swallow_stderr => true
      }
    )
  rescue Cocaine::ExitStatusError
    ""
  rescue Cocaine::CommandNotFoundError => e
    raise_because_imagemagick_missing
  end
end
path() click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 34
def path
  @file.respond_to?(:path) ? @file.path : @file
end
raise_because_imagemagick_missing() click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 44
def raise_because_imagemagick_missing
  raise Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
raise_if_blank_file() click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 38
def raise_if_blank_file
  if path.blank?
    raise Errors::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")
  end
end