Module: GD2
- Included in:
- Rchart
- Defined in:
- lib/gd2_helper.rb
Instance Method Summary collapse
- #add_point(x, y) ⇒ Object
- #export_image(file_name, options = {}) ⇒ Object
-
#gd2(fmt = GD2::FMT_RAW, img = self.picture) ⇒ Object
Format flags for Image#gd2 GD2::FMT_RAW GD2::FMT_COMPRESSED.
- #get_image_size(image) ⇒ Object
- #image_color_allocate(picture, r, g, b) ⇒ Object
- #image_color_at(picture, x, y) ⇒ Object
- #image_color_transparent(im, r, g, b) ⇒ Object
- #image_copy(src_pic, dest_pic, dest_x, dest_y, self_x, self_y, width, height) ⇒ Object
- #image_copy_merge(src_pic, dest_pic, dst_x, dst_y, src_x, src_y, dst_w, dst_h, pct, gray = false) ⇒ Object
- #image_create_from_gif(file_name) ⇒ Object
- #image_create_from_jpeg(file_name) ⇒ Object
- #image_create_from_png(file_name) ⇒ Object
- #image_create_true_color(width, height) ⇒ Object
- #image_destroy(image) ⇒ Object
- #image_filled_polygon(picture, points, r, g, b, points_count = 0) ⇒ Object
- #image_filled_rectangle(picture, x1, y1, x2, y2, r, g, b) ⇒ Object
-
#image_ftb_box(font_size, angle, font_name, string, x = 0, y = 0, options = {}) ⇒ Object
color helper.
-
#image_line(picture, x1, y1, x2, y2, r, g, b) ⇒ Object
rgb_color(picture, pixel).
- #image_set_pixel(picture, x, y, r, g, b) ⇒ Object
- #image_ttf_text(picture, font_size, angle, x_pos, y_pos, fg_color, font_name, string, options = {}) ⇒ Object
- #render_gd_str(img = self.picture) ⇒ Object
- #render_gif_str(img = self.picture) ⇒ Object
- #render_jepeg_str(level = 9, img = self.picture) ⇒ Object
-
#render_jpeg(file_name, quality = 0) ⇒ Object
render Graph as jpeg format.
-
#render_png(file_name, level = 9) ⇒ Object
render Graph as png format.
-
#render_png_str(level = 9, img = self.picture) ⇒ Object
Outputs the image in PNG format as String object.
- #render_wbmp_str(fgcolor, img = self.picture) ⇒ Object
- #rgb_color(picture, pixel) ⇒ Object
Instance Method Details
#add_point(x, y) ⇒ Object
10 11 12 |
# File 'lib/gd2_helper.rb', line 10 def add_point(x,y) Canvas::Point.new(x,y) end |
#export_image(file_name, options = {}) ⇒ Object
122 123 124 |
# File 'lib/gd2_helper.rb', line 122 def export_image(file_name,={}) @picture.export(file_name,) end |
#gd2(fmt = GD2::FMT_RAW, img = self.picture) ⇒ Object
Format flags for Image#gd2 GD2::FMT_RAW GD2::FMT_COMPRESSED
150 151 152 |
# File 'lib/gd2_helper.rb', line 150 def gd2(fmt= GD2::FMT_RAW,img=self.picture) img.gd2(fmt) end |
#get_image_size(image) ⇒ Object
88 89 90 |
# File 'lib/gd2_helper.rb', line 88 def get_image_size(image) [image.width,image.height] end |
#image_color_allocate(picture, r, g, b) ⇒ Object
14 15 16 |
# File 'lib/gd2_helper.rb', line 14 def image_color_allocate(picture,r,g,b) Color.new(r,g,b) # returns an integer value end |
#image_color_at(picture, x, y) ⇒ Object
41 42 43 44 |
# File 'lib/gd2_helper.rb', line 41 def image_color_at(picture,x,y) pixel = picture.get_pixel(x, y) # rgb_color(picture, pixel) end |
#image_color_transparent(im, r, g, b) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/gd2_helper.rb', line 68 def image_color_transparent(im,r,g,b) color = allocate_color(im, r, g, b) # im.save_alpha =true im.transparent = color end |
#image_copy(src_pic, dest_pic, dest_x, dest_y, self_x, self_y, width, height) ⇒ Object
64 65 66 |
# File 'lib/gd2_helper.rb', line 64 def image_copy(src_pic,dest_pic,dest_x, dest_y, self_x, self_y, width, height) dest_pic.copy_from(src_pic,dest_x, dest_y, self_x, self_y, width, height) end |
#image_copy_merge(src_pic, dest_pic, dst_x, dst_y, src_x, src_y, dst_w, dst_h, pct, gray = false) ⇒ Object
60 61 62 |
# File 'lib/gd2_helper.rb', line 60 def image_copy_merge(src_pic,dest_pic, dst_x, dst_y, src_x, src_y, dst_w, dst_h, pct, gray = false) dest_pic.merge_from(src_pic, dst_x, dst_y, src_x, src_y, dst_w, dst_h,pct/100.0) end |
#image_create_from_gif(file_name) ⇒ Object
85 86 87 |
# File 'lib/gd2_helper.rb', line 85 def image_create_from_gif(file_name) Image.import(file_name) end |
#image_create_from_jpeg(file_name) ⇒ Object
82 83 84 |
# File 'lib/gd2_helper.rb', line 82 def image_create_from_jpeg(file_name) Image.import(file_name) end |
#image_create_from_png(file_name) ⇒ Object
79 80 81 |
# File 'lib/gd2_helper.rb', line 79 def image_create_from_png(file_name) Image.import(file_name) end |
#image_create_true_color(width, height) ⇒ Object
5 6 7 8 |
# File 'lib/gd2_helper.rb', line 5 def image_create_true_color(width,height) # Image::IndexedColor.new(width,height) Image::TrueColor.new(width,height) end |
#image_destroy(image) ⇒ Object
75 76 77 |
# File 'lib/gd2_helper.rb', line 75 def image_destroy(image) # GD2FFI.gdImageDestroy(image.image_ptr) end |
#image_filled_polygon(picture, points, r, g, b, points_count = 0) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/gd2_helper.rb', line 92 def image_filled_polygon(picture,points,r,g,b,points_count=0) color = allocate_color(picture,r,g,b) polygon_points = [] i=0 if points_count == 0 num_points = (points.length+1) else num_points = points_count+points_count end while(i<=num_points) j =i polygon_points << Canvas::Point.new(points[j],points[j+1]) if(!points[j+1].nil?) i = i+2 end polygon=Canvas::FilledPolygon.new(polygon_points) polygon.draw(picture,color.to_i) end |
#image_filled_rectangle(picture, x1, y1, x2, y2, r, g, b) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/gd2_helper.rb', line 53 def image_filled_rectangle(picture,x1,y1,x2,y2,r,g,b) color = allocate_color(picture, r, g, b) point1 = add_point(x1,y1) point2 = add_point(x2,y2) filled_rectangle = Canvas::FilledRectangle.new(point1,point2) filled_rectangle.draw(picture,color.rgba) end |
#image_ftb_box(font_size, angle, font_name, string, x = 0, y = 0, options = {}) ⇒ Object
color helper
27 28 29 30 31 32 |
# File 'lib/gd2_helper.rb', line 27 def image_ftb_box(font_size,angle,font_name,string,x=0,y=0,={}) angle = deg2rad(angle) font = Font::TrueType.new(font_name, font_size,) position = font.bounding_rectangle(string,angle) [position[:lower_left][0],position[:lower_left][1],position[:lower_right][0],position[:lower_right][1],position[:upper_right][0],position[:upper_right][1],position[:upper_left][0],position[:upper_left][1]] end |
#image_line(picture, x1, y1, x2, y2, r, g, b) ⇒ Object
rgb_color(picture, pixel)
45 46 47 48 49 50 51 |
# File 'lib/gd2_helper.rb', line 45 def image_line(picture,x1,y1,x2,y2,r,g,b) color = allocate_color(picture,r,g,b) point1 = add_point(x1,y1) point2 = add_point(x2,y2) line = Canvas::Line.new(point1,point2) line.draw(picture,color) end |
#image_set_pixel(picture, x, y, r, g, b) ⇒ Object
36 37 38 39 |
# File 'lib/gd2_helper.rb', line 36 def image_set_pixel(picture,x,y,r,g,b) color= image_color_allocate(picture,r,g,b) picture.set_pixel(x,y,color.rgba.to_i) end |
#image_ttf_text(picture, font_size, angle, x_pos, y_pos, fg_color, font_name, string, options = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/gd2_helper.rb', line 18 def image_ttf_text(picture,font_size,angle,x_pos,y_pos,fg_color,font_name,string,={}) angle = deg2rad(angle) font = Font::TrueType.new(font_name, font_size,) point= add_point(x_pos,y_pos) text = Canvas::Text.new(font,point,angle,string) text.draw(picture,fg_color.rgba) end |
#render_gd_str(img = self.picture) ⇒ Object
144 145 146 |
# File 'lib/gd2_helper.rb', line 144 def render_gd_str(img=self.picture) img.gd(fgcolor) end |
#render_gif_str(img = self.picture) ⇒ Object
136 137 138 |
# File 'lib/gd2_helper.rb', line 136 def render_gif_str(img=self.picture) img.gif end |
#render_jepeg_str(level = 9, img = self.picture) ⇒ Object
133 134 135 |
# File 'lib/gd2_helper.rb', line 133 def render_jepeg_str(level=9,img=self.picture) img.png(level) end |
#render_jpeg(file_name, quality = 0) ⇒ Object
render Graph as jpeg format
155 156 157 158 159 160 |
# File 'lib/gd2_helper.rb', line 155 def render_jpeg(file_name,quality=0) print_errors(@error_interface) if ( @error_reporting ) file = File.new(file_name,"wb") file.write @picture.jpeg(quality) file.close end |
#render_png(file_name, level = 9) ⇒ Object
render Graph as png format
115 116 117 118 119 120 |
# File 'lib/gd2_helper.rb', line 115 def render_png(file_name,level=9) print_errors(@error_interface) if ( @error_reporting ) file = File.new(file_name,"wb") file.write @picture.png(level) file.close end |
#render_png_str(level = 9, img = self.picture) ⇒ Object
Outputs the image in PNG format as String object. This method will be especially useful when you want to transmit an image directly to an user(i.e, without first writing it to a file)
129 130 131 |
# File 'lib/gd2_helper.rb', line 129 def render_png_str(level=9,img=self.picture) img.png(level) end |
#render_wbmp_str(fgcolor, img = self.picture) ⇒ Object
140 141 142 |
# File 'lib/gd2_helper.rb', line 140 def render_wbmp_str(fgcolor,img=self.picture) img.wbmp(fgcolor) end |
#rgb_color(picture, pixel) ⇒ Object
110 111 112 113 |
# File 'lib/gd2_helper.rb', line 110 def rgb_color(picture,pixel) color = picture.pixel2color(pixel) [color.r,color.g,color.b] end |