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.
-
#extname ⇒ String
readonly
returns the extension of image_src without the preceeding ‘.’.
-
#file_name ⇒ String
readonly
The name of the image file, sans directory info.
-
#height ⇒ Object
providing access to update the anchor’s height attribute.
-
#image_src ⇒ String
The path to the image you want to include Only local images are supported at this time and only jpg support.
-
#index ⇒ Index
readonly
The index of this image in the workbooks images collections.
-
#name ⇒ String
The name to use for this picture.
-
#pn ⇒ String
readonly
The part name for this image used in serialization and relationship building.
-
#width ⇒ Object
providing access to the anchor’s width attribute.
Instance Method Summary collapse
-
#initialize(anchor, options = {}) {|_self| ... } ⇒ Pic
constructor
Creates a new Pic(ture) object.
-
#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.
Constructor Details
#initialize(anchor, options = {}) {|_self| ... } ⇒ Pic
Creates a new Pic(ture) object
66 67 68 69 70 71 72 73 74 |
# File 'lib/axlsx/drawing/pic.rb', line 66 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? end |
Instance Attribute Details
#anchor ⇒ OneCellAnchor (readonly)
The anchor for this image
36 37 38 |
# File 'lib/axlsx/drawing/pic.rb', line 36 def anchor @anchor end |
#descr ⇒ String
A description of the picture
27 28 29 |
# File 'lib/axlsx/drawing/pic.rb', line 27 def descr @descr end |
#extname ⇒ String (readonly)
returns the extension of image_src without the preceeding ‘.’
40 41 42 |
# File 'lib/axlsx/drawing/pic.rb', line 40 def extname @extname end |
#file_name ⇒ String (readonly)
The name of the image file, sans directory info
44 45 46 |
# File 'lib/axlsx/drawing/pic.rb', line 44 def file_name @file_name end |
#height ⇒ Object
providing access to update the anchor’s height attribute
23 24 25 |
# File 'lib/axlsx/drawing/pic.rb', line 23 def height @height 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
32 33 34 |
# File 'lib/axlsx/drawing/pic.rb', line 32 def image_src @image_src end |
#index ⇒ Index (readonly)
The index of this image in the workbooks images collections
52 53 54 |
# File 'lib/axlsx/drawing/pic.rb', line 52 def index @index 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 |
#pn ⇒ String (readonly)
The part name for this image used in serialization and relationship building
48 49 50 |
# File 'lib/axlsx/drawing/pic.rb', line 48 def pn @pn end |
#width ⇒ Object
providing access to the anchor’s width attribute
18 19 20 |
# File 'lib/axlsx/drawing/pic.rb', line 18 def width @width end |
Instance Method Details
#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
124 125 126 127 |
# File 'lib/axlsx/drawing/pic.rb', line 124 def start_at(x, y) @anchor.from.col = x @anchor.from.row = y end |
#to_xml(xml) ⇒ String
Serializes the picture
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/axlsx/drawing/pic.rb', line 132 def to_xml(xml) xml.send('xdr:pic') { xml.send('xdr:nvPicPr') { xml.send('xdr:cNvPr', :id=>"2", :name=>name, :descr=>descr) xml.send('xdr:cNvPicPr') { xml.send('a:picLocks', :noChangeAspect=>1) } } xml.send('xdr:blipFill') { xml.send('a:blip', :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId1") xml.send('a:stretch') { xml.send('a:fillRect') } } xml.send('xdr:spPr') { xml.send('a:xfrm') { xml.send('a:off', :x=>0, :y=>0) xml.send('a:ext', :cx=>2336800, :cy=>2161540) } xml.send('a:prstGeom', :prst=>:rect) { xml.send('a:avLst') } } } end |