Module: PhotoCook::Resizing
- Included in:
- PhotoCook
- Defined in:
- lib/photo-cook/resizing.rb
Instance Method Summary collapse
-
#build_resize_uri(uri, width, height, options = {}) ⇒ Object
(also: #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.
-
#hresize(uri, width, options = {}) ⇒ Object
Shorthand: hresize(‘/uploads/car.png’, 280) <=> resize(‘/uploads/car.png’, 280, nil).
-
#resize_photo(path, width, height, options = {}) ⇒ Object
Performs photo resizing: resize_photo(‘/application/public/uploads/car.png’, 280, 280).
-
#vresize(uri, height, options = {}) ⇒ Object
Shorthand: vresize(‘/uploads/car.png’, 280) <=> resize(‘/uploads/car.png’, nil, 280).
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, = {}) width, height = parse_and_check_dimensions(width, height) pixel_ratio, crop = () # 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, = {}) resize(uri, width, :auto, ) 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, = {}) started = Time.now width, height = parse_and_check_dimensions(width, height) pixel_ratio, crop = () # 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, = {}) resize(uri, :auto, height, ) end |