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
- ALLOWED_EXTENSIONS =
allowed file extenstions
['gif', 'jpeg', 'png', 'jpg']
Instance Attribute Summary (collapse)
-
- (OneCellAnchor) anchor
readonly
The anchor for this image.
-
- (String) descr
A description of the picture.
-
- (String) image_src
The path to the image you want to include Only local images are supported at this time and only jpg support.
-
- (String) name
The name to use for this picture.
Instance Method Summary (collapse)
-
- (String) extname
returns the extension of image_src without the preceeding ’.’.
-
- (String) file_name
The file name of image_src without any path information.
-
- (Object) height
providing access to update the anchor’s height attribute.
- - (Object) height=(v)
-
- (Index) index
The index of this image in the workbooks images collections.
-
- (Pic) initialize(anchor, options = {}) {|_self| ... }
constructor
Creates a new Pic(ture) object.
-
- (String) pn
The part name for this image used in serialization and relationship building.
-
- (Marker) start_at(x, y)
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.
-
- (String) to_xml(xml)
Serializes the picture.
-
- (Object) width
providing access to the anchor’s width attribute.
- - (Object) width=(v)
Constructor Details
- (Pic) initialize(anchor, options = {}) {|_self| ... }
Creates a new Pic(ture) object
38 39 40 41 42 43 44 45 46 |
# File 'lib/axlsx/drawing/pic.rb', line 38 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
- (OneCellAnchor) anchor (readonly)
The anchor for this image
27 28 29 |
# File 'lib/axlsx/drawing/pic.rb', line 27 def anchor @anchor end |
- (String) descr
A description of the picture
18 19 20 |
# File 'lib/axlsx/drawing/pic.rb', line 18 def descr @descr end |
- (String) image_src
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 |
- (String) name
The name to use for this picture
13 14 15 |
# File 'lib/axlsx/drawing/pic.rb', line 13 def name @name end |
Instance Method Details
- (String) extname
returns the extension of image_src without the preceeding ’.’
70 71 72 |
# File 'lib/axlsx/drawing/pic.rb', line 70 def extname File.extname(image_src).delete('.') unless image_src.nil? end |
- (String) file_name
The file name of image_src without any path information
64 65 66 |
# File 'lib/axlsx/drawing/pic.rb', line 64 def file_name File.basename(image_src) unless image_src.nil? end |
- (Object) height
providing access to update the anchor’s height attribute
101 102 103 |
# File 'lib/axlsx/drawing/pic.rb', line 101 def height @anchor.height end |
- (Object) height=(v)
106 107 108 |
# File 'lib/axlsx/drawing/pic.rb', line 106 def height=(v) @anchor.height = v end |
- (Index) index
The index of this image in the workbooks images collections
76 77 78 |
# File 'lib/axlsx/drawing/pic.rb', line 76 def index @anchor.drawing.worksheet.workbook.images.index(self) end |
- (String) pn
The part name for this image used in serialization and relationship building
82 83 84 |
# File 'lib/axlsx/drawing/pic.rb', line 82 def pn "#{IMAGE_PN % [(index+1), extname]}" end |
- (Marker) start_at(x, y)
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
116 117 118 119 |
# File 'lib/axlsx/drawing/pic.rb', line 116 def start_at(x, y) @anchor.from.col = x @anchor.from.row = y end |
- (String) to_xml(xml)
Serializes the picture
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/axlsx/drawing/pic.rb', line 124 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 |
- (Object) width
providing access to the anchor’s width attribute
89 90 91 |
# File 'lib/axlsx/drawing/pic.rb', line 89 def width @anchor.width end |
- (Object) width=(v)
94 95 96 |
# File 'lib/axlsx/drawing/pic.rb', line 94 def width=(v) @anchor.width = v end |