Class: MiddlemanSimpleThumbnailer::Image
- Inherits:
-
Object
- Object
- MiddlemanSimpleThumbnailer::Image
- Defined in:
- lib/middleman-simple-thumbnailer/image.rb
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.
Instance Method Summary collapse
- #base64_data ⇒ Object
- #cached_resized_img_abs_path ⇒ Object
-
#initialize(img_path, resize_to, app, options_hash) ⇒ Image
constructor
A new instance of Image.
- #middleman_abs_path ⇒ Object
- #middleman_resized_abs_path ⇒ Object
- #mime_type ⇒ Object
- #prepare_thumbnail ⇒ Object
- #render ⇒ Object
- #resized_img_abs_path ⇒ Object
- #resized_img_path ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(img_path, resize_to, app, options_hash) ⇒ Image
Returns a new instance of Image.
9 10 11 12 13 14 15 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 9 def initialize(img_path, resize_to, app, ) @img_path = img_path @resize_to = resize_to @middleman_config = app.config @app = app @options = end |
Instance Attribute Details
#img_path ⇒ Object
Returns the value of attribute img_path.
7 8 9 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 7 def img_path @img_path end |
#middleman_config ⇒ Object
Returns the value of attribute middleman_config.
7 8 9 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 7 def middleman_config @middleman_config end |
#resize_to ⇒ Object
Returns the value of attribute resize_to.
7 8 9 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 7 def resize_to @resize_to end |
Instance Method Details
#base64_data ⇒ Object
25 26 27 28 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 25 def base64_data prepare_thumbnail Base64.strict_encode64(File.read(cached_resized_img_abs_path)) end |
#cached_resized_img_abs_path ⇒ Object
60 61 62 63 64 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 60 def cached_resized_img_abs_path File.join(cache_dir, middleman_abs_path).gsub(image_name, resized_image_name).split('.').tap { |a| a.insert(-2, image_checksum) }.join('.') end |
#middleman_abs_path ⇒ Object
56 57 58 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 56 def middleman_abs_path img_path.start_with?('/') ? img_path : File.join(images_dir, img_path) end |
#middleman_resized_abs_path ⇒ Object
52 53 54 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 52 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 |
#prepare_thumbnail ⇒ Object
30 31 32 33 34 35 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 30 def prepare_thumbnail unless cached_thumbnail_available? resize! save_cached_thumbnail end end |
#render ⇒ Object
37 38 39 40 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 37 def render prepare_thumbnail File.read(cached_resized_img_abs_path) end |
#resized_img_abs_path ⇒ Object
48 49 50 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 48 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
43 44 45 46 |
# File 'lib/middleman-simple-thumbnailer/image.rb', line 43 def save! prepare_thumbnail FileUtils.copy_file(cached_resized_img_abs_path, resized_img_abs_path) end |