Class: MiddlemanSimpleThumbnailer::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-simple-thumbnailer/image.rb

Constant Summary collapse

@@options =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_pathObject

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_configObject

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_toObject

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.options=(options)
  @@options = options
end

Instance Method Details

#base64_dataObject



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_pathObject



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_pathObject



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_typeObject



17
18
19
# File 'lib/middleman-simple-thumbnailer/image.rb', line 17

def mime_type
  image.mime_type
end

#resized_img_abs_pathObject



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_pathObject



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