Class: DynamicImageElements::ImageElement
- Inherits:
-
Object
- Object
- DynamicImageElements::ImageElement
- Includes:
- ElementInterface
- Defined in:
- lib/elements/image_element.rb
Overview
Element providing rendering of image.
Instance Method Summary collapse
-
#initialize(source, options, parent) ⇒ ImageElement
constructor
Image element accepts source as path to image file and options
Hash
.
Methods included from ElementInterface
#final_size, #set_height, #set_width
Constructor Details
#initialize(source, options, parent) ⇒ ImageElement
Image element accepts source as path to image file and options Hash
.
Options
Options can contain general attributes specified by BlockElement if it’s created by it.
- :alpha
-
Makes image semi-transparent. Valid values are 0.0 - 1.0 or “0%” - “100%”. Default is 1.0.
- :crop
-
Sets cropping rectangle by values in this order: [x, y, width, height]. Use
Array
orString
to describe it, values inString
must be separated by space char. - :height
-
Sets height of image.
- :width
-
Sets width of image.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/elements/image_element.rb', line 22 def initialize(source, , parent) @source = source @options = @parent = parent :margin if @options[:crop].is_a? Array @crop = (@options[:crop].flatten.map{|v| v.class == Fixnum || v.class == Float || v.class == String ? v.to_i : 0} + [0, 0, 0, 0])[0..3] else @crop = (@options[:crop].to_s.scan(/\-?\d+/).flatten.map(&:to_i) + [0, 0, 0, 0])[0..3] end end |