amardaxini-ruby-gd 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,989 @@
1
+ =begin
2
+
3
+ = Ruby/GD Version 0.7.4
4
+
5
+ Ruby extension library for using Thomas Boutell's gd
6
+ library(http://www.boutell.com/gd/).
7
+
8
+ Originally written by Yukihiro Matsumoto (matz@ruby-lang.org)
9
+
10
+ Current maintainer: Ryuichi Tamura (tam@kais.kyoto-u.ac.jp)
11
+
12
+ ((* If gd-2.0.x is installed in your system, and Ruby/GD is compiled
13
+ with (({--enable-gd2_0})) option, you can use those constants or
14
+ methods described in the subsection "gd-2.0.0 or higher"*))
15
+
16
+ == Module/Class Hierarchy
17
+
18
+ GD -+
19
+ |
20
+ +- GD::Image
21
+ |
22
+ +- GD::Polygon
23
+ |
24
+ +- GD::Font
25
+
26
+ = Module GD
27
+
28
+ Module that defines some constants refered by GD::Image or GD::Polygon
29
+ instances.
30
+
31
+ == Constants
32
+
33
+ --- GD::Brushed
34
+
35
+ If this constant is used as the color when invoking a line-drawing
36
+ method such as ((<GD::Image#line>)) or ((<GD::Image#rectangle>)), the
37
+ line to be drawn is the brush image that has been set with
38
+ ((<GD::Image#setBrush>)).
39
+
40
+ --- GD::Styled
41
+
42
+ If this constant is used as the color when invoking a line-drawing
43
+ method such as ((<GD::Image#line>)) or ((<GD::Image#rectangle>)), the
44
+ colors of the pixels are drawn successively from the style that has
45
+ been set with ((<GD::Image#setStyle>)). If the color of a pixel is
46
+ equal to ((<GD::Transparent>)), that pixel is not altered.
47
+
48
+ --- GD::StyledBrushed
49
+
50
+ If this constant is used as the color when invoking a line-drawing
51
+ method such as ((<GD::Image#line>)) or ((<GD::Image#rectangle>)), the
52
+ brush set with ((<GD::Image#setBrush>)) is drawn wherever the color
53
+ specified in ((<GD::Image#setStyle>)) is neither zero nor
54
+ ((<GD::Transparent>)).
55
+
56
+ --- GD::Tiled
57
+
58
+ If this constant is used as the color when invoking a filling method
59
+ such as ((<GD::Image#filledRectangle>)),
60
+ ((<GD::Image#filledPolygon>)), ((<GD::Image#fill>)), and
61
+ ((<GD::Image#fillToBorder>)). The area is filled with a tile image set
62
+ with ((<GD::Image#setTile>)).
63
+
64
+ --- GD::Transparent
65
+
66
+ Used in place of a normal color in a style to be set with
67
+ ((<GD::Image#setStyle>)). This constant is not the transparent color
68
+ index of the image; for that functionality, see
69
+ ((<GD::Image#transparent>)).
70
+
71
+ --- GD::GD2_FMT_COMPRESSED
72
+
73
+ specifies Gd2 image to be compressed. This constant is used in
74
+ ((<GD::Image#gd2>)).
75
+
76
+ --- GD::GD2_FMT_RAW
77
+
78
+ specifies Gd2 image to be uncompressed. This constant is used in
79
+ ((<GD::Image#gd2>)).
80
+
81
+
82
+ === gd-2.0.0 or higher
83
+
84
+ --- GD::AlphaTransparent
85
+
86
+ --- GD::AlphaOpaque
87
+
88
+ These constants are used in ((<GD::Image.trueColorAlpha>)), and each
89
+ defines the upper(127) and lower(0) bounds of alpha channel value,
90
+ respectively. Full transparency corresponds to GD::AlphaTransparent.
91
+
92
+ --- GD::Arc
93
+
94
+ --- GD::Chord
95
+
96
+ --- GD::Pie
97
+
98
+ --- GD::NoFill
99
+
100
+ --- GD::Edged
101
+
102
+ These constants become options that specify how an arc is drawn with
103
+ using ((<GD::Image#filledArc>)). See also ((<GD::Image#filledArc>)).
104
+
105
+
106
+ = Class GD::Image
107
+
108
+ == Class Methods
109
+
110
+ + Instance Creation
111
+
112
+ --- GD::Image.new(width, height)
113
+
114
+ creates a new palette image instance with specified ((|width|)) and
115
+ ((|height|)).
116
+
117
+ --- GD::Image.newFromGd(file)
118
+
119
+ creates a new image instance from Gd file. ((|file|)) is a File
120
+ object.
121
+
122
+ --- GD::Image.new_from_gd(filename)
123
+
124
+ creates a new Gd image instance from ((|filename|)). ((|filename|))
125
+ is a String object which specifies the localtion of the image file.
126
+
127
+ --- GD::Image.newFromGd2(file)
128
+
129
+ creates a new image instance from Gd2 file. ((|file|)) is a File
130
+ object.
131
+
132
+ --- GD::Image.new_from_gd2(filename)
133
+
134
+ creates a new Gd2 image instance from ((|filename|)). ((|filename|))
135
+ is a String object which specifies the location of the image file.
136
+
137
+ --- GD::Image.newFromGd2Part(file, srcX, srcY, width, height)
138
+
139
+ creates a new image instance from part of Gd2 file. ((|file|)) is a
140
+ File object.
141
+
142
+ --- GD::Image.new_from_gd2_part(filename)
143
+
144
+ creates a new Gd2 image instance from ((|filename|)). ((|filename|))
145
+ is a String object which specifies the location of the image file.
146
+
147
+ --- GD::Image.newFromJpeg(file)
148
+ (gd-1.8 or later)
149
+
150
+ Creates a new image instance from JPEG file. ((|file|)) is a File
151
+ object.
152
+
153
+ --- GD::Image.new_from_jpeg(filename)
154
+
155
+ creates a new Jpeg image instance from ((|filename|)). ((|filename|))
156
+ is a String object which specifies the location of the image file.
157
+
158
+ --- GD::Image.newFromPng(file)
159
+
160
+ creates a new image instance from PNG file. ((|file|)) is a File
161
+ object.
162
+
163
+ --- GD::Image.new_from_png(filename)
164
+
165
+ creates a new PNG image instance from ((|filename|)). ((|filename|))
166
+ is a String object which specifies the location of the image file.
167
+
168
+ --- GD::Image.newFromGif(file)
169
+
170
+ creates a new image instance from GIF file. ((|file|)) is a File
171
+ object.
172
+
173
+ --- GD::Image.new_from_gif(filename)
174
+
175
+ creates a new GIF image instance from ((|filename|)). ((|filename|))
176
+ is a String object which specifies the location of the image file.
177
+
178
+ --- GD::Image.newFromXbm(file)
179
+
180
+ creates a new image instance from Xbm file. ((|file|)) is a File
181
+ object.
182
+
183
+ --- GD::Image.new_from_xbm(filename)
184
+
185
+ creates a new XBitmap image instance from
186
+ ((|filename|)). ((|filename|)) is a String object which specifies the
187
+ location of the image file.
188
+
189
+
190
+ --- GD::Image.newFromXpm(file)
191
+ (gd-1.7 or later)
192
+
193
+ creates a new image instance from Xpm file. ((|file|)) is a File
194
+ object.
195
+
196
+ --- GD::Image.new_from_xpm(filename)
197
+
198
+ creates a new XPixmaps image instance from
199
+ ((|filename|)). ((|filename|)) is a String object which specifies the
200
+ location of the image file.
201
+
202
+ + Query
203
+
204
+ --- GD::Image.stringTTF(fg_color, fnt_name, pt, angle, x, y, str)
205
+ (gd-1.6.1 or later)
206
+
207
+ Tries to find the bounding rectangle of ((|str|)) with size (((|pt|)))
208
+ and the name of the TrueType font(((|fnt_name|))), and returns the
209
+ array consists of the error message string and the array of each
210
+ vertex of the rectangle(brect[8], see the figure in the section of
211
+ ((<GD::Image#stringTTF>))). If successful, the error message is
212
+ ((:nil:)). See also ((<GD::Image#stringTTF>)).
213
+
214
+ --- GD::Image.stringFT(fg_color, fnt_name, pt, angle, x, y, str)
215
+ (gd-1.8.4)
216
+
217
+ This method provides the same functionarity as
218
+ ((<GD::Image.stringTTF>)) does, but uses FreeType2 library when
219
+ redering the string. See also ((<GD::Image#stringFT>))
220
+
221
+ === gd-2.0.0 or higher
222
+
223
+ --- GD::Image.newTrueColor(width, height)
224
+
225
+ Creates a new truecolor image instance with specified ((|width|)) and
226
+ ((|height|)).
227
+
228
+ --- GD::Image.trueColor(r, g, b)
229
+ --- GD::Image.trueColor(rgbstr)
230
+
231
+ returns the RGBA color value for drawing on a truecolor image, or an
232
+ image created by ((<GD::Image.newTrueColor>)). ((|r|)), ((|g|)),
233
+ ((|b|)) values are in the range between 0 and 255. Or, you can
234
+ specify it by ((|rgbstr|)) which is in the range between "#000000" and
235
+ "#FFFFFF".
236
+
237
+ --- GD::Image.trueColor(r, g, b, alpha)
238
+ --- GD::Image.trueColorAlpha(rgbstr, alpha)
239
+
240
+ returns the RGBA color value for drawing on a truecolor image, or an
241
+ image created by ((<GD::Image.newTrueColor>)) with alpha channel
242
+ transparency. Because gd has 7-bit alpha channel, the ((|alpha|))
243
+ value takes between 0(opaque) and 127(transparent).
244
+
245
+ These class methods are used for ((*truecolor*)) images. If you want
246
+ to specify alpha value for ((*palette*)) images, use
247
+ ((<GD::Image#colorAllocateAlpha>)), ((<GD::Image#colorExactAlpha>)),
248
+ ((<GD::Image#colorClosestAlpha>)), or
249
+ ((<GD::Image#colorResolveAlpha>)) instead.
250
+
251
+
252
+ == Methods
253
+
254
+ --- GD::Image#destroy
255
+
256
+ Free the memory associated with the image instance.
257
+
258
+ --- GD::Image#interlace=(val)
259
+
260
+ If ((|val|)) is ((:true:)), the image is interlaced. Otherwise and by
261
+ default, the image is not interlaced.
262
+
263
+ === Color Handling
264
+
265
+ --- GD::Image#colorAllocate(r, g, b)
266
+ --- GD::Image#colorAllocate(str)
267
+
268
+ Finds the first available color index in the image instance, and sets
269
+ its RGB values to ((|r|)), ((|g|)), ((|b|)), respectively and returns
270
+ the index of the new color table entry. ((|r|)), ((|g|)), ((|b|)) take
271
+ a value between 0 and 255. Also, if you use Ruby-1.6.0 or later, you
272
+ can specify a color as strings like "#FF00FF".
273
+
274
+ Note that the first time you invoke this method after creating a new
275
+ image by ((<GD::Image.new>)), ((*the background color*)) of the image
276
+ is set.
277
+
278
+ You can allocate upto 256 colors to one image. If there is no space to
279
+ allocate the requested color, this returns -1.
280
+
281
+ If you use gd-1.6.2 or later, you can use
282
+ ((<GD::Image#colorResolve>)), more robust way of color allocation.
283
+
284
+ --- GD::Image#colorClosest(r, g, b)
285
+ --- GD::Image#colorClosest(str)
286
+
287
+ Searches the colors which have been defined thus far in the image
288
+ instance and returns the index of the color with RGB values closest to
289
+ ((|r|)), ((|g|)), ((|b|)), respectively. Also, if you use Ruby-1.6.0
290
+ or later, you can specify a color as strings like "#FF00FF".If no
291
+ color have been yet allocated to that image, this returns -1
292
+
293
+ This method is useful when a image instance which you want to allocate
294
+ a new color is created from the image scanned from a photograph in
295
+ which many colors will be used.
296
+
297
+ --- GD::Image#colorDeallocate(color)
298
+
299
+ This marks the ((|color|)) at the specified index as being ripe for
300
+ reallocation. The next time ((<GD::Image#colorAllocate>)) is used,
301
+ this entry will be replaced. You can call this method several times
302
+ to deallocate multiple colors.
303
+
304
+ --- GD::Image#colorExact(r, g, b)
305
+ --- GD::Image#colorExact(str)
306
+
307
+ Searches the colors which have been defined thus far in the image
308
+ instance and returns the index of the first color with RGB values
309
+ which exactly match (((|r|)), ((|g|)), ((|b|))). If no allocated color
310
+ matches the request precisely, this returns -1. Also, if you use
311
+ Ruby-1.6.0 or later, you can specify a color as strings like
312
+ "#FF00FF".
313
+
314
+ --- GD::Image#colorResolve(r, g, b)
315
+ --- GD::Image#colorResolve(str)
316
+ (gd-1.6.2 or later)
317
+
318
+ Searches the colors which have been defined thus far in the image
319
+ specified and returns the index of the first color with RGB values
320
+ which exactly match those of the request. Also, if you use Ruby-1.6.0
321
+ or later, you can specify a color as strings like "#FF00FF".
322
+
323
+ If no allocated color matches the request precisely, then this method
324
+ tries to allocate the exact color.If there is no space left in the
325
+ color table then this method returns the closest color (as in
326
+ ((<GD::Image#colorClosest>))).
327
+
328
+ Unlike ((<GD::Image#colorAllocate>)), this method always returns an
329
+ index of a color.
330
+
331
+ --- GD::Image#transparent(idx)
332
+
333
+ Sets the transparent color index for the specified image to the
334
+ specified color index ((|idx|)). To indicate that there should be no
335
+ transparent color, set ((|idx|)) to -1.
336
+
337
+ Note that JPEG images ((*do not support*)) transparency, so this
338
+ setting has no effect when writing JPEG images.
339
+
340
+ + Drawing and Filling
341
+
342
+ --- GD::Image#arc(cx, cy, width, height, start, end, color)
343
+
344
+ Draw a partial ellipse centered at the given point (((|cx|)),((|cy|)))
345
+ with specified width ((|width|)) and height ((|height|)) in pixel with
346
+ specified ((|color|)). The arc begins at the position in degrees
347
+ specified by ((|start|)) and ends at the position specified by
348
+ ((|end|)).
349
+
350
+ --- GD::Image#dashedLine(x1, y1, x2, y2, color)
351
+
352
+ This method is provided solely for backwards compatibility of the
353
+ Boutell's gd library. When drawing a dashed line, new programs should
354
+ use ((<GD::Image#line>)) with ((<GD::Image#setStyle>)).
355
+
356
+ --- GD::Image#fill(x, y, color)
357
+
358
+ Flood a portion of the image with the specified ((|color|)), beginning
359
+ at the specified point (((|x|)),((|y|))) and flooding the surrounding
360
+ region of the same color as the starting point. See also
361
+ ((<GD::Image#fillToBorder>)).
362
+
363
+ --- GD::Image#filledPolygon(points, color)
364
+
365
+ Draw a filled polygon with the verticies specified, using the
366
+ ((|color|)) index specified. see also ((<GD::Image#polygon>)).
367
+
368
+ --- GD::Image#filledRectangle(x1, y1, x2, y2, color)
369
+
370
+ Draw a filled rectangle. See also ((<GD::Image#rectangle>)).
371
+
372
+ --- GD::Image#fillToBorder(x, y, border_color, color)
373
+
374
+ floods a portion of the image with the specified ((|color|)),
375
+ beginning at the specified point (((|x|)),((|y|))) and stopping at the
376
+ specified ((|border_color|)).
377
+
378
+ The ((|border_color|)) cannot be a special color such as
379
+ ((<GD::Tiled>)). It must be a proper solid color. However the fill
380
+ ((|color|)) can be a special color.
381
+
382
+ --- GD::Image#line(x1, y1, x2, y2, color)
383
+
384
+ Draw a line between two endpoints (((|x1|)),((|y1|))) and
385
+ (((|x2|)),((|y2|))). ((|color|)) is the color allocated by
386
+ ((<GD::Image#colorAllocate>)), or one of ((<GD::Styled>)),
387
+ ((<GD::Brushed>)), ((<GD::StyledBrushed>)).
388
+
389
+ --- GD::Image#polygon(points, color)
390
+
391
+ Draw a polygon with the verticies (at least 3) specified, using the
392
+ ((|color|)) index. ((|points|)) is ((:GD::Polygon:)) instance. After
393
+ you created the ((:GD::Polygon:)) instances and did some operation on
394
+ the vertices, the poligon is drawn with this method.
395
+
396
+ --- GD::Image#rectangle(x1, y1, x2, y2, color)
397
+
398
+ Draw a rectangle with two corners(upper left is (((|x1|)),((|y1|))),
399
+ lower right (((|x2|)), ((|y2|)))) with the specified ((|color|))
400
+ index.
401
+
402
+ --- GD::Image#setBrush(image)
403
+
404
+ Set a "brush"(an image used to draw wide, shaped strokes) to
405
+ ((|image|)). ((|image|)) can be any of ((:GD::Image:)) instance.By
406
+ setting the transparent color index of the brush image with
407
+ ((<GD::Image#transparent>)), a brush of any shape can be created. All
408
+ line-drawing methods, such as ((<GD::Image#line>)) and
409
+ ((<GD::Image#polygon>)), will use the current brush if the special
410
+ "color" ((<GD::Brushed>)) or ((<GD::StyledBrushed>)) is used when
411
+ invoking them.
412
+
413
+ As for any image instance, brush image must be destroyed by
414
+ ((<GD::Image#destroy>)).
415
+
416
+ --- GD::Image#setPixel(x, y, color)
417
+
418
+ Set the color of a pixel at (((|x|)),((|y|))) to ((|color|)) index.
419
+
420
+ --- GD::Image#setStyle(color1, color2, ...)
421
+
422
+ Set the series of colors to be drawn repeatedly during the drawing by
423
+ a method such as ((<GD::Image#line>)). Each element of ((|color|)) is
424
+ either the color index allocated by ((<GD::Image#colorAllocate>)), or
425
+ ((<GD::Transparent>)) if you want the color of the particular pixel
426
+ left unchanged.
427
+
428
+ --- GD::Image#setTile(image)
429
+
430
+ Set the image to be tiled. ((|image|)) can be any ((:GD::Image:)) instance.
431
+
432
+ + Copy and Merge
433
+
434
+ --- GD::Image#copy(dest_img, dest_X, dest_Y, self_X, self_Y, width, height)
435
+
436
+ Copy a portion of the image at (((|self_X, self_Y|))) with specified
437
+ ((|width|)) and ((|height|)) to (((|dest_X|)), ((|dest_Y|))) of
438
+ ((|dest_img|)).
439
+
440
+ --- GD::Image#copyMerge(dest_img, dest_X, dest_Y, self_X, self_Y, width, height, percent)
441
+
442
+ Copy the two images by an amount specified in the last parameter
443
+ ((|percent|)). Arguments except for this are identical to those of
444
+ ((<GD::Image#copy>)). If ((|percent|)) is equal to 100, then this
445
+ method will function identically to ((<GD::Image#copy>)) i.e. the
446
+ source image replaces the pixels in the destination. If the
447
+ ((|percent|)) = 0, no action is taken.
448
+
449
+ This feature is most useful to 'highlight' sections of an image by
450
+ merging a solid color with ((|percent|)) = 50.
451
+
452
+ --- GD::Image#copyMergeGray(dest_img, dest_X, dest_Y, self_X, self_Y, width, height, percent)
453
+
454
+ Identical to ((<GD::Image#copyMerge>)), except that when merging
455
+ images it preserves the hue of the source by converting the
456
+ destination pixels to grey scale before the copy operation.
457
+
458
+ --- GD::Image#copyResized(dest_img, dest_X, dest_Y, self_X, self_Y, self_width, self_height, dest_X, dest_Y)
459
+
460
+ Copy a portion of the image at (((|self_X, self_Y|))) with specified
461
+ ((|self_width|)) and ((|self_height|)) to ((|dest_img|)) at
462
+ (((|dest_X|)), ((|dest_Y|))) with specified ((|dest_width|)) and
463
+ ((|dest_height|)).
464
+
465
+ --- GD::Image#paletteCopy(dest)
466
+
467
+ Copies a palette to ((|dest|)) image, attempting to match the colors
468
+ in the target image to the colors in the palette of the self.
469
+
470
+ + Font and text handling
471
+
472
+ --- GD::Image#char(font, x, y, char, color)
473
+
474
+ Draws a single character ((|char|)) at (((|x|)), ((|y|))) with
475
+ specified ((|color|)). ((|font|)) is specified by one of
476
+ ((<GD::Font::TinyFont>)), ((<GD::Font::SmallFont>)),
477
+ ((<GD::Font::MediumFont>)), ((<GD::Font::LargeFont>)),
478
+ ((<GD::Font::GiantFont>)).
479
+
480
+ --- GD::Image#charUp(font, x, y, char, color)
481
+
482
+ Draws a single chracter ((|char|)) at (((|x|)), ((|y|))) with
483
+ specified ((|color|)). ((|char|)) is drawn in a vertical direction,
484
+ i.e. drawn with rotated in 90 degree. See also ((<GD::Image#char>)).
485
+
486
+ --- GD::Image#string(font, x, y, str, color)
487
+
488
+ Draws multiple characters ((|str|)) on the image with the specified
489
+ ((|color|)). ((|font|)) is specified by one of
490
+ ((<GD::Font::TinyFont>)), ((<GD::Font::SmallFont>)),
491
+ ((<GD::Font::MediumFont>)), ((<GD::Font::LargeFont>)),
492
+ ((<GD::Font::GiantFont>)), or ((:GD::Font:)) instance created by
493
+ ((<GD::Font.new>)).
494
+
495
+ --- GD::Image#stringUp(font, x, y, str, color)
496
+
497
+ Draw multiple characters ((|str|)) on the image with the specified
498
+ ((|color|)). ((|str|)) is drawn in a vertical direction, i.e. drawn
499
+ with rotated in 90 degree. See also ((<GD::Image#string>)).
500
+
501
+ --- GD::Image#stringTTF(fg_color, fnt_name, pt, angle, x, y, str)
502
+
503
+ (gd-1.6.1 or later)
504
+
505
+ Draws a string ((|str|)) at (((|x|)), ((|y|))) on the image using
506
+ user-supplied TrueType fonts with specified ((|fg_color|)). The
507
+ location of TrueType font ((|fnt_name|)) is specified by full path.
508
+ The string may be arbitrarily scaled at ((|pt|)) and rotated
509
+ (((|angle|)) in radians).
510
+
511
+ This method returns an array of 2 elements. the first element is the
512
+ error message string, the 2nd is ((*brect*)) of the bounding rectangle
513
+ with 8 elements. Each element of ((*brect*)) is illustrated as below:
514
+
515
+ (brect[6],brect[7]) (brect[4],brect[5])
516
+ +--------------------+
517
+ |( S t r i n g )|
518
+ +--------------------+
519
+ (brect[0],brect[1]) (brect[2],brect[3])
520
+
521
+ When the string is successfully drawn, error message is ((:nil:)).
522
+
523
+ If you only want to know the brect of the bounding rectangle, you can
524
+ use ((<GD::Image.stringTTF>)).
525
+
526
+ --- GD::Image#stringFT(fg_color, fnt_name, pt, angle, x, y, str)
527
+ (gd-1.8.4)
528
+
529
+ This method provides the same functionarity as
530
+ ((<GD::Image#stringTTF>)) does, but uses FreeType2 library when
531
+ redering the string.
532
+
533
+ + Query
534
+
535
+ --- GD::Image#bounds
536
+
537
+ Returns the width and height of the image as Array instance.
538
+
539
+ --- GD::Image#boundsSafe(x, y)
540
+
541
+ Returns ((:true:)) if specified point (((|x|)),((|y|))) is within the
542
+ bounds of the image. Otherwise return ((:false:)).
543
+
544
+ --- GD::Image#blue(idx)
545
+
546
+ Returns the blue component of the specified color index ((|idx|)).
547
+
548
+ --- GD::Image#colorsTotal
549
+
550
+ Returns the number of colors currently allocated in the image.
551
+
552
+ --- GD::Image#getTransparent
553
+
554
+ Returns the current transparent color index of the image. Returns -1
555
+ if there is no transparent color.
556
+
557
+ --- GD::Image#getPixel(x, y)
558
+
559
+ Returns the color index of a pixel at (((|x|)),((|y|)))).
560
+
561
+ --- GD::Image#green(idx)
562
+
563
+ Returns the green component of the specified color index ((|idx|)).
564
+
565
+ --- GD::Image#height
566
+
567
+ Returns the height of the image.
568
+
569
+ --- GD::Image#interlace
570
+
571
+ Returns ((:true:)) if the image is interlaced, and returns ((:false:)) otherwise.
572
+
573
+ --- GD::Image#red(idx)
574
+
575
+ Returns the red component of the specified color index ((|idx|)).
576
+
577
+ --- GD::Image#rgb(idx)
578
+
579
+ Returns array of the RGB values for the specified index ((|idx|)) of
580
+ the image.
581
+
582
+ --- GD::Image#width
583
+
584
+ Returns the width of the image.
585
+
586
+ + Output
587
+
588
+ --- GD::Image#gd(file)
589
+
590
+ Outputs the image to the specified ((|file|)) in Gd format.
591
+
592
+ --- GD::Image#gd2(file, chunk_size, fmt)
593
+
594
+ Outputs the image to the specified ((|file|)) in Gd2 format with
595
+ specified ((|chunk_size|)) and ((|fmt|)). A gd2 Image are stored as a
596
+ series of compressed/uncompressed subimages. You can specify
597
+ ((|chunk_size|)) which determines the size of the subimages. If
598
+ ((|chunk_size|)) is set zero, the default size is used. Whether the image
599
+ is compressed or uncompressed is determined by ((|fmt|)) being
600
+ ((<GD::GD2_FMT_COMPRESSED>)) or
601
+ ((<GD::GD2_FMT_RAW>)), respectively.
602
+
603
+ --- GD::Image#jpeg(file, quality)
604
+ (gd-1.8 or later)
605
+
606
+ Outputs the image to the specified ((|file|)) with ((|quality|)) in
607
+ Jpeg format. If ((|quality|)) is set to nagative, the default IJG JPEG
608
+ quality value (which should yield a good general quality size
609
+ trade-off for most situations) is used. For practical purposes,
610
+ quality should be a value in the range 0-95.
611
+
612
+ --- GD::Image#jpegStr(quality)
613
+ (gd-1.8 or later)
614
+
615
+ Outputs the Jpeg image as String object with specified ((|quality|)).
616
+ This method will be especially useful when you want to transmit an
617
+ image ((*directly*)) to an user(i.e, without first writing it to a
618
+ file).
619
+
620
+ This method is provided by Colin Steele(colin@webg2.com).
621
+
622
+ --- GD::Image#png(file)
623
+
624
+ Outputs the image to the specified ((|file|)) in PNG format.
625
+
626
+ --- GD::Image#pngStr(file)
627
+
628
+ Outputs the image in PNG format as String object. This method will be
629
+ especially useful when you want to transmit an image ((*directly*)) to
630
+ an user(i.e, without first writing it to a file).
631
+
632
+ --- GD::Image#gif(file)
633
+
634
+ Outputs the image to the specified ((|file|)) in GIF format.
635
+
636
+ --- GD::Image#gifStr(file)
637
+
638
+ Outputs the image in GIF format as String object. This method will be
639
+ especially useful when you want to transmit an image ((*directly*)) to
640
+ an user(i.e, without first writing it to a file).
641
+
642
+ --- GD::Image#wbmp(fg_color, file)
643
+ (gd-1.8 or later)
644
+
645
+ Outputs the specified image to the specified file in WBMP format.
646
+
647
+ WBMP file support is ((*black*)) and ((*white*)) only. The color index
648
+ specified by the ((|fg_color|)) argument is the "foreground," and only
649
+ pixels of this color will be set in the WBMP file. All other pixels
650
+ will be considered "background."
651
+
652
+
653
+ === gd-2.0.0 or higher
654
+
655
+ + Color handling
656
+
657
+ --- GD::Image#colorAllocateAlpha(r, g, b, alpha)
658
+ --- GD::Image#colorAllocateAlpha(rgbstr, alpha)
659
+
660
+ Finds the first available color index in the image specified, sets its
661
+ RGBA values to those requested and returns the index of the new color
662
+ table entry, or an RGBA value in the case of a truecolor image; in
663
+ either case you can then use the returned value as a parameter to
664
+ drawing functions. The ((|alpha|)) value takes between 0(opaque) and
665
+ 127(transparent).
666
+
667
+ See also ((<GD::Image#colorAllocate>)).
668
+
669
+ --- GD::Image#colorExactAlpha(r, g, b, alpha)
670
+ --- GD::Image#colorExactAlpha(rgbstr, alpha)
671
+
672
+ Searches the colors which have been defined thus far in the image
673
+ specified and returns the index of the first color entry which exactly
674
+ match those of the request, or an RGBA value in the case of a
675
+ truecolor image; in either case you can then use the returned value as
676
+ a parameter to drawing functions.The ((|alpha|)) value takes between
677
+ 0(opaque) and 127(transparent).
678
+
679
+ See also ((<GD::Image#colorExact>)).
680
+
681
+ --- GD::Image#colorClosestAlpha(r, g, b, alpha)
682
+ --- GD::Image#colorClosestAlpha(rgbstr, alpha)
683
+
684
+ Searches the colors which have been defined thus far in the palette
685
+ image specified and returns the index of the color with RGBA values
686
+ closest to those of the request. The ((|alpha|)) value takes between
687
+ 0(opaque) and 127(transparent).
688
+
689
+ Closeness is determined by Euclidian distance, which is used to
690
+ determine the distance in four-dimensional color/alpha space between
691
+ colors.
692
+
693
+ When applied to a truecolor image, this method always succeeds in
694
+ returning the desired color.
695
+
696
+ See also ((<GD::Image#colorClosest>)).
697
+
698
+ --- GD::Image#colorResolveAlpha(r, g, b, alpha)
699
+ --- GD::Image#colorResolveAlpha(rgbstr, alpha)
700
+
701
+ Searches the colors which have been defined thus far in the palette
702
+ image specified and returns the index of the first color with RGBA
703
+ values which exactly match those of the request. The ((|alpha|)) value
704
+ takes between 0(opaque) and 127(transparent).
705
+
706
+ If no allocated color matches the request precisely, then it tries to
707
+ allocate the exact color. If there is no space left in the color table
708
+ then it returns the closest color (as in
709
+ ((<GD::Image#closestAlpha>))).
710
+
711
+ This method always returns an index of a color. When applied to a
712
+ truecolor image, this function always succeeds in returning the
713
+ desired color.
714
+
715
+ See also ((<GD::Image#colorResolve>)).
716
+
717
+ --- GD::Image#alphaBlending=(bool)
718
+
719
+ Specifies the different modes for drawing on ((*truecolor*)) images.
720
+ When ((|bool|)) sets ((:true:))("blending mode"), how much of the
721
+ underlying color should be allowed to shine through is determined by
722
+ the alpha channel value of the color.
723
+
724
+ This blending mode is effective for the following drawing operations,
725
+ and in this mode, the existing color at the drawing point is blended
726
+ with drawing color with its alpha value.
727
+
728
+ When ((|bool|)) sets ((:false:))("non-blending mode"), the existing
729
+ color at the drawing point is replaced by the drawing color with its
730
+ own alpha value.
731
+
732
+ Note that this blending mode is not available when drawing on
733
+ ((*palette*)) images.
734
+
735
+ --- GD::Image#alpha(color)
736
+
737
+ Returns the alpha channel component (between 0 and 127) of the
738
+ specified color index.
739
+
740
+
741
+ + Image manipulation
742
+
743
+ --- GD::Image#copyResampled(dest_img, dest_X, dest_Y, self_X, self_Y, dest_width, dest_height, self_width, self_height)
744
+
745
+ Copies a rectangular portion of one image to another image, smoothly
746
+ interpolating pixel values so that, in particular, reducing the size
747
+ of an image still retains a great deal of clarity.
748
+
749
+ Pixel values are interpolated only if the destination image is a
750
+ truecolor image. Otherwise, for a palette image, the same
751
+ functionality as ((<GD::Image#copyResized>)) will be invoked.
752
+
753
+ See also ((<GD::Image#copyResized>)), for a version which does not
754
+ interpolate pixel values.
755
+
756
+ --- GD::Image#filledEllipse(cx, cy, width, height, start, end, color)
757
+
758
+ draws an ellipse centered at the given point (((|cx|)), ((|cy|))),
759
+ with the specified ((|width|)) and ((|height|)) in pixels.
760
+
761
+ The ellipse is filled in the ((|color|)) and is drawn by beginning
762
+ from ((|start|)) degrees and ending at ((|end|)) degrees. ((|end|))
763
+ must be greater than ((|start|)). Values greater than 360 are
764
+ interpreted modulo 360.
765
+
766
+ --- GD::Image#filledArc(cx, cy, width, height, start, end, color, style)
767
+
768
+ draws an partial ellipse(arc) centered at the given point (((|cx|)),
769
+ ((|cy|))), with the specified ((|width|)) and ((|height|)) in pixels,
770
+ and filled in the ((|color|)). The arc begins at ((|start|)) degrees
771
+ and ends at ((|end|)) degrees.
772
+
773
+ The last argument is bitwise (({OR})) of the following possibilities.
774
+
775
+ * (({GD::Arc}))
776
+
777
+ draws the rounded edge between ((|start|)) and ((|end|)).
778
+
779
+ * (({GD::Chord}))
780
+
781
+ draws the line connecting ((|start|)) and ((|end|)).
782
+
783
+ * (({GD::Pie}))
784
+
785
+ synonym for (({GD::Arc}))
786
+
787
+
788
+ * (({GD::NoFill}))
789
+
790
+ indicates Pie and Chord should be outlined, not filled.
791
+
792
+ * (({GD::Edged}))
793
+
794
+ used together with (({GD::NoFill})), indicates that the beginning and
795
+ ending angles should be connected to the center; this is a good way to
796
+ outline (rather than fill) a 'pie slice'.
797
+
798
+ --- GD::Image#to_paletteImage(dither_flag, colors)
799
+
800
+ transforms the truecolor image to palette image. If ((|dither_flag|))
801
+ is ((:true:)), the image will be dithered to approximate colors
802
+ better, at the expense of some obvious "speckling." ((|colors|)) may
803
+ be anything up to 256, but if the image includes the photographic
804
+ information, or is a JPEG image, 256 is strongly recommended.
805
+
806
+ + Query methods
807
+
808
+ --- GD::Image#is_trueColor?
809
+
810
+ returns ((:true:)) if the image is a truecolor image.
811
+
812
+ --- GD::Image#is_palette?
813
+
814
+ returns ((:true:)) if the image is a palette image.
815
+
816
+ --- GD::Image#thickness=(val)
817
+
818
+ specifies the line thickness (defaults to 1) that affects methods
819
+ drawing lines or curves.
820
+
821
+ = Class GD::Polygon
822
+
823
+ == Class Methods
824
+
825
+ --- GD::Polygon.new
826
+
827
+ Creates a new polygon instance. After some operations provided below,
828
+ the polygon is drawn on the image by ((<GD::Image#polygon>)) method.
829
+
830
+ == Methods
831
+
832
+ + Operation
833
+
834
+ --- GD::Polygon#addPt(x, y)
835
+
836
+ Adds a new point(vertex) from which the polygon is formed.
837
+
838
+ --- GD::Polygon#deletePt(idx)
839
+
840
+ Deletes the the specified ((|idx|))-th elements of the vertices.
841
+
842
+ --- GD::Polygon#getPt(idx)
843
+
844
+ Returns the value of the specified ((|idx|))-th elements of the
845
+ vertices.
846
+
847
+ --- GD::Polygon#map(dest_L, dest_T, dest_R, dest_B)
848
+ --- GD::Polygon#map([src_L, src_T, src_R, src_B,] dest_L, dest_T, dest_R, dest_B)
849
+
850
+ Maps the polygon from a source rectangle to an equivalent position in
851
+ a destination rectangle, moving it and resizing it as necessary. Both
852
+ the source and destination rectangles are given in
853
+ (left,top,right,bottom) coordinates. See figure below.
854
+
855
+ This method takes 4 or 8 arguments. Note that if 4 arguments are
856
+ given, source rectangle are automatically computed as the bounding box
857
+ of the poligon, and maps it to the destination rectangle specified in
858
+ the arguments.
859
+
860
+
861
+ <source rectangle> <destination rectangle>
862
+ (src_L, src_T) (dest_L, dest_T)
863
+ +--------------+ +----------+
864
+ | | | |
865
+ | | => | |
866
+ | | | |
867
+ +--------------+ | |
868
+ (src_R, src_B) +----------+
869
+ (dest_R, dest_B)
870
+
871
+ --- GD::Polygon#offset(dx, dy)
872
+
873
+ Offsets all the vertices of the polygon by ((|dx|)) pixels
874
+ horizontally and ((|dy|)) pixels vertically.
875
+
876
+ --- GD::Polygon#setPt(idx, new_x, new_y)
877
+
878
+ Changes the value of the specified ((|idx|))-th elements of the
879
+ vertices to (((|new_x|)), ((|new_y|))).
880
+
881
+ --- GD::Polygon#toPt(dx, dy)
882
+
883
+ Draw from current vertex to a new vertex, using relative (((|dx|)),
884
+ ((|dy|))) coordinates. If this is the first point, act like
885
+ ((<GD::Image#addPt>)).
886
+
887
+ --- GD::Polygon#scale(sx, sy)
888
+
889
+ Scales each vertex of the polygon by the X and Y factors indicated by
890
+ ((|sx|)) and ((|sy|)). For best results, move the center of the
891
+ polygon to position (0,0) before you scale, then move it back to its
892
+ previous position.
893
+
894
+ --- GD::Polygon#transform(sx,rx,sy,ry,tx,ty)
895
+
896
+ Runs each vertex of the polygon through a transformation matrix, where
897
+ ((|sx|)) and ((|sy|)) are the X and Y scaling factors, ((|rx|)) and
898
+ ((|ry|)) are the X and Y rotation factors, and ((|tx|)) and ((|ty|))
899
+ are X and Y offsets.
900
+
901
+ + Query
902
+
903
+ --- GD::Polygon#bounds
904
+
905
+ Returns the smallest rectangle that completely encloses the polygon.
906
+ The return value is an array containing the [left,top,right,bottom] of
907
+ the rectangle.
908
+
909
+ --- GD::Polygon#length
910
+
911
+ Returns the number of the vertices.
912
+
913
+ --- GD::Polygon#vertices
914
+
915
+ Returns all of the coodinates of the vertices as Array instance.
916
+
917
+ = Class GD::Font
918
+
919
+ == Class Methods
920
+
921
+ --- GD::Font.new(name)
922
+
923
+ Creates a new font instance. The font is specified by its
924
+ ((|name|)), which is one of "((*Tiny*))", "((*Small*))",
925
+ "((*Medium*))", "((*Large*))", "((*Giant*))". These strings correspond
926
+ to ((<GD::Font::TinyFont>)), ((<GD::Font::SmallFont>)),
927
+ ((<GD::Font::MediumFont>)), ((<GD::Font::LargeFont>)),
928
+ ((<GD::Font::GiantFont>)), respectively.
929
+
930
+ The instance becomes the arguments in the charcter/string drawing
931
+ method such as ((<GD::Image#char>)), ((<GD::Image#string>)).
932
+
933
+ == Methods
934
+
935
+ --- GD::Font#height
936
+
937
+ Returns the height of each character of the font.
938
+
939
+ --- GD::Font#nchars
940
+
941
+ Returns the number of characeters in the font.
942
+
943
+ --- GD::Font#offset
944
+
945
+ Returns the offset of the first character in the font.
946
+
947
+ --- GD::Font#width
948
+
949
+ Returns the width of each character of the font.
950
+
951
+ == Constants
952
+
953
+ These constants also becomes the arguments in the charcter/string
954
+ drawing method such as ((<GD::Image#char>)), ((<GD::Image#string>)).
955
+
956
+ --- GD::Font::GiantFont
957
+
958
+ This stands for 9x15 bold font:
959
+ -Misc-Fixed-Bold-R-Normal-Sans-15-140-75-75-C-90-ISO8859-2
960
+
961
+ --- GD::Font::LargeFont
962
+
963
+ This stands for the public domain 8x16 font:
964
+ -misc-fixed-medium-r-normal--16-140-75-75-c-80-iso8859-2
965
+
966
+ --- GD::Font::MediumFont
967
+
968
+ This stands for the a public domain 7x13 font:
969
+ -misc-fixed-bold-r-normal-sans-13-94-100-100-c-70-iso8859-2
970
+
971
+ --- GD::Font::SmallFont
972
+
973
+ This stands for a well known public domain 6x12 font:
974
+ -misc-fixed-medium-r-semicondensed-sans-12-116-75-75-c-60-iso8859-2
975
+
976
+ --- GD::Font::TinyFont
977
+
978
+ This stands for almost unreadable font, 5x8 pixels wide:
979
+ -Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO8859-2
980
+
981
+
982
+ = Reference
983
+
984
+ * index.html distributed with gd-1.8.4
985
+ * index.html distributed with gd-2.0.1
986
+ * gd.h distributed with gd-2.0.1
987
+ * documents embedded in GD.pm version 1.30
988
+
989
+ =end