Class: MiddlemanSimpleThumbnailer::Image
- Inherits:
-
Object
- Object
- MiddlemanSimpleThumbnailer::Image
- Defined in:
- lib/middleman-simple-thumbnailer/image.rb
Constant Summary collapse
- @@options =
nil
Instance Attribute Summary collapse
-
#img_path ⇒ Object
Returns the value of attribute img_path.
-
#middleman_config ⇒ Object
Returns the value of attribute middleman_config.
-
#resize_to ⇒ Object
Returns the value of attribute resize_to.
Class Method Summary collapse
Instance Method Summary collapse
- #base64_data ⇒ Object
-
#initialize(img_path, resize_to, app) ⇒ Image
constructor
A new instance of Image.
- #middleman_abs_path ⇒ Object
- #middleman_resized_abs_path ⇒ Object
- #mime_type ⇒ Object
- #resized_img_abs_path ⇒ Object
- #resized_img_path ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(img_path, resize_to, app) ⇒ Image
Returns a new instance of Image.
10 11 12 13 14 15 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 10 def initialize(img_path, resize_to, app) @img_path = img_path @resize_to = resize_to @middleman_config = app.config @app = app end |
Instance Attribute Details
#img_path ⇒ Object
Returns the value of attribute img_path.
8 9 10 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 8 def img_path @img_path end |
#middleman_config ⇒ Object
Returns the value of attribute middleman_config.
8 9 10 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 8 def middleman_config @middleman_config end |
#resize_to ⇒ Object
Returns the value of attribute resize_to.
8 9 10 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 8 def resize_to @resize_to end |
Class Method Details
.options=(options) ⇒ Object
42 43 44 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 42 def self.=() = end |
Instance Method Details
#base64_data ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 25 def base64_data unless cached_thumbnail_available? resize! save_cached_thumbnail end Base64.strict_encode64(File.read(cached_resized_img_abs_path)) end |
#middleman_abs_path ⇒ Object
54 55 56 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 54 def middleman_abs_path img_path.start_with?('/') ? img_path : File.join(images_dir, img_path) end |
#middleman_resized_abs_path ⇒ Object
50 51 52 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 50 def middleman_resized_abs_path middleman_abs_path.gsub(image_name, resized_image_name) end |
#mime_type ⇒ Object
17 18 19 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 17 def mime_type image.mime_type end |
#resized_img_abs_path ⇒ Object
46 47 48 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 46 def resized_img_abs_path File.join(build_dir, middleman_abs_path).gsub(image_name, resized_image_name) end |
#resized_img_path ⇒ Object
21 22 23 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 21 def resized_img_path img_path.gsub(image_name, resized_image_name) end |
#save! ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 33 def save! unless cached_thumbnail_available? resize! save_cached_thumbnail end FileUtils.copy_file(cached_resized_img_abs_path, resized_img_abs_path) end |