Class: PictureTag::GeneratedImage

Inherits:
Object
  • Object
show all
Includes:
MiniMagick
Defined in:
lib/jekyll_picture_tag/images/generated_image.rb

Overview

Represents a generated image file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file:, width:, format:, crop: nil, gravity: '') ⇒ GeneratedImage

Returns a new instance of GeneratedImage.



10
11
12
13
14
15
16
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 10

def initialize(source_file:, width:, format:, crop: nil, gravity: '')
  @source = source_file
  @width  = width
  @format = process_format format
  @crop = crop
  @gravity = gravity
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



6
7
8
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 6

def format
  @format
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 6

def width
  @width
end

Instance Method Details

#absolute_filenameObject

/home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



28
29
30
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 28

def absolute_filename
  @absolute_filename ||= File.join(PictureTag.dest_dir, name)
end

#exists?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 18

def exists?
  File.exist?(absolute_filename)
end

#generateObject



22
23
24
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 22

def generate
  generate_image unless @source.missing || exists?
end

#nameObject

/home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


34
35
36
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 34

def name
  @name ||= "#{@source.base_name}-#{@width}-#{id}.#{@format}"
end

#source_heightObject

Post crop



52
53
54
55
56
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 52

def source_height
  update_cache unless cache[:height]

  cache[:height]
end

#source_widthObject

Post crop



45
46
47
48
49
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 45

def source_width
  update_cache unless cache[:width]

  cache[:width]
end

#uriObject

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


40
41
42
# File 'lib/jekyll_picture_tag/images/generated_image.rb', line 40

def uri
  ImgURI.new(name).to_s
end