class AastraXmlApi::PhoneGDImage
Public Class Methods
new()
click to toggle source
Creates a new GD image of size 144x40 (maximum allowed on phone). Also creates black and white colors to be used and sets default font path based on whether this is running under rails or a specific operating system.
# File lib/aastra_xml_api/phone_gd_image.rb, line 101 def initialize # create image @img = GD::Image.new(144, 40) # define black and white @white = @img.colorAllocate(255, 255, 255) @black = @img.colorAllocate(0, 0, 0) # black and white only so disable anti-aliasing @black *= -1 @white *= -1 # define a default font path if defined?(RAILS_ROOT) then @fontpath = "#{RAILS_ROOT}/fonts" else os = RUBY_PLATFORM.downcase @fontpath = "C:\\Windows\\Fonts" if not os.scan(/win/).nil? @fontpath = "../fonts" if not os.scan(/linux$/).nil? @fontpath = "../fonts" if not os.scan(/darwin\d+\.\d+$/).nil? end ENV['GDFONTPATH'] = @fontpath end
Public Instance Methods
drawtext(size, x, y, text, colorIndex)
click to toggle source
Draw text on the image.
# File lib/aastra_xml_api/phone_gd_image.rb, line 138 def drawtext(size, x, y, text, colorIndex) @img.string(size, x, y, text, getColor(colorIndex)) end
drawttftext(size, angle, x, y, text, colorIndex, font)
click to toggle source
Draw text on the image using a specific true type font. See GD documentation for parameters.
# File lib/aastra_xml_api/phone_gd_image.rb, line 133 def drawttftext(size, angle, x, y, text, colorIndex, font) @img.stringTTF(getColor(colorIndex), font, size, angle, x, y, text) end
ellipse(cx, cy, width, height, colorIndex, filled=false)
click to toggle source
Draw an ellipse on the image. Ellipse will be unfilled by default.
# File lib/aastra_xml_api/phone_gd_image.rb, line 162 def ellipse(cx, cy, width, height, colorIndex, filled=false) if filled then @img.filledEllipse(cx, cy, width, height, 0, 360, getColor(colorIndex)) else @img.ellipse(cx, cy, width, height, 0, 360, getColor(colorIndex)) end end
getColor(index)
click to toggle source
Get the GD color element based on an index.
- 0
-
white
- 1
-
black
# File lib/aastra_xml_api/phone_gd_image.rb, line 182 def getColor(index) return @white if index == 0 return @black end
getGDImage()
click to toggle source
Get the GD image created.
# File lib/aastra_xml_api/phone_gd_image.rb, line 148 def getGDImage return @img end
line(x1, y1, x2, y2, colorIndex, dashed=false)
click to toggle source
Draw a line on the image. Line will be solid by default.
# File lib/aastra_xml_api/phone_gd_image.rb, line 171 def line(x1, y1, x2, y2, colorIndex, dashed=false) if dashed then @img.dashedLine(x1, y2, x2, y2, getColor(colorIndex)) else @img.line(x1, y2, x2, y2, getColor(colorIndex)) end end
rectangle(x1, y1, x2, y2, colorIndex, filled=false)
click to toggle source
Draw a rectangle on the image. Rectangle will be unfilled by default.
# File lib/aastra_xml_api/phone_gd_image.rb, line 153 def rectangle(x1, y1, x2, y2, colorIndex, filled=false) if filled then @img.filledRectangle(x1, y1, x2, y2, getColor(colorIndex)) else @img.rectangle(x1, y1, x2, y2, getColor(colorIndex)) end end
setFontPath(fontpath)
click to toggle source
Set font path for GD.
# File lib/aastra_xml_api/phone_gd_image.rb, line 126 def setFontPath(fontpath) @fontpath = fontpath ENV['GDFONTPATH'] = @fontpath end
setGDImage(image)
click to toggle source
Set the image from an externally created GD image.
# File lib/aastra_xml_api/phone_gd_image.rb, line 143 def setGDImage(image) @img = image end