Class: PictureTag::SourceImage
- Inherits:
-
Object
- Object
- PictureTag::SourceImage
- Defined in:
- lib/jekyll_picture_tag/images/source_image.rb
Overview
Handles a given source image file and its properties. Provides a speed advantage by storing expensive file reads and writes in instance variables, to be reused by many different generated images.
Instance Attribute Summary collapse
-
#media_preset ⇒ Object
readonly
Returns the value of attribute media_preset.
-
#missing ⇒ Object
readonly
Returns the value of attribute missing.
-
#shortname ⇒ Object
readonly
Returns the value of attribute shortname.
Instance Method Summary collapse
-
#base_name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^.
- #crop ⇒ Object
- #crop? ⇒ Boolean
- #cropped_aspect ⇒ Object
- #digest ⇒ Object
- #dimensions ⇒ Object
-
#ext ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^.
- #height ⇒ Object
-
#initialize(relative_filename, media_preset = nil) ⇒ SourceImage
constructor
include MiniMagick.
- #keep ⇒ Object
-
#name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.
- #width ⇒ Object
Constructor Details
#initialize(relative_filename, media_preset = nil) ⇒ SourceImage
include MiniMagick
10 11 12 13 14 15 16 17 18 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 10 def initialize(relative_filename, media_preset = nil) # /home/dave/my_blog/assets/images/somefolder/myimage.jpg # ^^^^^^^^^^^^^^^^^^^^^^ @shortname = relative_filename @media_preset = media_preset @missing = missing? check_cache end |
Instance Attribute Details
#media_preset ⇒ Object (readonly)
Returns the value of attribute media_preset.
6 7 8 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6 def media_preset @media_preset end |
#missing ⇒ Object (readonly)
Returns the value of attribute missing.
6 7 8 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6 def missing @missing end |
#shortname ⇒ Object (readonly)
Returns the value of attribute shortname.
6 7 8 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 6 def shortname @shortname end |
Instance Method Details
#base_name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^
66 67 68 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 66 def base_name @shortname.delete_suffix File.extname(@shortname) end |
#crop ⇒ Object
24 25 26 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 24 def crop PictureTag.crop(media_preset) end |
#crop? ⇒ Boolean
28 29 30 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 28 def crop? !crop.nil? end |
#cropped_aspect ⇒ Object
52 53 54 55 56 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 52 def cropped_aspect return Utils.aspect_float(raw_width, raw_height) unless crop? Utils.aspect_float(*crop.split(':').map(&:to_f)) end |
#digest ⇒ Object
20 21 22 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 20 def digest @digest ||= cache[:digest] || '' end |
#dimensions ⇒ Object
36 37 38 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 36 def dimensions [width, height] end |
#ext ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^
72 73 74 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 72 def ext @ext ||= File.extname(name)[1..].downcase end |
#height ⇒ Object
46 47 48 49 50 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 46 def height return raw_height unless crop? [raw_height, (raw_width / cropped_aspect)].min.round end |
#keep ⇒ Object
32 33 34 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 32 def keep PictureTag.keep(media_preset) end |
#name ⇒ Object
/home/dave/my_blog/assets/images/somefolder/myimage.jpg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60 61 62 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 60 def name @name ||= File.join(PictureTag.source_dir, @shortname) end |
#width ⇒ Object
40 41 42 43 44 |
# File 'lib/jekyll_picture_tag/images/source_image.rb', line 40 def width return raw_width unless crop? [raw_width, (raw_height * cropped_aspect)].min.round end |