Module: DynamicImage::Model::Transformations

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

Overview

DynamicImage Model Transformations

Instance Method Summary collapse

Instance Method Details

#resize(max_size) ⇒ Object

Resizes the image


9
10
11
12
13
14
15
16
17
18
# File 'lib/dynamic_image/model/transformations.rb', line 9

def resize(max_size)
  transform_image do |image|
    new_size = real_size.constrain_both(max_size)
    scale = new_size.x / real_size.x
    image.resize(new_size)
    crop_attributes.each do |attr|
      self[attr] = self[attr] * scale if self[attr]
    end
  end
end

#rotate(degrees = 90) ⇒ Object

Rotates the image


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dynamic_image/model/transformations.rb', line 21

def rotate(degrees = 90)
  degrees = degrees.to_i % 360

  return self if degrees.zero?

  if (degrees % 90).nonzero?
    raise DynamicImage::Errors::InvalidTransformation,
          "angle must be a multiple of 90 degrees"
  end

  transform_image do |image|
    image.rotate(degrees)
    rotate_dimensions(real_size.x, real_size.y, degrees)
  end
end