Class: Writeexcel::Image
- Inherits:
-
Object
- Object
- Writeexcel::Image
- Defined in:
- lib/writeexcel/image.rb
Instance Attribute Summary collapse
-
#checksum1 ⇒ Object
readonly
Returns the value of attribute checksum1.
-
#checksum2 ⇒ Object
readonly
Returns the value of attribute checksum2.
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ref_count ⇒ Object
Returns the value of attribute ref_count.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#scale_x ⇒ Object
readonly
Returns the value of attribute scale_x.
-
#scale_y ⇒ Object
readonly
Returns the value of attribute scale_y.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
Returns the value of attribute type.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x_offset ⇒ Object
readonly
Returns the value of attribute x_offset.
-
#y_offset ⇒ Object
readonly
Returns the value of attribute y_offset.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(worksheet, row, col, filename, x_offset = 0, y_offset = 0, scale_x = 1, scale_y = 1) ⇒ Image
constructor
A new instance of Image.
- #store_image_record(i, num_images, num_charts, num_filters, num_comments, spid) ⇒ Object
Constructor Details
#initialize(worksheet, row, col, filename, x_offset = 0, y_offset = 0, scale_x = 1, scale_y = 1) ⇒ Image
Returns a new instance of Image.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/writeexcel/image.rb', line 10 def initialize(worksheet, row, col, filename, x_offset = 0, y_offset = 0, scale_x = 1, scale_y = 1) @worksheet = worksheet @row = row @col = col @filename = filename @x_offset = x_offset @y_offset = y_offset @scale_x = scale_x @scale_y = scale_y get_checksum_method end |
Instance Attribute Details
#checksum1 ⇒ Object (readonly)
Returns the value of attribute checksum1.
7 8 9 |
# File 'lib/writeexcel/image.rb', line 7 def checksum1 @checksum1 end |
#checksum2 ⇒ Object (readonly)
Returns the value of attribute checksum2.
7 8 9 |
# File 'lib/writeexcel/image.rb', line 7 def checksum2 @checksum2 end |
#col ⇒ Object (readonly)
Returns the value of attribute col.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def col @col end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/writeexcel/image.rb', line 7 def data @data end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def filename @filename end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/writeexcel/image.rb', line 8 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/writeexcel/image.rb', line 8 def id @id end |
#ref_count ⇒ Object
Returns the value of attribute ref_count.
8 9 10 |
# File 'lib/writeexcel/image.rb', line 8 def ref_count @ref_count end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def row @row end |
#scale_x ⇒ Object (readonly)
Returns the value of attribute scale_x.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def scale_x @scale_x end |
#scale_y ⇒ Object (readonly)
Returns the value of attribute scale_y.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def scale_y @scale_y end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
7 8 9 |
# File 'lib/writeexcel/image.rb', line 7 def size @size end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/writeexcel/image.rb', line 8 def type @type end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/writeexcel/image.rb', line 8 def width @width end |
#x_offset ⇒ Object (readonly)
Returns the value of attribute x_offset.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def x_offset @x_offset end |
#y_offset ⇒ Object (readonly)
Returns the value of attribute y_offset.
6 7 8 |
# File 'lib/writeexcel/image.rb', line 6 def y_offset @y_offset end |
Instance Method Details
#import ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/writeexcel/image.rb', line 22 def import File.open(@filename, "rb") do |fh| raise "Couldn't import #{@filename}: #{$!}" unless fh @data = fh.read end @size = data.bytesize @checksum1 = image_checksum(@data) @checksum2 = @checksum1 process end |
#store_image_record(i, num_images, num_charts, num_filters, num_comments, spid) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/writeexcel/image.rb', line 33 def store_image_record(i, num_images, num_charts, num_filters, num_comments, spid) image_width = width image_height = height image_width = width * scale_x unless scale_x == 0 image_height = height * scale_y unless scale_y == 0 # Calculate the positions of image object. vertices = @worksheet.position_object(col, row, x_offset, y_offset, image_width, image_height) if (i == 0) data = images_parent_msodrawing_record(num_images, num_charts, num_filters, num_comments, spid, id, vertices) else data = images_child_msodrawing_record(spid, id, vertices) end record = 0x00EC # Record identifier length = 0x0000 # Bytes to follow length = data.bytesize header = [record, length].pack("vv") append(header, data) end |