Class: Writeexcel::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/writeexcel/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checksum1Object (readonly)

Returns the value of attribute checksum1


7
8
9
# File 'lib/writeexcel/image.rb', line 7

def checksum1
  @checksum1
end

#checksum2Object (readonly)

Returns the value of attribute checksum2


7
8
9
# File 'lib/writeexcel/image.rb', line 7

def checksum2
  @checksum2
end

#colObject (readonly)

Returns the value of attribute col


6
7
8
# File 'lib/writeexcel/image.rb', line 6

def col
  @col
end

#dataObject (readonly)

Returns the value of attribute data


7
8
9
# File 'lib/writeexcel/image.rb', line 7

def data
  @data
end

#filenameObject (readonly)

Returns the value of attribute filename


6
7
8
# File 'lib/writeexcel/image.rb', line 6

def filename
  @filename
end

#heightObject

Returns the value of attribute height


8
9
10
# File 'lib/writeexcel/image.rb', line 8

def height
  @height
end

#idObject

Returns the value of attribute id


8
9
10
# File 'lib/writeexcel/image.rb', line 8

def id
  @id
end

#ref_countObject

Returns the value of attribute ref_count


8
9
10
# File 'lib/writeexcel/image.rb', line 8

def ref_count
  @ref_count
end

#rowObject (readonly)

Returns the value of attribute row


6
7
8
# File 'lib/writeexcel/image.rb', line 6

def row
  @row
end

#scale_xObject (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_yObject (readonly)

Returns the value of attribute scale_y


6
7
8
# File 'lib/writeexcel/image.rb', line 6

def scale_y
  @scale_y
end

#sizeObject (readonly)

Returns the value of attribute size


7
8
9
# File 'lib/writeexcel/image.rb', line 7

def size
  @size
end

#typeObject

Returns the value of attribute type


8
9
10
# File 'lib/writeexcel/image.rb', line 8

def type
  @type
end

#widthObject

Returns the value of attribute width


8
9
10
# File 'lib/writeexcel/image.rb', line 8

def width
  @width
end

#x_offsetObject (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_offsetObject (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

#importObject


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