Class: DragonflyLibvips::Analysers::ImageProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_libvips/analysers/image_properties.rb

Constant Summary collapse

DPI =
300

Instance Method Summary collapse

Instance Method Details

#call(content) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dragonfly_libvips/analysers/image_properties.rb', line 10

def call(content)
  return {} unless content.ext
  return {} unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  input_options = {}
  input_options["access"] = "sequential"
  input_options["autorotate"] = true if content.mime_type == "image/jpeg"
  input_options["dpi"] = DPI if content.mime_type == "application/pdf"

  img = ::Vips::Image.new_from_file(content.path, **DragonflyLibvips.symbolize_keys(input_options))

  width = img.width
  height = img.height
  xres = img.xres
  yres = img.yres

  {
    "format" => content.ext.to_s,
    "width" => width,
    "height" => height,
    "xres" => xres,
    "yres" => yres,
    "progressive" => (content.mime_type == "image/jpeg" && img.get("jpeg-multiscan") != 0)
  }
end