module DynamicImage::Model::Dimensions

DynamicImage Model Dimensions

Public Instance Methods

crop_gravity() click to toggle source

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.

# 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?() click to toggle source

Returns true if crop gravity has been explicitely set.

# File lib/dynamic_image/model/dimensions.rb, line 29
def crop_gravity?
  crop_gravity_x.present? && crop_gravity_y.present?
end
crop_size() click to toggle source

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

# File lib/dynamic_image/model/dimensions.rb, line 34
def crop_size
  vector(crop_width, crop_height) if crop_size?
end
crop_size?() click to toggle source

Returns true if crop size has been set.

# File lib/dynamic_image/model/dimensions.rb, line 39
def crop_size?
  crop_width? && crop_height?
end
crop_start() click to toggle source

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

# 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?() click to toggle source

Returns true if crop start has been set.

# File lib/dynamic_image/model/dimensions.rb, line 53
def crop_start?
  crop_start_x.present? && crop_start_y.present?
end
cropped?() click to toggle source

Returns true if the image is cropped.

# File lib/dynamic_image/model/dimensions.rb, line 58
def cropped?
  crop_size? && real_size? && crop_size != real_size
end
real_size() click to toggle source

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

# File lib/dynamic_image/model/dimensions.rb, line 63
def real_size
  vector(real_width, real_height) if real_size?
end
real_size?() click to toggle source

Returns true if the size has been set.

# File lib/dynamic_image/model/dimensions.rb, line 68
def real_size?
  real_width? && real_height?
end
size() click to toggle source

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

# File lib/dynamic_image/model/dimensions.rb, line 74
def size
  crop_size || real_size
end
size?() click to toggle source

Returns true if the image has size set.

# File lib/dynamic_image/model/dimensions.rb, line 79
def size?
  size ? true : false
end

Private Instance Methods

vector(width, height) click to toggle source
# File lib/dynamic_image/model/dimensions.rb, line 85
def vector(width, height)
  Vector2d.new(width, height)
end