Module: DynamicImage::Model::Dimensions

Included in:
DynamicImage::Model
Defined in:
lib/dynamic_image/model/dimensions.rb

Overview

DynamicImage Model Dimensions

Vector accessors over the real_* and crop_* columns.

real_size is the size of the stored image. size is the size after cropping, or real_size when no crop is set.

Instance Method Summary collapse

Instance Method Details

#crop_gravityVector2d?

Returns the crop gravity, the focal point kept as close to the center as possible when cropping.

The coordinates are relative to 0,0 on the original image. Unless set explicitly, the gravity is the center of the cropped image.

Returns:

  • (Vector2d, nil)


18
19
20
21
22
23
24
25
26
# File 'lib/dynamic_image/model/dimensions.rb', line 18

def crop_gravity
  if crop_gravity?
    vector(crop_gravity_x, crop_gravity_y)
  elsif cropped?
    crop_start + (crop_size / 2)
  elsif size?
    size / 2
  end
end

#crop_gravity?Boolean

Returns true if the crop gravity has been set explicitly.

Returns:

  • (Boolean)


31
32
33
# File 'lib/dynamic_image/model/dimensions.rb', line 31

def crop_gravity?
  crop_gravity_x.present? && crop_gravity_y.present?
end

#crop_sizeVector2d?

Returns the crop size, or nil if no cropping is applied.

Returns:

  • (Vector2d, nil)


38
39
40
# File 'lib/dynamic_image/model/dimensions.rb', line 38

def crop_size
  vector(crop_width, crop_height) if crop_size?
end

#crop_size?Boolean

Returns true if crop size has been set.

Returns:

  • (Boolean)


45
46
47
# File 'lib/dynamic_image/model/dimensions.rb', line 45

def crop_size?
  crop_width? && crop_height?
end

#crop_startVector2d

Returns the crop start if set, or Vector2d(0, 0) if not.

Returns:

  • (Vector2d)

    the top left corner of the crop



52
53
54
55
56
57
58
# File 'lib/dynamic_image/model/dimensions.rb', line 52

def crop_start
  if crop_start?
    vector(crop_start_x, crop_start_y)
  else
    vector(0, 0)
  end
end

#crop_start?Boolean

Returns true if crop start has been set.

Returns:

  • (Boolean)


63
64
65
# File 'lib/dynamic_image/model/dimensions.rb', line 63

def crop_start?
  crop_start_x.present? && crop_start_y.present?
end

#cropped?Boolean

Returns true if the image is cropped.

Returns:

  • (Boolean)


70
71
72
# File 'lib/dynamic_image/model/dimensions.rb', line 70

def cropped?
  crop_size? && real_size? && crop_size != real_size
end

#real_sizeVector2d?

Returns the real size of the image, without any cropping applied.

Returns:

  • (Vector2d, nil)

    the size of the stored image



77
78
79
# File 'lib/dynamic_image/model/dimensions.rb', line 77

def real_size
  vector(real_width, real_height) if real_size?
end

#real_size?Boolean

Returns true if the real size has been set.

Returns:

  • (Boolean)


84
85
86
# File 'lib/dynamic_image/model/dimensions.rb', line 84

def real_size?
  real_width? && real_height?
end

#sizeVector2d?

Returns the cropped size, or the real size if the image isn't cropped.

Returns:

  • (Vector2d, nil)

    the visible size of the image



91
92
93
# File 'lib/dynamic_image/model/dimensions.rb', line 91

def size
  crop_size || real_size
end

#size?Boolean

Returns true if the image has a size.

Returns:

  • (Boolean)


98
99
100
# File 'lib/dynamic_image/model/dimensions.rb', line 98

def size?
  size ? true : false
end