Module: DynamicImage::Model::Dimensions

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

Overview

DynamicImage Model Dimensions

Instance Method Summary collapse

Instance Method Details

#crop_gravityObject

Returns the crop gravity.

DynamicImage will try to keep the pixel represented by crop_gravity as close to the center as possible when cropping images.

It is relative to 0,0 on the original image.

Unless crop_gravity has been explicitely set, it defaults to 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 crop gravity has been explicitely set.


29
30
31
# File 'lib/dynamic_image/model/dimensions.rb', line 29

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

#crop_sizeObject

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


34
35
36
# File 'lib/dynamic_image/model/dimensions.rb', line 34

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

#crop_size?Boolean

Returns true if crop size has been set.


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

def crop_size?
  crop_width? && crop_height?
end

#crop_startObject

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


44
45
46
47
48
49
50
# File 'lib/dynamic_image/model/dimensions.rb', line 44

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.


53
54
55
# File 'lib/dynamic_image/model/dimensions.rb', line 53

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

#cropped?Boolean

Returns true if the image is cropped.


58
59
60
# File 'lib/dynamic_image/model/dimensions.rb', line 58

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

#real_sizeObject

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


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

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

#real_size?Boolean

Returns true if the size has been set.


68
69
70
# File 'lib/dynamic_image/model/dimensions.rb', line 68

def real_size?
  real_width? && real_height?
end

#sizeObject

Returns the cropped size if the image has been cropped. If not, it returns the actual size.


74
75
76
# File 'lib/dynamic_image/model/dimensions.rb', line 74

def size
  crop_size || real_size
end

#size?Boolean

Returns true if the image has size set.


79
80
81
# File 'lib/dynamic_image/model/dimensions.rb', line 79

def size?
  size ? true : false
end