Class: Jekyll::Images::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/images/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, filename) ⇒ Image

Returns a new instance of Image.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jekyll/images/image.rb', line 10

def initialize(site, filename)
  unless File.exist? filename
    raise ArgumentError, "File not found: #{filename}"
  end

  @cached_thumbnails = {}
  @site = site
  @filename = filename

  # We only need the image to get height and width
  image = Vips::Image.new_from_file filename, access: :sequential

  @height = image.height
  @width = image.width
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/jekyll/images/image.rb', line 8

def filename
  @filename
end

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/jekyll/images/image.rb', line 8

def height
  @height
end

#siteObject (readonly)

Returns the value of attribute site.



8
9
10
# File 'lib/jekyll/images/image.rb', line 8

def site
  @site
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/jekyll/images/image.rb', line 8

def width
  @width
end

Instance Method Details

#thumbnail(**args) ⇒ Object



26
27
28
# File 'lib/jekyll/images/image.rb', line 26

def thumbnail(**args)
  @cached_thumbnails[args.hash.to_s] ||= Thumbnail.new site: site, filename: filename, image: self, **args
end