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
-
#crop_gravity ⇒ Vector2d?
Returns the crop gravity, the focal point kept as close to the center as possible when cropping.
-
#crop_gravity? ⇒ Boolean
Returns true if the crop gravity has been set explicitly.
-
#crop_size ⇒ Vector2d?
Returns the crop size, or nil if no cropping is applied.
-
#crop_size? ⇒ Boolean
Returns true if crop size has been set.
-
#crop_start ⇒ Vector2d
Returns the crop start if set, or Vector2d(0, 0) if not.
-
#crop_start? ⇒ Boolean
Returns true if crop start has been set.
-
#cropped? ⇒ Boolean
Returns true if the image is cropped.
-
#real_size ⇒ Vector2d?
Returns the real size of the image, without any cropping applied.
-
#real_size? ⇒ Boolean
Returns true if the real size has been set.
-
#size ⇒ Vector2d?
Returns the cropped size, or the real size if the image isn't cropped.
-
#size? ⇒ Boolean
Returns true if the image has a size.
Instance Method Details
#crop_gravity ⇒ Vector2d?
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.
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.
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_size ⇒ Vector2d?
Returns the crop size, or nil if no cropping is applied.
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.
45 46 47 |
# File 'lib/dynamic_image/model/dimensions.rb', line 45 def crop_size? crop_width? && crop_height? end |
#crop_start ⇒ Vector2d
Returns the crop start if set, or Vector2d(0, 0) if not.
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.
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.
70 71 72 |
# File 'lib/dynamic_image/model/dimensions.rb', line 70 def cropped? crop_size? && real_size? && crop_size != real_size end |
#real_size ⇒ Vector2d?
Returns the real size of the image, without any cropping applied.
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.
84 85 86 |
# File 'lib/dynamic_image/model/dimensions.rb', line 84 def real_size? real_width? && real_height? end |
#size ⇒ Vector2d?
Returns the cropped size, or the real size if the image isn't cropped.
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.
98 99 100 |
# File 'lib/dynamic_image/model/dimensions.rb', line 98 def size? size ? true : false end |