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
  orientation = Paperclip.options[:use_exif_orientation] ?
    "%[exif:orientation]" : "1"
  Paperclip.run(
    Paperclip.options[:is_windows] ? "magick identify" : "identify",
    "-format '%wx%h,#{orientation}' :file", {
      file: "#{path}[0]"
    },
    swallow_stderr: true
  )
rescue Terrapin::ExitStatusError
  ""
rescue Terrapin::CommandNotFoundError => e
  raise_because_imagemagick_missing
end
path() click to toggle source
# File lib/paperclip/geometry_detector_factory.rb, line 31
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 41
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 35
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