Module: PhotoCook::Resizing

Included in:
PhotoCook
Defined in:
lib/photo-cook/resizing.rb

Instance Method Summary collapse

Instance Method Details

#build_resize_uri(uri, width, height, options = {}) ⇒ Object Also known as: resize

Builds URI for resizing:

resize('/uploads/car.png', 280, 280, pixel_ratio: 2.5)
  => /resized/uploads/width:280&height:280&crop:0&pixel_ratio:3

NOTE: This method will perform validation



27
28
29
30
31
32
33
# File 'lib/photo-cook/resizing.rb', line 27

def build_resize_uri(uri, width, height, options = {})
  width, height     = parse_and_check_dimensions(width, height)
  pixel_ratio, crop = open_options(options)
                                                  # Explicit     # From cookies                  # Default
  pixel_ratio       = parse_and_check_pixel_ratio(pixel_ratio || PhotoCook.client_pixel_ratio || 1)
  assemble_uri(uri, width, height, unify_pixel_ratio(pixel_ratio), !!crop)
end

#hresize(uri, width, options = {}) ⇒ Object

Shorthand: hresize(‘/uploads/car.png’, 280) <=> resize(‘/uploads/car.png’, 280, nil)



38
39
40
# File 'lib/photo-cook/resizing.rb', line 38

def hresize(uri, width, options = {})
  resize(uri, width, :auto, options)
end

#resize_photo(path, width, height, options = {}) ⇒ Object

Performs photo resizing:

resize_photo('/application/public/uploads/car.png', 280, 280)

NOTE: This method will perform validation



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/photo-cook/resizing.rb', line 8

def resize_photo(path, width, height, options = {})
  started           = Time.now

  width, height     = parse_and_check_dimensions(width, height)
  pixel_ratio, crop = open_options(options)
                                                  # Explicit     # Default
  pixel_ratio       = unify_pixel_ratio(parse_and_check_pixel_ratio(pixel_ratio || 1))
  photo             = Resizer.instance.resize(path, width, height, pixel_ratio, !!crop)

  finished          = Time.now
  log_resize(photo, width, height, pixel_ratio, !!crop, (finished - started) * 1000.0)
  photo
end

#vresize(uri, height, options = {}) ⇒ Object

Shorthand: vresize(‘/uploads/car.png’, 280) <=> resize(‘/uploads/car.png’, nil, 280)



43
44
45
# File 'lib/photo-cook/resizing.rb', line 43

def vresize(uri, height, options = {})
  resize(uri, :auto, height, options)
end