Class: Axlsx::Pic
- Inherits:
-
Object
- Object
- Axlsx::Pic
- Defined in:
- lib/axlsx/drawing/pic.rb
Overview
a Pic object represents an image in your worksheet Worksheet#add_image is the recommended way to manage images in your sheets
Constant Summary collapse
- ALLOWED_EXTENSIONS =
allowed file extenstions
['gif', 'jpeg', 'png', 'jpg']
Instance Attribute Summary collapse
-
#anchor ⇒ OneCellAnchor
readonly
The anchor for this image.
-
#descr ⇒ String
A description of the picture.
-
#hyperlink ⇒ Object
Returns the value of attribute hyperlink.
-
#image_src ⇒ String
The path to the image you want to include Only local images are supported at this time and only jpg support.
-
#name ⇒ String
The name to use for this picture.
-
#picture_locking ⇒ Object
readonly
The picture locking attributes for this picture.
Instance Method Summary collapse
-
#extname ⇒ String
returns the extension of image_src without the preceeding ‘.’.
-
#file_name ⇒ String
The file name of image_src without any path information.
-
#height ⇒ Object
providing access to update the anchor’s height attribute.
- #height=(v) ⇒ Object
-
#id ⇒ Object
The relational id withing the drawing’s relationships.
-
#index ⇒ Index
The index of this image in the workbooks images collections.
-
#initialize(anchor, options = {}) {|_self| ... } ⇒ Pic
constructor
Creates a new Pic(ture) object.
-
#pn ⇒ String
The part name for this image used in serialization and relationship building.
-
#start_at(x, y) ⇒ Marker
This is a short cut method to set the start anchor position If you need finer granularity in positioning use graphic_frame.anchor.from.colOff / rowOff.
-
#to_xml(xml) ⇒ String
Serializes the picture.
-
#width ⇒ Object
providing access to the anchor’s width attribute.
- #width=(v) ⇒ Object
Constructor Details
#initialize(anchor, options = {}) {|_self| ... } ⇒ Pic
Creates a new Pic(ture) object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/axlsx/drawing/pic.rb', line 40 def initialize(anchor, ={}) @anchor = anchor @anchor.drawing.worksheet.workbook.images << self .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end start_at(*[:start_at]) if [:start_at] yield self if block_given? @picture_locking = PictureLocking.new() end |
Instance Attribute Details
#anchor ⇒ OneCellAnchor (readonly)
The anchor for this image
27 28 29 |
# File 'lib/axlsx/drawing/pic.rb', line 27 def anchor @anchor end |
#descr ⇒ String
A description of the picture
18 19 20 |
# File 'lib/axlsx/drawing/pic.rb', line 18 def descr @descr end |
#hyperlink ⇒ Object
Returns the value of attribute hyperlink.
51 52 53 |
# File 'lib/axlsx/drawing/pic.rb', line 51 def hyperlink @hyperlink end |
#image_src ⇒ String
The path to the image you want to include Only local images are supported at this time and only jpg support
23 24 25 |
# File 'lib/axlsx/drawing/pic.rb', line 23 def image_src @image_src end |
#name ⇒ String
The name to use for this picture
13 14 15 |
# File 'lib/axlsx/drawing/pic.rb', line 13 def name @name end |
#picture_locking ⇒ Object (readonly)
The picture locking attributes for this picture
30 31 32 |
# File 'lib/axlsx/drawing/pic.rb', line 30 def picture_locking @picture_locking end |
Instance Method Details
#extname ⇒ String
returns the extension of image_src without the preceeding ‘.’
90 91 92 |
# File 'lib/axlsx/drawing/pic.rb', line 90 def extname File.extname(image_src).delete('.') unless image_src.nil? end |
#file_name ⇒ String
The file name of image_src without any path information
84 85 86 |
# File 'lib/axlsx/drawing/pic.rb', line 84 def file_name File.basename(image_src) unless image_src.nil? end |
#height ⇒ Object
providing access to update the anchor’s height attribute
126 127 128 |
# File 'lib/axlsx/drawing/pic.rb', line 126 def height @anchor.height end |
#height=(v) ⇒ Object
131 132 133 |
# File 'lib/axlsx/drawing/pic.rb', line 131 def height=(v) @anchor.height = v end |
#id ⇒ Object
The relational id withing the drawing’s relationships
107 108 109 |
# File 'lib/axlsx/drawing/pic.rb', line 107 def id @anchor.drawing.charts.size + @anchor.drawing.images.index(self) + 1 end |
#index ⇒ Index
The index of this image in the workbooks images collections
96 97 98 |
# File 'lib/axlsx/drawing/pic.rb', line 96 def index @anchor.drawing.worksheet.workbook.images.index(self) end |
#pn ⇒ String
The part name for this image used in serialization and relationship building
102 103 104 |
# File 'lib/axlsx/drawing/pic.rb', line 102 def pn "#{IMAGE_PN % [(index+1), extname]}" end |
#start_at(x, y) ⇒ Marker
This is a short cut method to set the start anchor position If you need finer granularity in positioning use graphic_frame.anchor.from.colOff / rowOff
141 142 143 144 |
# File 'lib/axlsx/drawing/pic.rb', line 141 def start_at(x, y) @anchor.from.col = x @anchor.from.row = y end |
#to_xml(xml) ⇒ String
Serializes the picture
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/axlsx/drawing/pic.rb', line 149 def to_xml(xml) xml.pic { xml.nvPicPr { xml.cNvPr(:id=>"2", :name=>name, :descr=>descr) { if @hyperlink.is_a?(Hyperlink) @hyperlink.to_xml(xml) end } xml.cNvPicPr { picture_locking.to_xml(xml) } } xml.blipFill { xml[:a].blip :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId#{id}" xml[:a].stretch { xml.fillRect } } xml.spPr { xml[:a].xfrm { xml.off :x=>0, :y=>0 xml.ext :cx=>2336800, :cy=>2161540 } xml[:a].prstGeom(:prst=>:rect) { xml.avLst } } } end |
#width ⇒ Object
providing access to the anchor’s width attribute
114 115 116 |
# File 'lib/axlsx/drawing/pic.rb', line 114 def width @anchor.width end |
#width=(v) ⇒ Object
119 120 121 |
# File 'lib/axlsx/drawing/pic.rb', line 119 def width=(v) @anchor.width = v end |