Class: FormatParser::Image

Inherits:
Object
  • Object
show all
Includes:
AttributesJSON
Defined in:
lib/image.rb

Constant Summary collapse

NATURE =
:image

Constants included from AttributesJSON

AttributesJSON::MAXIMUM_JSON_NESTING_WHEN_SANITIZING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributesJSON

_sanitize_json_value, #as_json, #to_json

Constructor Details

#initialize(**attributes) ⇒ Image

Only permits assignments via defined accessors



71
72
73
74
75
# File 'lib/image.rb', line 71

def initialize(**attributes)
  attributes.map { |(k, v)| public_send("#{k}=", v) }
  @display_width_px ||= @width_px
  @display_height_px ||= @height_px
end

Instance Attribute Details

#color_modeObject

Basic information about the color mode



47
48
49
# File 'lib/image.rb', line 47

def color_mode
  @color_mode
end

#content_typeObject

The MIME type of the image file



68
69
70
# File 'lib/image.rb', line 68

def content_type
  @content_type
end

#display_height_pxObject

Image height when displayed and taking into account things like camera orientation tags and non-square pixels/anamorphicity. The dimensions used for display are always computed by squashing, not by stretching.

If the display width/height are not specified, the sizes of the pixel buffer will get returned instead (values of the ‘width_px`/`height_px` attributes)



34
35
36
# File 'lib/image.rb', line 34

def display_height_px
  @display_height_px
end

#display_width_pxObject

Image width when displayed and taking into account things like camera orientation tags and non-square pixels/anamorphicity. The dimensions used for display are always computed by squashing, not by stretching.

If the display width/height are not specified, the sizes of the pixel buffer will get returned instead (values of the ‘width_px`/`height_px` attributes)



25
26
27
# File 'lib/image.rb', line 25

def display_width_px
  @display_width_px
end

#formatObject

What filetype was recognized? Will contain a non-ambiguous symbol referring to the file format. The symbol can be used as a filename extension safely



10
11
12
# File 'lib/image.rb', line 10

def format
  @format
end

#has_multiple_framesObject

Whether the file has multiple frames (relevant for image files and video)



37
38
39
# File 'lib/image.rb', line 37

def has_multiple_frames
  @has_multiple_frames
end

#has_transparencyObject

Whether the image has transparency (or an alpha channel)



44
45
46
# File 'lib/image.rb', line 44

def has_transparency
  @has_transparency
end

#height_pxObject

Number of pixels vertically in the pixel buffer



16
17
18
# File 'lib/image.rb', line 16

def height_px
  @height_px
end

#image_orientationObject

Orientation from EXIF data. Will come through as an integer. To be perfectly honest EXIF orientation handling is a bit of a mess, here’s a reasonable blog post about it: magnushoff.com/jpeg-orientation.html



61
62
63
# File 'lib/image.rb', line 61

def image_orientation
  @image_orientation
end

#intrinsicsObject

If a parser wants to provide any extra information to the caller it can be placed here



65
66
67
# File 'lib/image.rb', line 65

def intrinsics
  @intrinsics
end

#num_animation_or_video_framesObject

If the file has animation or is video, this might indicate the number of frames. Some formats do not allow retrieving this value without parsing the entire file, so for GIF this might be nil even though it is animated. For a boolean check, ‘has_multiple_frames` might offer a better clue.



55
56
57
# File 'lib/image.rb', line 55

def num_animation_or_video_frames
  @num_animation_or_video_frames
end

#orientationObject

The angle by which the camera was rotated when taking the picture (affects display width and height)



41
42
43
# File 'lib/image.rb', line 41

def orientation
  @orientation
end

#width_pxObject

Number of pixels horizontally in the pixel buffer



13
14
15
# File 'lib/image.rb', line 13

def width_px
  @width_px
end

Instance Method Details

#natureObject



77
78
79
# File 'lib/image.rb', line 77

def nature
  NATURE
end