ruby-gd-0.8.0/0000775000175000017500000000000011745022735011564 5ustar paulpaulruby-gd-0.8.0/metadata.yml0000664000175000017500000000226611745022735014075 0ustar paulpaul--- !ruby/object:Gem::Specification name: ruby-gd version: !ruby/object:Gem::Version version: 0.8.0 platform: ruby authors: - Ryuichi Tamura autorequire: GD bindir: bin cert_chain: [] date: 2008-07-08 00:00:00 +09:00 default_executable: dependencies: [] description: email: tam at kais dot kyoto-u dot ac dot jp executables: [] extensions: - extconf.rb extra_rdoc_files: - readme.en files: - Changes - extconf.rb - GD.c - readme.ja - readme.en - doc/INSTALL.ja - doc/manual.html - doc/manual.rd - doc/INSTALL.en - doc/manual_index.html - sample/webpng.rb - sample/gdtestttf.rb - sample/gdtestttf.png - sample/example.rb has_rdoc: true homepage: http://tam.0xfa.com/ruby-gd post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: "0" version: required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: "0" version: requirements: [] rubyforge_project: rubygems_version: 1.0.1 signing_key: specification_version: 2 summary: An interface to Boutell GD library test_files: [] ruby-gd-0.8.0/sample/0000775000175000017500000000000011745022735013045 5ustar paulpaulruby-gd-0.8.0/sample/example.rb0000644000175000017500000000112211745022735015017 0ustar paulpaul#!/usr/bin/env ruby require "GD" # create a new image im = GD::Image.new(100,100) # allocate some colors white = im.colorAllocate(255,255,255) black = im.colorAllocate(0,0,0) red = im.colorAllocate(255,0,0) blue = im.colorAllocate(0,0,255) # make the background transparent and interlaced im.transparent(white) im.interlace = true # Put a black frame around the picture im.rectangle(0,0,99,99,black) # Draw a blue oval im.arc(50,50,95,75,0,360,blue) # And fill it with red im.fill(50,50,red) # Convert the image to PNG and print it on standard output im.png STDOUT ruby-gd-0.8.0/sample/gdtestttf.png0000644000175000017500000000460511745022735015566 0ustar paulpaulPNG  IHDR,PLTE???l(C 1IDATx]Yv8`` X:agN&[OAYL>P@Лy'x H{a䗽 i1<m8c{C׽(3upͷȹr;bcH-}O-Cjpi{Zj̮45oְL@K ZycGRk v5Aj S; 5R>xSS)fSrCMԲjVxS7jNڿ}J.EBb?mQӦHQrPUt"ȎokD_]`jCg3Q.fjZTx1oZׁ\S+LZdJ“CPh@B#xC؃&!sj<[ǣt8j@?5#.a)S5U!j BX}ԢBHZXCg&Nbd=B4ij\o,.6t=RkuĸfWӺ^v >Fa.q >8PָGf]^#6F~ϸkRg4h.h![qɻ_x$^0%/CWX>4LbGvW֐];K>q̂ ?i}\#,.$&U],!9J..LT#:& H|ohNQ 9<]i}n ڑ@Re4$, $X L&v1H@S1aU,H,`u^v3T%X#"tqVTI̵k}U%oFZMŪNzAzu@&8uUf@]X/$W\`V3q[Lq3`A݋Qeվ|Y +a،˯[NzO*S6@WGxcSY{ :_c{xbάz7f 'OY̬)Cėp{ ~IWxqjEx*c+;e_W [Pv%Z,`Մu}7#P5}w$܍/K@i@c_Qk2{r:%5Eju&׏÷D-80j0ЂV >-Ri YetxmajԹܕːzGY5; N[% q"g"> ϡHaڈM"7(3`hά_ W&fREُ ж d}xb*:u%}"'OνJ 6U8ٴG]X+8#P(LЮn}I;J;PLd_ЯH-l7"QBMϬ7|$DjOPK{&xOJY].(!$`)Tc9MFK⃙"auo.eׇ&j_JcoJ!x/} H^t\ɵ"웒7жf2g]$Z+cN~גֲ>$h--̦ *J]$Zpi(jJoײ2u q!PA&ޢ2dc7mPSfL"}ዙ t 0Z[%9QWSԥ@^%]hN,R]Rmex՛W]LlU}.MR(b?՗`qݬg Ze-jf_#8}?+u5 7m_BR^u;-r5U(05sc>@PԎ_|'x'x+/Έx/IENDB`ruby-gd-0.8.0/sample/gdtestttf.rb0000644000175000017500000000205311745022735015400 0ustar paulpaul#! /usr/bin/env ruby =begin gdtestttf.rb - =end require 'GD' # change this to be suitable for your Environment fontpath = "/mnt/windows/FONTS/times.ttf" def deg2rad(degree) degree*(Math::PI/180.0) end def maxx(brect) [[brect[0],brect[2]].max, [brect[4],brect[6]].max].max end def maxy(brect) [[brect[1],brect[3]].max, [brect[5],brect[7]].max].max end def minx(brect) [[brect[0],brect[2]].min, [brect[4],brect[6]].min].min end def miny(brect) [[brect[1],brect[3]].min, [brect[5],brect[7]].min].min end str = "Ruby/GD version 0.7.2" angle = deg2rad(20) sz = 36.0 # obtain brect so that we can size the image err,brect = GD::Image.stringTTF(0, fontpath, sz, angle, 0, 0, str) if err puts err exit 1 end x = maxx(brect) - minx(brect) + 6 y = maxy(brect) - miny(brect) + 6 im = GD::Image.new(x,y) white = im.colorResolve(255,255,255) black = im.colorResolve(0,0,0) x = 0 - minx(brect) + 3 y = 0 - miny(brect) + 3 (err, brect) = im.stringTTF(black, fontpath, sz, angle, x, y, str) if err puts err exit 1 end im.png $stdout im.destroy ruby-gd-0.8.0/sample/webpng.rb0000644000175000017500000000425511745022735014660 0ustar paulpaul#! /usr/bin/env ruby =begin webpng.rb - =end require 'getopts' require 'GD' def usage $stderr.print < demoout.png) EOS exit 1 end usage if ARGV.size < 2 if ARGV[-1] == '-' useStdinStdout = true end # option parse usage unless getopts("ld", "i:", "t:", "help") usage if $OPT_help if $OPT_i usage unless $OPT_i == "y" or $OPT_i == "n" end if $OPT_t usage unless $OPT_t == "none" or ($OPT_t.to_i >= 0 and $OPT_t.to_i <= 255) end if useStdinStdout in_file = $stdin else in_fname = ARGV.pop in_file = File.open(in_fname, "rb") end im = GD::Image.newFromPng(in_file) in_file.close # options for information displaying and exiting if $OPT_l printf("Index\tRed\tGreen\tBlue\n") for j in 0 .. im.colorsTotal rgb_ary = im.rgb(j) printf("%d\t%d\t%d\t%d\n", j, rgb_ary[0], rgb_ary[1], rgb_ary[2]) end im.destroy exit 0 end if $OPT_d printf("Width: %d Height: %d Colors: %d\n",im.width, im.height, im.colorsTotal) t = im.getTransparent if t != -1 printf("Transparent index: %d\n", t) else puts "Transparent index: none"; # -1 means the image is not transparent. end if im.interlace puts "Interlaced: yes"; else puts "Interlaced: no"; end im.destroy exit 0 end # options for involving for output part if $OPT_i if $OPT_i == 'y' im.interlace = true # Set interlace else im.interlace = false # Clear interlace end end if $OPT_t if $OPT_t == 'none' im.transparent(-1) # -1 means not transparent else im.transparent($OPT_t.to_i) # OK, get an integer and set the index end end if useStdinStdout im.png $stdout else o_fname = "webpng.tmp"+$$.to_s ofile = open(o_fname, "wb") im.png ofile ofile.close File.delete in_fname File.rename o_fname, in_fname end im.destroy ruby-gd-0.8.0/doc/0000775000175000017500000000000011745022735012331 5ustar paulpaulruby-gd-0.8.0/doc/manual_index.html0000644000175000017500000001637011745022735015670 0ustar paulpaul Method Index --- manual.rmi

Method Index -- manual.rmi


GD
GD::Font
GD::Image
GD::Polygon
ruby-gd-0.8.0/doc/INSTALL.en0000644000175000017500000000415311745022735013764 0ustar paulpaul= Installation Guide == Requirements Ruby/GD requires version 1.6.0 or later of the gd library, and Ruby-1.4.0 or later. The latest version of gd is available from: http://www.boutell.com/gd/ The latest version of Ruby is available from: http://www.ruby-lang.org/ To build the extension library, at least the following libraries must be correctly installed in your system. * libpng * zlib = Install 1. To generate the Makefile with which Ruby/GD is build, issue this command from your prompt: ruby extconf.rb [options...] The following options can be specified: * --with-xpm If your gd has support for XPM format images, add this option. Note that libX11 and libXpm must be correctly installed in your system. * --with-ttf If your gd has support for TrueType fonts, add this option. Note that Freetype library must be correctly installed in your system. * --with-freetype If you want use the newest feature of font rendering provided by gd-1.8.4, add this option along with '--with-ttf'. Note that Freetype library must be correctly installed in your system. * --with-jpeg If your gd has support for JPEG format images, add this option. Note that libjpeg-6b or later must be correctly installed in your system. * --with-gd-include=[dir], --with-gd-lib=[dir] You can specify explicitly the location in which gd library is installed. EXAMPLE the case libgd.a and header files exist in "/home/foo/gd-1.8.4": $ ruby extconf.rb --with-gd-include=/home/foo/gd-1.8.4 --with-gd-lib=/home/foo/gd-1.8.4 * --enable-gd2_0 If you want to use the newest features (support for truecolor images, alpha channels, etc.) provided by gd-2.0.x from Ruby/GD, add this option. gd-2.0.x must be correctly installed on your system. 2. Build the extension library issue this command: $ make If successful, the library named "GD.so" is generated. 3. Install in your system type (if needed, as superuser) # make install or, # make site-install and GD.so will be correctly installed in your system. This finishes the installation. ruby-gd-0.8.0/doc/manual.rd0000644000175000017500000007616611745022735014153 0ustar paulpaul=begin = Ruby/GD Version 0.7.4 Ruby extension library for using Thomas Boutell's gd library(http://www.boutell.com/gd/). Originally written by Yukihiro Matsumoto (matz@ruby-lang.org) Current maintainer: Ryuichi Tamura (tam@kais.kyoto-u.ac.jp) ((* If gd-2.0.x is installed in your system, and Ruby/GD is compiled with (({--enable-gd2_0})) option, you can use those constants or methods described in the subsection "gd-2.0.0 or higher"*)) == Module/Class Hierarchy GD -+ | +- GD::Image | +- GD::Polygon | +- GD::Font = Module GD Module that defines some constants refered by GD::Image or GD::Polygon instances. == Constants --- GD::Brushed If this constant is used as the color when invoking a line-drawing method such as (()) or (()), the line to be drawn is the brush image that has been set with (()). --- GD::Styled If this constant is used as the color when invoking a line-drawing method such as (()) or (()), the colors of the pixels are drawn successively from the style that has been set with (()). If the color of a pixel is equal to (()), that pixel is not altered. --- GD::StyledBrushed If this constant is used as the color when invoking a line-drawing method such as (()) or (()), the brush set with (()) is drawn wherever the color specified in (()) is neither zero nor (()). --- GD::Tiled If this constant is used as the color when invoking a filling method such as (()), (()), (()), and (()). The area is filled with a tile image set with (()). --- GD::Transparent Used in place of a normal color in a style to be set with (()). This constant is not the transparent color index of the image; for that functionality, see (()). --- GD::GD2_FMT_COMPRESSED specifies Gd2 image to be compressed. This constant is used in (()). --- GD::GD2_FMT_RAW specifies Gd2 image to be uncompressed. This constant is used in (()). === gd-2.0.0 or higher --- GD::AlphaTransparent --- GD::AlphaOpaque These constants are used in (()), and each defines the upper(127) and lower(0) bounds of alpha channel value, respectively. Full transparency corresponds to GD::AlphaTransparent. --- GD::Arc --- GD::Chord --- GD::Pie --- GD::NoFill --- GD::Edged These constants become options that specify how an arc is drawn with using (()). See also (()). = Class GD::Image == Class Methods + Instance Creation --- GD::Image.new(width, height) creates a new palette image instance with specified ((|width|)) and ((|height|)). --- GD::Image.newFromGd(file) creates a new image instance from Gd file. ((|file|)) is a File object. --- GD::Image.new_from_gd(filename) creates a new Gd image instance from ((|filename|)). ((|filename|)) is a String object which specifies the localtion of the image file. --- GD::Image.newFromGd2(file) creates a new image instance from Gd2 file. ((|file|)) is a File object. --- GD::Image.new_from_gd2(filename) creates a new Gd2 image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. --- GD::Image.newFromGd2Part(file, srcX, srcY, width, height) creates a new image instance from part of Gd2 file. ((|file|)) is a File object. --- GD::Image.new_from_gd2_part(filename) creates a new Gd2 image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. --- GD::Image.newFromJpeg(file) (gd-1.8 or later) Creates a new image instance from JPEG file. ((|file|)) is a File object. --- GD::Image.new_from_jpeg(filename) creates a new Jpeg image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. --- GD::Image.newFromPng(file) creates a new image instance from PNG file. ((|file|)) is a File object. --- GD::Image.new_from_png(filename) creates a new PNG image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. --- GD::Image.newFromGif(file) creates a new image instance from GIF file. ((|file|)) is a File object. --- GD::Image.new_from_gif(filename) creates a new GIF image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. --- GD::Image.newFromXbm(file) creates a new image instance from Xbm file. ((|file|)) is a File object. --- GD::Image.new_from_xbm(filename) creates a new XBitmap image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. --- GD::Image.newFromXpm(file) (gd-1.7 or later) creates a new image instance from Xpm file. ((|file|)) is a File object. --- GD::Image.new_from_xpm(filename) creates a new XPixmaps image instance from ((|filename|)). ((|filename|)) is a String object which specifies the location of the image file. + Query --- GD::Image.stringTTF(fg_color, fnt_name, pt, angle, x, y, str) (gd-1.6.1 or later) Tries to find the bounding rectangle of ((|str|)) with size (((|pt|))) and the name of the TrueType font(((|fnt_name|))), and returns the array consists of the error message string and the array of each vertex of the rectangle(brect[8], see the figure in the section of (())). If successful, the error message is ((:nil:)). See also (()). --- GD::Image.stringFT(fg_color, fnt_name, pt, angle, x, y, str) (gd-1.8.4) This method provides the same functionarity as (()) does, but uses FreeType2 library when redering the string. See also (()) === gd-2.0.0 or higher --- GD::Image.newTrueColor(width, height) Creates a new truecolor image instance with specified ((|width|)) and ((|height|)). --- GD::Image.trueColor(r, g, b) --- GD::Image.trueColor(rgbstr) returns the RGBA color value for drawing on a truecolor image, or an image created by (()). ((|r|)), ((|g|)), ((|b|)) values are in the range between 0 and 255. Or, you can specify it by ((|rgbstr|)) which is in the range between "#000000" and "#FFFFFF". --- GD::Image.trueColor(r, g, b, alpha) --- GD::Image.trueColorAlpha(rgbstr, alpha) returns the RGBA color value for drawing on a truecolor image, or an image created by (()) with alpha channel transparency. Because gd has 7-bit alpha channel, the ((|alpha|)) value takes between 0(opaque) and 127(transparent). These class methods are used for ((*truecolor*)) images. If you want to specify alpha value for ((*palette*)) images, use (()), (()), (()), or (()) instead. == Methods --- GD::Image#destroy Free the memory associated with the image instance. --- GD::Image#interlace=(val) If ((|val|)) is ((:true:)), the image is interlaced. Otherwise and by default, the image is not interlaced. === Color Handling --- GD::Image#colorAllocate(r, g, b) --- GD::Image#colorAllocate(str) Finds the first available color index in the image instance, and sets its RGB values to ((|r|)), ((|g|)), ((|b|)), respectively and returns the index of the new color table entry. ((|r|)), ((|g|)), ((|b|)) take a value between 0 and 255. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF". Note that the first time you invoke this method after creating a new image by (()), ((*the background color*)) of the image is set. You can allocate upto 256 colors to one image. If there is no space to allocate the requested color, this returns -1. If you use gd-1.6.2 or later, you can use (()), more robust way of color allocation. --- GD::Image#colorClosest(r, g, b) --- GD::Image#colorClosest(str) Searches the colors which have been defined thus far in the image instance and returns the index of the color with RGB values closest to ((|r|)), ((|g|)), ((|b|)), respectively. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF".If no color have been yet allocated to that image, this returns -1 This method is useful when a image instance which you want to allocate a new color is created from the image scanned from a photograph in which many colors will be used. --- GD::Image#colorDeallocate(color) This marks the ((|color|)) at the specified index as being ripe for reallocation. The next time (()) is used, this entry will be replaced. You can call this method several times to deallocate multiple colors. --- GD::Image#colorExact(r, g, b) --- GD::Image#colorExact(str) Searches the colors which have been defined thus far in the image instance and returns the index of the first color with RGB values which exactly match (((|r|)), ((|g|)), ((|b|))). If no allocated color matches the request precisely, this returns -1. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF". --- GD::Image#colorResolve(r, g, b) --- GD::Image#colorResolve(str) (gd-1.6.2 or later) Searches the colors which have been defined thus far in the image specified and returns the index of the first color with RGB values which exactly match those of the request. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF". If no allocated color matches the request precisely, then this method tries to allocate the exact color.If there is no space left in the color table then this method returns the closest color (as in (())). Unlike (()), this method always returns an index of a color. --- GD::Image#transparent(idx) Sets the transparent color index for the specified image to the specified color index ((|idx|)). To indicate that there should be no transparent color, set ((|idx|)) to -1. Note that JPEG images ((*do not support*)) transparency, so this setting has no effect when writing JPEG images. + Drawing and Filling --- GD::Image#arc(cx, cy, width, height, start, end, color) Draw a partial ellipse centered at the given point (((|cx|)),((|cy|))) with specified width ((|width|)) and height ((|height|)) in pixel with specified ((|color|)). The arc begins at the position in degrees specified by ((|start|)) and ends at the position specified by ((|end|)). --- GD::Image#dashedLine(x1, y1, x2, y2, color) This method is provided solely for backwards compatibility of the Boutell's gd library. When drawing a dashed line, new programs should use (()) with (()). --- GD::Image#fill(x, y, color) Flood a portion of the image with the specified ((|color|)), beginning at the specified point (((|x|)),((|y|))) and flooding the surrounding region of the same color as the starting point. See also (()). --- GD::Image#filledPolygon(points, color) Draw a filled polygon with the verticies specified, using the ((|color|)) index specified. see also (()). --- GD::Image#filledRectangle(x1, y1, x2, y2, color) Draw a filled rectangle. See also (()). --- GD::Image#fillToBorder(x, y, border_color, color) floods a portion of the image with the specified ((|color|)), beginning at the specified point (((|x|)),((|y|))) and stopping at the specified ((|border_color|)). The ((|border_color|)) cannot be a special color such as (()). It must be a proper solid color. However the fill ((|color|)) can be a special color. --- GD::Image#line(x1, y1, x2, y2, color) Draw a line between two endpoints (((|x1|)),((|y1|))) and (((|x2|)),((|y2|))). ((|color|)) is the color allocated by (()), or one of (()), (()), (()). --- GD::Image#polygon(points, color) Draw a polygon with the verticies (at least 3) specified, using the ((|color|)) index. ((|points|)) is ((:GD::Polygon:)) instance. After you created the ((:GD::Polygon:)) instances and did some operation on the vertices, the poligon is drawn with this method. --- GD::Image#rectangle(x1, y1, x2, y2, color) Draw a rectangle with two corners(upper left is (((|x1|)),((|y1|))), lower right (((|x2|)), ((|y2|)))) with the specified ((|color|)) index. --- GD::Image#setBrush(image) Set a "brush"(an image used to draw wide, shaped strokes) to ((|image|)). ((|image|)) can be any of ((:GD::Image:)) instance.By setting the transparent color index of the brush image with (()), a brush of any shape can be created. All line-drawing methods, such as (()) and (()), will use the current brush if the special "color" (()) or (()) is used when invoking them. As for any image instance, brush image must be destroyed by (()). --- GD::Image#setPixel(x, y, color) Set the color of a pixel at (((|x|)),((|y|))) to ((|color|)) index. --- GD::Image#setStyle(color1, color2, ...) Set the series of colors to be drawn repeatedly during the drawing by a method such as (()). Each element of ((|color|)) is either the color index allocated by (()), or (()) if you want the color of the particular pixel left unchanged. --- GD::Image#setTile(image) Set the image to be tiled. ((|image|)) can be any ((:GD::Image:)) instance. + Copy and Merge --- GD::Image#copy(dest_img, dest_X, dest_Y, self_X, self_Y, width, height) Copy a portion of the image at (((|self_X, self_Y|))) with specified ((|width|)) and ((|height|)) to (((|dest_X|)), ((|dest_Y|))) of ((|dest_img|)). --- GD::Image#copyMerge(dest_img, dest_X, dest_Y, self_X, self_Y, width, height, percent) Copy the two images by an amount specified in the last parameter ((|percent|)). Arguments except for this are identical to those of (()). If ((|percent|)) is equal to 100, then this method will function identically to (()) i.e. the source image replaces the pixels in the destination. If the ((|percent|)) = 0, no action is taken. This feature is most useful to 'highlight' sections of an image by merging a solid color with ((|percent|)) = 50. --- GD::Image#copyMergeGray(dest_img, dest_X, dest_Y, self_X, self_Y, width, height, percent) Identical to (()), except that when merging images it preserves the hue of the source by converting the destination pixels to grey scale before the copy operation. --- GD::Image#copyResized(dest_img, dest_X, dest_Y, self_X, self_Y, self_width, self_height, dest_X, dest_Y) Copy a portion of the image at (((|self_X, self_Y|))) with specified ((|self_width|)) and ((|self_height|)) to ((|dest_img|)) at (((|dest_X|)), ((|dest_Y|))) with specified ((|dest_width|)) and ((|dest_height|)). --- GD::Image#paletteCopy(dest) Copies a palette to ((|dest|)) image, attempting to match the colors in the target image to the colors in the palette of the self. + Font and text handling --- GD::Image#char(font, x, y, char, color) Draws a single character ((|char|)) at (((|x|)), ((|y|))) with specified ((|color|)). ((|font|)) is specified by one of (()), (()), (()), (()), (()). --- GD::Image#charUp(font, x, y, char, color) Draws a single chracter ((|char|)) at (((|x|)), ((|y|))) with specified ((|color|)). ((|char|)) is drawn in a vertical direction, i.e. drawn with rotated in 90 degree. See also (()). --- GD::Image#string(font, x, y, str, color) Draws multiple characters ((|str|)) on the image with the specified ((|color|)). ((|font|)) is specified by one of (()), (()), (()), (()), (()), or ((:GD::Font:)) instance created by (()). --- GD::Image#stringUp(font, x, y, str, color) Draw multiple characters ((|str|)) on the image with the specified ((|color|)). ((|str|)) is drawn in a vertical direction, i.e. drawn with rotated in 90 degree. See also (()). --- GD::Image#stringTTF(fg_color, fnt_name, pt, angle, x, y, str) (gd-1.6.1 or later) Draws a string ((|str|)) at (((|x|)), ((|y|))) on the image using user-supplied TrueType fonts with specified ((|fg_color|)). The location of TrueType font ((|fnt_name|)) is specified by full path. The string may be arbitrarily scaled at ((|pt|)) and rotated (((|angle|)) in radians). This method returns an array of 2 elements. the first element is the error message string, the 2nd is ((*brect*)) of the bounding rectangle with 8 elements. Each element of ((*brect*)) is illustrated as below: (brect[6],brect[7]) (brect[4],brect[5]) +--------------------+ |( S t r i n g )| +--------------------+ (brect[0],brect[1]) (brect[2],brect[3]) When the string is successfully drawn, error message is ((:nil:)). If you only want to know the brect of the bounding rectangle, you can use (()). --- GD::Image#stringFT(fg_color, fnt_name, pt, angle, x, y, str) (gd-1.8.4) This method provides the same functionarity as (()) does, but uses FreeType2 library when redering the string. + Query --- GD::Image#bounds Returns the width and height of the image as Array instance. --- GD::Image#boundsSafe(x, y) Returns ((:true:)) if specified point (((|x|)),((|y|))) is within the bounds of the image. Otherwise return ((:false:)). --- GD::Image#blue(idx) Returns the blue component of the specified color index ((|idx|)). --- GD::Image#colorsTotal Returns the number of colors currently allocated in the image. --- GD::Image#getTransparent Returns the current transparent color index of the image. Returns -1 if there is no transparent color. --- GD::Image#getPixel(x, y) Returns the color index of a pixel at (((|x|)),((|y|)))). --- GD::Image#green(idx) Returns the green component of the specified color index ((|idx|)). --- GD::Image#height Returns the height of the image. --- GD::Image#interlace Returns ((:true:)) if the image is interlaced, and returns ((:false:)) otherwise. --- GD::Image#red(idx) Returns the red component of the specified color index ((|idx|)). --- GD::Image#rgb(idx) Returns array of the RGB values for the specified index ((|idx|)) of the image. --- GD::Image#width Returns the width of the image. + Output --- GD::Image#gd(file) Outputs the image to the specified ((|file|)) in Gd format. --- GD::Image#gd2(file, chunk_size, fmt) Outputs the image to the specified ((|file|)) in Gd2 format with specified ((|chunk_size|)) and ((|fmt|)). A gd2 Image are stored as a series of compressed/uncompressed subimages. You can specify ((|chunk_size|)) which determines the size of the subimages. If ((|chunk_size|)) is set zero, the default size is used. Whether the image is compressed or uncompressed is determined by ((|fmt|)) being (()) or (()), respectively. --- GD::Image#jpeg(file, quality) (gd-1.8 or later) Outputs the image to the specified ((|file|)) with ((|quality|)) in Jpeg format. If ((|quality|)) is set to nagative, the default IJG JPEG quality value (which should yield a good general quality size trade-off for most situations) is used. For practical purposes, quality should be a value in the range 0-95. --- GD::Image#jpegStr(quality) (gd-1.8 or later) Outputs the Jpeg image as String object with specified ((|quality|)). 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). This method is provided by Colin Steele(colin@webg2.com). --- GD::Image#png(file) Outputs the image to the specified ((|file|)) in PNG format. --- GD::Image#pngStr(file) 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). --- GD::Image#gif(file) Outputs the image to the specified ((|file|)) in GIF format. --- GD::Image#gifStr(file) Outputs the image in GIF 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). --- GD::Image#wbmp(fg_color, file) (gd-1.8 or later) Outputs the specified image to the specified file in WBMP format. WBMP file support is ((*black*)) and ((*white*)) only. The color index specified by the ((|fg_color|)) argument is the "foreground," and only pixels of this color will be set in the WBMP file. All other pixels will be considered "background." === gd-2.0.0 or higher + Color handling --- GD::Image#colorAllocateAlpha(r, g, b, alpha) --- GD::Image#colorAllocateAlpha(rgbstr, alpha) Finds the first available color index in the image specified, sets its RGBA values to those requested and returns the index of the new color table entry, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions. The ((|alpha|)) value takes between 0(opaque) and 127(transparent). See also (()). --- GD::Image#colorExactAlpha(r, g, b, alpha) --- GD::Image#colorExactAlpha(rgbstr, alpha) Searches the colors which have been defined thus far in the image specified and returns the index of the first color entry which exactly match those of the request, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions.The ((|alpha|)) value takes between 0(opaque) and 127(transparent). See also (()). --- GD::Image#colorClosestAlpha(r, g, b, alpha) --- GD::Image#colorClosestAlpha(rgbstr, alpha) Searches the colors which have been defined thus far in the palette image specified and returns the index of the color with RGBA values closest to those of the request. The ((|alpha|)) value takes between 0(opaque) and 127(transparent). Closeness is determined by Euclidian distance, which is used to determine the distance in four-dimensional color/alpha space between colors. When applied to a truecolor image, this method always succeeds in returning the desired color. See also (()). --- GD::Image#colorResolveAlpha(r, g, b, alpha) --- GD::Image#colorResolveAlpha(rgbstr, alpha) Searches the colors which have been defined thus far in the palette image specified and returns the index of the first color with RGBA values which exactly match those of the request. The ((|alpha|)) value takes between 0(opaque) and 127(transparent). If no allocated color matches the request precisely, then it tries to allocate the exact color. If there is no space left in the color table then it returns the closest color (as in (())). This method always returns an index of a color. When applied to a truecolor image, this function always succeeds in returning the desired color. See also (()). --- GD::Image#alphaBlending=(bool) Specifies the different modes for drawing on ((*truecolor*)) images. When ((|bool|)) sets ((:true:))("blending mode"), how much of the underlying color should be allowed to shine through is determined by the alpha channel value of the color. This blending mode is effective for the following drawing operations, and in this mode, the existing color at the drawing point is blended with drawing color with its alpha value. When ((|bool|)) sets ((:false:))("non-blending mode"), the existing color at the drawing point is replaced by the drawing color with its own alpha value. Note that this blending mode is not available when drawing on ((*palette*)) images. --- GD::Image#alpha(color) Returns the alpha channel component (between 0 and 127) of the specified color index. + Image manipulation --- GD::Image#copyResampled(dest_img, dest_X, dest_Y, self_X, self_Y, dest_width, dest_height, self_width, self_height) Copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. Pixel values are interpolated only if the destination image is a truecolor image. Otherwise, for a palette image, the same functionality as (()) will be invoked. See also (()), for a version which does not interpolate pixel values. --- GD::Image#filledEllipse(cx, cy, width, height, start, end, color) draws an ellipse centered at the given point (((|cx|)), ((|cy|))), with the specified ((|width|)) and ((|height|)) in pixels. The ellipse is filled in the ((|color|)) and is drawn by beginning from ((|start|)) degrees and ending at ((|end|)) degrees. ((|end|)) must be greater than ((|start|)). Values greater than 360 are interpreted modulo 360. --- GD::Image#filledArc(cx, cy, width, height, start, end, color, style) draws an partial ellipse(arc) centered at the given point (((|cx|)), ((|cy|))), with the specified ((|width|)) and ((|height|)) in pixels, and filled in the ((|color|)). The arc begins at ((|start|)) degrees and ends at ((|end|)) degrees. The last argument is bitwise (({OR})) of the following possibilities. * (({GD::Arc})) draws the rounded edge between ((|start|)) and ((|end|)). * (({GD::Chord})) draws the line connecting ((|start|)) and ((|end|)). * (({GD::Pie})) synonym for (({GD::Arc})) * (({GD::NoFill})) indicates Pie and Chord should be outlined, not filled. * (({GD::Edged})) used together with (({GD::NoFill})), indicates that the beginning and ending angles should be connected to the center; this is a good way to outline (rather than fill) a 'pie slice'. --- GD::Image#to_paletteImage(dither_flag, colors) transforms the truecolor image to palette image. If ((|dither_flag|)) is ((:true:)), the image will be dithered to approximate colors better, at the expense of some obvious "speckling." ((|colors|)) may be anything up to 256, but if the image includes the photographic information, or is a JPEG image, 256 is strongly recommended. + Query methods --- GD::Image#is_trueColor? returns ((:true:)) if the image is a truecolor image. --- GD::Image#is_palette? returns ((:true:)) if the image is a palette image. --- GD::Image#thickness=(val) specifies the line thickness (defaults to 1) that affects methods drawing lines or curves. = Class GD::Polygon == Class Methods --- GD::Polygon.new Creates a new polygon instance. After some operations provided below, the polygon is drawn on the image by (()) method. == Methods + Operation --- GD::Polygon#addPt(x, y) Adds a new point(vertex) from which the polygon is formed. --- GD::Polygon#deletePt(idx) Deletes the the specified ((|idx|))-th elements of the vertices. --- GD::Polygon#getPt(idx) Returns the value of the specified ((|idx|))-th elements of the vertices. --- GD::Polygon#map(dest_L, dest_T, dest_R, dest_B) --- GD::Polygon#map([src_L, src_T, src_R, src_B,] dest_L, dest_T, dest_R, dest_B) Maps the polygon from a source rectangle to an equivalent position in a destination rectangle, moving it and resizing it as necessary. Both the source and destination rectangles are given in (left,top,right,bottom) coordinates. See figure below. This method takes 4 or 8 arguments. Note that if 4 arguments are given, source rectangle are automatically computed as the bounding box of the poligon, and maps it to the destination rectangle specified in the arguments. (src_L, src_T) (dest_L, dest_T) +--------------+ +----------+ | | | | | | => | | | | | | +--------------+ | | (src_R, src_B) +----------+ (dest_R, dest_B) --- GD::Polygon#offset(dx, dy) Offsets all the vertices of the polygon by ((|dx|)) pixels horizontally and ((|dy|)) pixels vertically. --- GD::Polygon#setPt(idx, new_x, new_y) Changes the value of the specified ((|idx|))-th elements of the vertices to (((|new_x|)), ((|new_y|))). --- GD::Polygon#toPt(dx, dy) Draw from current vertex to a new vertex, using relative (((|dx|)), ((|dy|))) coordinates. If this is the first point, act like (()). --- GD::Polygon#scale(sx, sy) Scales each vertex of the polygon by the X and Y factors indicated by ((|sx|)) and ((|sy|)). For best results, move the center of the polygon to position (0,0) before you scale, then move it back to its previous position. --- GD::Polygon#transform(sx,rx,sy,ry,tx,ty) Runs each vertex of the polygon through a transformation matrix, where ((|sx|)) and ((|sy|)) are the X and Y scaling factors, ((|rx|)) and ((|ry|)) are the X and Y rotation factors, and ((|tx|)) and ((|ty|)) are X and Y offsets. + Query --- GD::Polygon#bounds Returns the smallest rectangle that completely encloses the polygon. The return value is an array containing the [left,top,right,bottom] of the rectangle. --- GD::Polygon#length Returns the number of the vertices. --- GD::Polygon#vertices Returns all of the coodinates of the vertices as Array instance. = Class GD::Font == Class Methods --- GD::Font.new(name) Creates a new font instance. The font is specified by its ((|name|)), which is one of "((*Tiny*))", "((*Small*))", "((*Medium*))", "((*Large*))", "((*Giant*))". These strings correspond to (()), (()), (()), (()), (()), respectively. The instance becomes the arguments in the charcter/string drawing method such as (()), (()). == Methods --- GD::Font#height Returns the height of each character of the font. --- GD::Font#nchars Returns the number of characeters in the font. --- GD::Font#offset Returns the offset of the first character in the font. --- GD::Font#width Returns the width of each character of the font. == Constants These constants also becomes the arguments in the charcter/string drawing method such as (()), (()). --- GD::Font::GiantFont This stands for 9x15 bold font: -Misc-Fixed-Bold-R-Normal-Sans-15-140-75-75-C-90-ISO8859-2 --- GD::Font::LargeFont This stands for the public domain 8x16 font: -misc-fixed-medium-r-normal--16-140-75-75-c-80-iso8859-2 --- GD::Font::MediumFont This stands for the a public domain 7x13 font: -misc-fixed-bold-r-normal-sans-13-94-100-100-c-70-iso8859-2 --- GD::Font::SmallFont This stands for a well known public domain 6x12 font: -misc-fixed-medium-r-semicondensed-sans-12-116-75-75-c-60-iso8859-2 --- GD::Font::TinyFont This stands for almost unreadable font, 5x8 pixels wide: -Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO8859-2 = Reference * index.html distributed with gd-1.8.4 * index.html distributed with gd-2.0.1 * gd.h distributed with gd-2.0.1 * documents embedded in GD.pm version 1.30 =end ruby-gd-0.8.0/doc/manual.html0000644000175000017500000015266111745022735014505 0ustar paulpaul manual

Ruby/GD Version 0.7.4

Ruby extension library for using Thomas Boutell's gd library(http://www.boutell.com/gd/).

Originally written by Yukihiro Matsumoto (matz@ruby-lang.org)

Current maintainer: Ryuichi Tamura (tam@kais.kyoto-u.ac.jp)

If gd-2.0.x is installed in your system, and Ruby/GD is compiled with --enable-gd2_0 option, you can use those constants or methods described in the subsection "gd-2.0.0 or higher"

Module/Class Hierarchy

GD -+
    |
    +- GD::Image
    |
    +- GD::Polygon
    |
    +- GD::Font

Module GD

Module that defines some constants refered by GD::Image or GD::Polygon instances.

Constants

GD::Brushed

If this constant is used as the color when invoking a line-drawing method such as GD::Image#line or GD::Image#rectangle, the line to be drawn is the brush image that has been set with GD::Image#setBrush.

GD::Styled

If this constant is used as the color when invoking a line-drawing method such as GD::Image#line or GD::Image#rectangle, the colors of the pixels are drawn successively from the style that has been set with GD::Image#setStyle. If the color of a pixel is equal to GD::Transparent, that pixel is not altered.

GD::StyledBrushed

If this constant is used as the color when invoking a line-drawing method such as GD::Image#line or GD::Image#rectangle, the brush set with GD::Image#setBrush is drawn wherever the color specified in GD::Image#setStyle is neither zero nor GD::Transparent.

GD::Tiled

If this constant is used as the color when invoking a filling method such as GD::Image#filledRectangle, GD::Image#filledPolygon, GD::Image#fill, and GD::Image#fillToBorder. The area is filled with a tile image set with GD::Image#setTile.

GD::Transparent

Used in place of a normal color in a style to be set with GD::Image#setStyle. This constant is not the transparent color index of the image; for that functionality, see GD::Image#transparent.

GD::GD2_FMT_COMPRESSED

specifies Gd2 image to be compressed. This constant is used in GD::Image#gd2.

GD::GD2_FMT_RAW

specifies Gd2 image to be uncompressed. This constant is used in GD::Image#gd2.

gd-2.0.0 or higher

GD::AlphaTransparent
GD::AlphaOpaque

These constants are used in GD::Image.trueColorAlpha, and each defines the upper(127) and lower(0) bounds of alpha channel value, respectively. Full transparency corresponds to GD::AlphaTransparent.

GD::Arc
GD::Chord
GD::Pie
GD::NoFill
GD::Edged

These constants become options that specify how an arc is drawn with using GD::Image#filledArc. See also GD::Image#filledArc.

Class GD::Image

Class Methods

Instance Creation
GD::Image.new(width, height)

creates a new palette image instance with specified width and height.

GD::Image.newFromGd(file)

creates a new image instance from Gd file. file is a File object.

GD::Image.new_from_gd(filename)

creates a new Gd image instance from filename. filename is a String object which specifies the localtion of the image file.

GD::Image.newFromGd2(file)

creates a new image instance from Gd2 file. file is a File object.

GD::Image.new_from_gd2(filename)

creates a new Gd2 image instance from filename. filename is a String object which specifies the location of the image file.

GD::Image.newFromGd2Part(file, srcX, srcY, width, height)

creates a new image instance from part of Gd2 file. file is a File object.

GD::Image.new_from_gd2_part(filename)

creates a new Gd2 image instance from filename. filename is a String object which specifies the location of the image file.

GD::Image.newFromJpeg(file)

(gd-1.8 or later)

Creates a new image instance from JPEG file. file is a File object.

GD::Image.new_from_jpeg(filename)

creates a new Jpeg image instance from filename. filename is a String object which specifies the location of the image file.

GD::Image.newFromPng(file)

creates a new image instance from PNG file. file is a File object.

GD::Image.new_from_png(filename)

creates a new PNG image instance from filename. filename is a String object which specifies the location of the image file.

GD::Image.newFromXbm(file)

creates a new image instance from Xbm file. file is a File object.

GD::Image.new_from_xbm(filename)

creates a new XBitmap image instance from filename. filename is a String object which specifies the location of the image file.

GD::Image.newFromXpm(file)

(gd-1.7 or later)

creates a new image instance from Xpm file. file is a File object.

GD::Image.new_from_xpm(filename)

creates a new XPixmaps image instance from filename. filename is a String object which specifies the location of the image file.

Query
GD::Image.stringTTF(fg_color, fnt_name, pt, angle, x, y, str)

(gd-1.6.1 or later)

Tries to find the bounding rectangle of str with size (pt) and the name of the TrueType font(fnt_name), and returns the array consists of the error message string and the array of each vertex of the rectangle(brect[8], see the figure in the section of GD::Image#stringTTF). If successful, the error message is nil. See also GD::Image#stringTTF.

GD::Image.stringFT(fg_color, fnt_name, pt, angle, x, y, str)

(gd-1.8.4)

This method provides the same functionarity as GD::Image.stringTTF does, but uses FreeType2 library when redering the string. See also GD::Image#stringFT

gd-2.0.0 or higher

GD::Image.newTrueColor(width, height)

Creates a new truecolor image instance with specified width and height.

GD::Image.trueColor(r, g, b)
GD::Image.trueColor(rgbstr)

returns the RGBA color value for drawing on a truecolor image, or an image created by GD::Image.newTrueColor. r, g, b values are in the range between 0 and 255. Or, you can specify it by rgbstr which is in the range between "#000000" and "#FFFFFF".

GD::Image.trueColor(r, g, b, alpha)
GD::Image.trueColorAlpha(rgbstr, alpha)

returns the RGBA color value for drawing on a truecolor image, or an image created by GD::Image.newTrueColor with alpha channel transparency. Because gd has 7-bit alpha channel, the alpha value takes between 0(opaque) and 127(transparent).

These class methods are used for truecolor images. If you want to specify alpha value for palette images, use GD::Image#colorAllocateAlpha, GD::Image#colorExactAlpha, GD::Image#colorClosestAlpha, or GD::Image#colorResolveAlpha instead.

Methods

GD::Image#destroy

Free the memory associated with the image instance.

GD::Image#interlace=(val)

If val is true, the image is interlaced. Otherwise and by default, the image is not interlaced.

Color Handling

GD::Image#colorAllocate(r, g, b)
GD::Image#colorAllocate(str)

Finds the first available color index in the image instance, and sets its RGB values to r, g, b, respectively and returns the index of the new color table entry. r, g, b take a value between 0 and 255. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF".

Note that the first time you invoke this method after creating a new image by GD::Image.new, the background color of the image is set.

You can allocate upto 256 colors to one image. If there is no space to allocate the requested color, this returns -1.

If you use gd-1.6.2 or later, you can use GD::Image#colorResolve, more robust way of color allocation.

GD::Image#colorClosest(r, g, b)
GD::Image#colorClosest(str)

Searches the colors which have been defined thus far in the image instance and returns the index of the color with RGB values closest to r, g, b, respectively. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF".If no color have been yet allocated to that image, this returns -1

This method is useful when a image instance which you want to allocate a new color is created from the image scanned from a photograph in which many colors will be used.

GD::Image#colorDeallocate(color)

This marks the color at the specified index as being ripe for reallocation. The next time GD::Image#colorAllocate is used, this entry will be replaced. You can call this method several times to deallocate multiple colors.

GD::Image#colorExact(r, g, b)
GD::Image#colorExact(str)

Searches the colors which have been defined thus far in the image instance and returns the index of the first color with RGB values which exactly match (r, g, b). If no allocated color matches the request precisely, this returns -1. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF".

GD::Image#colorResolve(r, g, b)
GD::Image#colorResolve(str)

(gd-1.6.2 or later)

Searches the colors which have been defined thus far in the image specified and returns the index of the first color with RGB values which exactly match those of the request. Also, if you use Ruby-1.6.0 or later, you can specify a color as strings like "#FF00FF".

If no allocated color matches the request precisely, then this method tries to allocate the exact color.If there is no space left in the color table then this method returns the closest color (as in GD::Image#colorClosest).

Unlike GD::Image#colorAllocate, this method always returns an index of a color.

GD::Image#transparent(idx)

Sets the transparent color index for the specified image to the specified color index idx. To indicate that there should be no transparent color, set idx to -1.

Note that JPEG images do not support transparency, so this setting has no effect when writing JPEG images.

Drawing and Filling
GD::Image#arc(cx, cy, width, height, start, end, color)

Draw a partial ellipse centered at the given point (cx,cy) with specified width width and height height in pixel with specified color. The arc begins at the position in degrees specified by start and ends at the position specified by end.

GD::Image#dashedLine(x1, y1, x2, y2, color)

This method is provided solely for backwards compatibility of the Boutell's gd library. When drawing a dashed line, new programs should use GD::Image#line with GD::Image#setStyle.

GD::Image#fill(x, y, color)

Flood a portion of the image with the specified color, beginning at the specified point (x,y) and flooding the surrounding region of the same color as the starting point. See also GD::Image#fillToBorder.

GD::Image#filledPolygon(points, color)

Draw a filled polygon with the verticies specified, using the color index specified. see also GD::Image#polygon.

GD::Image#filledRectangle(x1, y1, x2, y2, color)

Draw a filled rectangle. See also GD::Image#rectangle.

GD::Image#fillToBorder(x, y, border_color, color)

floods a portion of the image with the specified color, beginning at the specified point (x,y) and stopping at the specified border_color.

The border_color cannot be a special color such as GD::Tiled. It must be a proper solid color. However the fill color can be a special color.

GD::Image#line(x1, y1, x2, y2, color)

Draw a line between two endpoints (x1,y1) and (x2,y2). color is the color allocated by GD::Image#colorAllocate, or one of GD::Styled, GD::Brushed, GD::StyledBrushed.

GD::Image#polygon(points, color)

Draw a polygon with the verticies (at least 3) specified, using the color index. points is GD::Polygon instance. After you created the GD::Polygon instances and did some operation on the vertices, the poligon is drawn with this method.

GD::Image#rectangle(x1, y1, x2, y2, color)

Draw a rectangle with two corners(upper left is (x1,y1), lower right (x2, y2)) with the specified color index.

GD::Image#setBrush(image)

Set a "brush"(an image used to draw wide, shaped strokes) to image. image can be any of GD::Image instance.By setting the transparent color index of the brush image with GD::Image#transparent, a brush of any shape can be created. All line-drawing methods, such as GD::Image#line and GD::Image#polygon, will use the current brush if the special "color" GD::Brushed or GD::StyledBrushed is used when invoking them.

As for any image instance, brush image must be destroyed by GD::Image#destroy.

GD::Image#setPixel(x, y, color)

Set the color of a pixel at (x,y) to color index.

GD::Image#setStyle(color1, color2, ...)

Set the series of colors to be drawn repeatedly during the drawing by a method such as GD::Image#line. Each element of color is either the color index allocated by GD::Image#colorAllocate, or GD::Transparent if you want the color of the particular pixel left unchanged.

GD::Image#setTile(image)

Set the image to be tiled. image can be any GD::Image instance.

Copy and Merge
GD::Image#copy(dest_img, dest_X, dest_Y, self_X, self_Y, width, height)

Copy a portion of the image at (self_X, self_Y) with specified width and height to (dest_X, dest_Y) of dest_img.

GD::Image#copyMerge(dest_img, dest_X, dest_Y, self_X, self_Y, width, height, percent)

Copy the two images by an amount specified in the last parameter percent. Arguments except for this are identical to those of GD::Image#copy. If percent is equal to 100, then this method will function identically to GD::Image#copy i.e. the source image replaces the pixels in the destination. If the percent = 0, no action is taken.

This feature is most useful to 'highlight' sections of an image by merging a solid color with percent = 50.

GD::Image#copyMergeGray(dest_img, dest_X, dest_Y, self_X, self_Y, width, height, percent)

Identical to GD::Image#copyMerge, except that when merging images it preserves the hue of the source by converting the destination pixels to grey scale before the copy operation.

GD::Image#copyResized(dest_img, dest_X, dest_Y, self_X, self_Y, self_width, self_height, dest_X, dest_Y)

Copy a portion of the image at (self_X, self_Y) with specified self_width and self_height to dest_img at (dest_X, dest_Y) with specified dest_width and dest_height.

GD::Image#paletteCopy(dest)

Copies a palette to dest image, attempting to match the colors in the target image to the colors in the palette of the self.

Font and text handling
GD::Image#char(font, x, y, char, color)

Draws a single character char at (x, y) with specified color. font is specified by one of GD::Font::TinyFont, GD::Font::SmallFont, GD::Font::MediumFont, GD::Font::LargeFont, GD::Font::GiantFont.

GD::Image#charUp(font, x, y, char, color)

Draws a single chracter char at (x, y) with specified color. char is drawn in a vertical direction, i.e. drawn with rotated in 90 degree. See also GD::Image#char.

GD::Image#string(font, x, y, str, color)

Draws multiple characters str on the image with the specified color. font is specified by one of GD::Font::TinyFont, GD::Font::SmallFont, GD::Font::MediumFont, GD::Font::LargeFont, GD::Font::GiantFont, or GD::Font instance created by GD::Font.new.

GD::Image#stringUp(font, x, y, str, color)

Draw multiple characters str on the image with the specified color. str is drawn in a vertical direction, i.e. drawn with rotated in 90 degree. See also GD::Image#string.

GD::Image#stringTTF(fg_color, fnt_name, pt, angle, x, y, str)

(gd-1.6.1 or later)

Draws a string str at (x, y) on the image using user-supplied TrueType fonts with specified fg_color. The location of TrueType font fnt_name is specified by full path. The string may be arbitrarily scaled at pt and rotated (angle in radians).

This method returns an array of 2 elements. the first element is the error message string, the 2nd is brect of the bounding rectangle with 8 elements. Each element of brect is illustrated as below:

(brect[6],brect[7])   (brect[4],brect[5]) 
         +--------------------+
         |( S  t  r  i  n  g )|
         +--------------------+
(brect[0],brect[1])   (brect[2],brect[3])

When the string is successfully drawn, error message is nil.

If you only want to know the brect of the bounding rectangle, you can use GD::Image.stringTTF.

GD::Image#stringFT(fg_color, fnt_name, pt, angle, x, y, str)

(gd-1.8.4)

This method provides the same functionarity as GD::Image#stringTTF does, but uses FreeType2 library when redering the string.

Query
GD::Image#bounds

Returns the width and height of the image as Array instance.

GD::Image#boundsSafe(x, y)

Returns true if specified point (x,y) is within the bounds of the image. Otherwise return false.

GD::Image#blue(idx)

Returns the blue component of the specified color index idx.

GD::Image#colorsTotal

Returns the number of colors currently allocated in the image.

GD::Image#getTransparent

Returns the current transparent color index of the image. Returns -1 if there is no transparent color.

GD::Image#getPixel(x, y)

Returns the color index of a pixel at (x,y)).

GD::Image#green(idx)

Returns the green component of the specified color index idx.

GD::Image#height

Returns the height of the image.

GD::Image#interlace

Returns true if the image is interlaced, and returns false otherwise.

GD::Image#red(idx)

Returns the red component of the specified color index idx.

GD::Image#rgb(idx)

Returns array of the RGB values for the specified index idx of the image.

GD::Image#width

Returns the width of the image.

Output
GD::Image#gd(file)

Outputs the image to the specified file in Gd format.

GD::Image#gd2(file, chunk_size, fmt)

Outputs the image to the specified file in Gd2 format with specified chunk_size and fmt. A gd2 Image are stored as a series of compressed/uncompressed subimages. You can specify chunk_size which determines the size of the subimages. If chunk_size is set zero, the default size is used. Whether the image is compressed or uncompressed is determined by fmt being GD::GD2_FMT_COMPRESSED or GD::GD2_FMT_RAW, respectively.

GD::Image#jpeg(file, quality)

(gd-1.8 or later)

Outputs the image to the specified file with quality in Jpeg format. If quality is set to nagative, the default IJG JPEG quality value (which should yield a good general quality size trade-off for most situations) is used. For practical purposes, quality should be a value in the range 0-95.

GD::Image#jpegStr(quality)

(gd-1.8 or later)

Outputs the Jpeg image as String object with specified quality. 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).

This method is provided by Colin Steele(colin@webg2.com).

GD::Image#png(file)

Outputs the image to the specified file in PNG format.

GD::Image#pngStr(file)

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).

GD::Image#wbmp(fg_color, file)

(gd-1.8 or later)

Outputs the specified image to the specified file in WBMP format.

WBMP file support is black and white only. The color index specified by the fg_color argument is the "foreground," and only pixels of this color will be set in the WBMP file. All other pixels will be considered "background."

gd-2.0.0 or higher

Color handling
GD::Image#colorAllocateAlpha(r, g, b, alpha)
GD::Image#colorAllocateAlpha(rgbstr, alpha)

Finds the first available color index in the image specified, sets its RGBA values to those requested and returns the index of the new color table entry, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions. The alpha value takes between 0(opaque) and 127(transparent).

See also GD::Image#colorAllocate.

GD::Image#colorExactAlpha(r, g, b, alpha)
GD::Image#colorExactAlpha(rgbstr, alpha)

Searches the colors which have been defined thus far in the image specified and returns the index of the first color entry which exactly match those of the request, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions.The alpha value takes between 0(opaque) and 127(transparent).

See also GD::Image#colorExact.

GD::Image#colorClosestAlpha(r, g, b, alpha)
GD::Image#colorClosestAlpha(rgbstr, alpha)

Searches the colors which have been defined thus far in the palette image specified and returns the index of the color with RGBA values closest to those of the request. The alpha value takes between 0(opaque) and 127(transparent).

Closeness is determined by Euclidian distance, which is used to determine the distance in four-dimensional color/alpha space between colors.

When applied to a truecolor image, this method always succeeds in returning the desired color.

See also GD::Image#colorClosest.

GD::Image#colorResolveAlpha(r, g, b, alpha)
GD::Image#colorResolveAlpha(rgbstr, alpha)

Searches the colors which have been defined thus far in the palette image specified and returns the index of the first color with RGBA values which exactly match those of the request. The alpha value takes between 0(opaque) and 127(transparent).

If no allocated color matches the request precisely, then it tries to allocate the exact color. If there is no space left in the color table then it returns the closest color (as in GD::Image#closestAlpha).

This method always returns an index of a color. When applied to a truecolor image, this function always succeeds in returning the desired color.

See also GD::Image#colorResolve.

GD::Image#alphaBlending=(bool)

Specifies the different modes for drawing on truecolor images. When bool sets true("blending mode"), how much of the underlying color should be allowed to shine through is determined by the alpha channel value of the color.

This blending mode is effective for the following drawing operations, and in this mode, the existing color at the drawing point is blended with drawing color with its alpha value.

When bool sets false("non-blending mode"), the existing color at the drawing point is replaced by the drawing color with its own alpha value.

Note that this blending mode is not available when drawing on palette images.

GD::Image#alpha(color)

Returns the alpha channel component (between 0 and 127) of the specified color index.

Image manipulation
GD::Image#copyResampled(dest_img, dest_X, dest_Y, self_X, self_Y, dest_width, dest_height, self_width, self_height)

Copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

Pixel values are interpolated only if the destination image is a truecolor image. Otherwise, for a palette image, the same functionality as GD::Image#copyResized will be invoked.

See also GD::Image#copyResized, for a version which does not interpolate pixel values.

GD::Image#filledEllipse(cx, cy, width, height, start, end, color)

draws an ellipse centered at the given point (cx, cy), with the specified width and height in pixels.

The ellipse is filled in the color and is drawn by beginning from start degrees and ending at end degrees. end must be greater than start. Values greater than 360 are interpreted modulo 360.

GD::Image#filledArc(cx, cy, width, height, start, end, color, style)

draws an partial ellipse(arc) centered at the given point (cx, cy), with the specified width and height in pixels, and filled in the color. The arc begins at start degrees and ends at end degrees.

The last argument is bitwise OR of the following possibilities.

  • GD::Arc

draws the rounded edge between start and end.

  • GD::Chord

draws the line connecting start and end.

  • GD::Pie

synonym for GD::Arc

  • GD::NoFill

indicates Pie and Chord should be outlined, not filled.

  • GD::Edged

used together with GD::NoFill, indicates that the beginning and ending angles should be connected to the center; this is a good way to outline (rather than fill) a 'pie slice'.

GD::Image#to_paletteImage(dither_flag, colors)

transforms the truecolor image to palette image. If dither_flag is true, the image will be dithered to approximate colors better, at the expense of some obvious "speckling." colors may be anything up to 256, but if the image includes the photographic information, or is a JPEG image, 256 is strongly recommended.

Query methods
GD::Image#is_trueColor?

returns true if the image is a truecolor image.

GD::Image#is_palette?

returns true if the image is a palette image.

GD::Image#thickness=(val)

specifies the line thickness (defaults to 1) that affects methods drawing lines or curves.

Class GD::Polygon

Class Methods

GD::Polygon.new

Creates a new polygon instance. After some operations provided below, the polygon is drawn on the image by GD::Image#polygon method.

Methods

Operation
GD::Polygon#addPt(x, y)

Adds a new point(vertex) from which the polygon is formed.

GD::Polygon#deletePt(idx)

Deletes the the specified idx-th elements of the vertices.

GD::Polygon#getPt(idx)

Returns the value of the specified idx-th elements of the vertices.

GD::Polygon#map(dest_L, dest_T, dest_R, dest_B)
GD::Polygon#map([src_L, src_T, src_R, src_B,] dest_L, dest_T, dest_R, dest_B)

Maps the polygon from a source rectangle to an equivalent position in a destination rectangle, moving it and resizing it as necessary. Both the source and destination rectangles are given in (left,top,right,bottom) coordinates. See figure below.

This method takes 4 or 8 arguments. Note that if 4 arguments are given, source rectangle are automatically computed as the bounding box of the poligon, and maps it to the destination rectangle specified in the arguments.

<source rectangle>            <destination rectangle>
(src_L, src_T)                  (dest_L, dest_T)                
        +--------------+                  +----------+        
        |              |                  |          |
        |              |        =>        |          |        
        |              |                  |          |        
        +--------------+                  |          |
               (src_R, src_B)             +----------+ 
                                              (dest_R, dest_B)
GD::Polygon#offset(dx, dy)

Offsets all the vertices of the polygon by dx pixels horizontally and dy pixels vertically.

GD::Polygon#setPt(idx, new_x, new_y)

Changes the value of the specified idx-th elements of the vertices to (new_x, new_y).

GD::Polygon#toPt(dx, dy)

Draw from current vertex to a new vertex, using relative (dx, dy) coordinates. If this is the first point, act like GD::Image#addPt.

GD::Polygon#scale(sx, sy)

Scales each vertex of the polygon by the X and Y factors indicated by sx and sy. For best results, move the center of the polygon to position (0,0) before you scale, then move it back to its previous position.

GD::Polygon#transform(sx,rx,sy,ry,tx,ty)

Runs each vertex of the polygon through a transformation matrix, where sx and sy are the X and Y scaling factors, rx and ry are the X and Y rotation factors, and tx and ty are X and Y offsets.

Query
GD::Polygon#bounds

Returns the smallest rectangle that completely encloses the polygon. The return value is an array containing the [left,top,right,bottom] of the rectangle.

GD::Polygon#length

Returns the number of the vertices.

GD::Polygon#vertices

Returns all of the coodinates of the vertices as Array instance.

Class GD::Font

Class Methods

GD::Font.new(name)

Creates a new font instance. The font is specified by its name, which is one of "Tiny", "Small", "Medium", "Large", "Giant". These strings correspond to GD::Font::TinyFont, GD::Font::SmallFont, GD::Font::MediumFont, GD::Font::LargeFont, GD::Font::GiantFont, respectively.

The instance becomes the arguments in the charcter/string drawing method such as GD::Image#char, GD::Image#string.

Methods

GD::Font#height

Returns the height of each character of the font.

GD::Font#nchars

Returns the number of characeters in the font.

GD::Font#offset

Returns the offset of the first character in the font.

GD::Font#width

Returns the width of each character of the font.

Constants

These constants also becomes the arguments in the charcter/string drawing method such as GD::Image#char, GD::Image#string.

GD::Font::GiantFont

This stands for 9x15 bold font:

-Misc-Fixed-Bold-R-Normal-Sans-15-140-75-75-C-90-ISO8859-2
GD::Font::LargeFont

This stands for the public domain 8x16 font:

-misc-fixed-medium-r-normal--16-140-75-75-c-80-iso8859-2
GD::Font::MediumFont

This stands for the a public domain 7x13 font:

-misc-fixed-bold-r-normal-sans-13-94-100-100-c-70-iso8859-2
GD::Font::SmallFont

This stands for a well known public domain 6x12 font:

-misc-fixed-medium-r-semicondensed-sans-12-116-75-75-c-60-iso8859-2
GD::Font::TinyFont

This stands for almost unreadable font, 5x8 pixels wide:

-Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO8859-2

Reference

  • index.html distributed with gd-1.8.4
  • index.html distributed with gd-2.0.1
  • gd.h distributed with gd-2.0.1
  • documents embedded in GD.pm version 1.30
ruby-gd-0.8.0/doc/INSTALL.ja0000644000175000017500000000500011745022735013744 0ustar paulpaul= Ruby/GD Υ󥹥ȡˡ == ɬפʥ饤֥γǧ ޤȤgd饤֥versionǧƲRuby/GD ˤPNGϤǽgd-1.6.0ʾ夬ɬפǤޤRuby1.4ʾ Ʋ ǿǤgd饤֥ϼWebȤꤹ뤳ȤǤޤ http://www.boutell.com/gd/ Ǥgd饤֥κˡˤĤƤϽҤ٤ޤ󡥤ξܺ٤źդ ƤMakefileɤDz RubyκǿǤϼWebȤꤹ뤳ȤǤޤ http://www.ruby-lang.org/ Ǿɬפʳ饤֥ϼ̤Ǥ PNG饤֥(libpng)zlib饤֥ == 󥹥ȡ 1. ĥ饤֥ѤMakefile롥 ץץȤ $ ruby extconf.rb [options...] ǤäƤ [options...] ˤϰʲΥץꤹ뤳ȤǤޤ * --with-xpm Ȥ gd version 1.7ʾǡXpm ե뤫Ϥ򥵥ݡȤ ƤʤСΥץղäƲX11饤֥ꡤXpm饤 ꤬󥹥ȡ뤵Ƥɬפޤ * --with-ttf Ȥ gd TrueTypeեȤμ갷򥵥ݡȤƤʤС ΥץղäƲFreetype饤֥꤬󥹥ȡ뤵 Ƥɬפޤ * --with-freetype gd-1.8.4 顢TruetTypeեȤѤˡFreeType 2.x ٤ʸ褬ǽȤʤޤ εǽѤˤϡ'--with-ttf' ץȤȤˡ ΥץɲäƲ FreeType 2.x 饤֥꤬󥹥ȡ뤵졢gd Υ饤֥ 󥯤Ƥɬפޤ * --with-jpeg Ȥ gd version 1.8 ʾǡJpegե뤫Ϥб ʤСΥץղäƲlibjpeg-6bʹߤ ȡ뤵Ƥɬפޤ * --with-gd-include=[dir], --with-gd-lib=[dir] gd.hlibgd.a¸ߤ򤳤2ĤˤäŪ˻ꤹ뤳Ȥ ޤ ) /home/foo/gd-1.8.3 libgd.aإåե뤬 $ ruby extconf.rb --with-gd-include=/home/foo/gd-1.8.3 --with-gd-lib=/home/foo/gd-1.8.3 * --enable-gd2_0 gd-2.0.xǤϡTrueColor᡼䡢եͥŬڤ˰ ¿εǽɲäƤޤRuby/GD餳εǽѤ ΥץղäƲgd-2.0.x 󥹥ȡ뤵Ƥ ɬפޤ 2. ĥ饤֥롥 ץץȤ $ make ǤäƤӥɤ "GD.so" ޤ 3. 󥹥ȡ # make install ޤ # make site-install ǤƤСĥ饤֥Υ󥹥ȡ뤬λޤѡ桼 ¤ɬפ⤷ޤ ruby-gd-0.8.0/readme.en0000644000175000017500000000337711745022735013355 0ustar paulpaul= Ruby/GD 0.7.4 An extension library to use Thomas Boutell's gd graphics library from Ruby. You can create PNG, GIF or JPEG images with your Ruby script. Ruby/GD requires gd library with PNG support(i.e. the version 1.6 or later). See 'doc/INSTALL.en' for detail. The latest version is available from: http://kirara.prec.kyoto-u.ac.jp/~tam/GD/ Ruby/GD is formerly known as "GD", originally written and maintained by Yukihiro "matz" Matsumoto (matz@ruby-lang.org). From this release of 0.7.0, Ruby/GD is maintained by Ryuichi Tamura (tam@kais.kyoto-u.ac.jp). == Changes from the version 0.7.4 * restored GIF I/O, provided by the gd-2.0.28 or later. == Changes from the version 0.6.2 * GIF I/O are no longer supported. You can use PNG I/O instead. * Support for API provided by the newest version of gd (gd-1.8.4). == Contents readme.en this file readme.ja Japanese version of this file extconf.rb ruby script generating Makefile for this extension library GD.c source file doc/INSTALL.en how to install (in English) doc/INSTALL.ja how to install (in Japanese) doc/manual.rd Reference manual written with RD format doc/manual.html manual converted into HTML sample/example.rb sample script to show the basic usage of Ruby/GD library sample/gdtestttf.rb translated Ruby script from gdtestttf.c sample/gdtestttf.png ./gdtestttf.rb > gdtestttf.png sample/webpng.rb translated Ruby script from webpng.c == Install see 'doc/INSTALL.en' == Reference see 'doc/manual.html' == Licence Ruby Library Licence == Maintainer Ryuichi Tamura (tam@kais.kyoto-u.ac.jp) Bug reports, comments, suggestions to this maintainer are welcome, but ruby-talk mailing list would be the best place for discussion :-). ruby-gd-0.8.0/readme.ja0000644000175000017500000000510211745022735013331 0ustar paulpaul= Ruby/GD 0.7.4 Thomas Boutellˤgd饤֥RubyѤ뤿γĥ饤֥ ǤPNGGIFJPEGեޥåȤΥ᡼ڤ˺뤳ȤǤޤ Ruby/GDϤȤ"GD"̾Τ ޤĤ 椭Ҥ(matz@ruby-lang.org) ˤäƳȯӥƥʥ󥹤ԤƤޤθ塤ܲgdεǽ ѹ/ĥȼäơRuby᡼󥰥ꥹȥС¿Υѥ 󶡤ޤ Version 0.7.0 ǤGD-0.6.2ȤˤΥѥåߡĤ̤ бεǽɲäޤ̾ΤGDRuby/GDѹƤޤ ǿǤ http://kirara.prec.kyoto-u.ac.jp/~tam/GD/ ꤹ뤳Ȥ Ǥޤ == 0.7.4μѹ * GIFݡȤκƳ gd饤֥2.0.28ʹߡGIF᡼ϤѤǤ褦 ʤޤ˽äơRuby/GDGIF˴ؤ륵ݡȤƳޤ == С(ΡGD-0.6.2.tar.gz)μѹ * GIFݡȤǤڤ gd饤֥version 1.6ʹߡGIF᡼ϥݡȤߤ PNG(Portable Network Graphics)᡼б褦ˤʤä ޤ˽äơRuby/GD 0.7.0GIF˴ؤ륵ݡȤƼʧ ޤäơRuby/GD gd-1.4 ʤGIFݡȤԤgd饤֥ бƤޤ * ǿgdεǽˤб gd-2.0ʹߤDzǽȤʤä TrueColor᡼䥢եͥΰ бƤޤ == ʪ readme.ja Υե롣 readme.en ΥեαѸǡ extconf.rb ĥ饤֥Makefileץ GD.c doc/INSTALL.ja 󥹥ȡˡ(ܸ) doc/INSTALL.en 󥹥ȡˡ(English) doc/manual.rd ޥ˥奢(English) RDեޥåȤǽ񤫤Ƥޤ doc/manual.html Υޥ˥奢HTMLѴΡ doc/manual_index.html ᥽åɤκե롣 doc/manual.css ޥ˥奢Υ륷ȡ sample/example.rb Ruby/GD δŪʻȤ򼨤ץ륹ץ sample/gdtestttf.rb gd-1.8.3 ˴ޤޤgdtestttf.cRuby˰ܿΡ sample/gdtestttf.png ./gdtestttf.rb > gdtestttf.png sample/webpng.rb gd-1.8.3 ˴ޤޤwebpng.c Ruby˰ܿΡ == 󥹥ȡˡ 'doc/INSTALL.ja' ɤ߲ == ɥ 'doc/manual.html' 򻲾ȤƲ == ۾ Ruby Library License ˽ޤ == ƥ ¼ ζ(tam@kais.kyoto-u.ac.jp) ХȡƤʤɤRuby ᡼󥰥ꥹȤƤ뤫⤷ 嵭Υƥʤޤǥ᡼äƤ == ռ * GDĥ饤֥θԤǤ餻ޤĤ 椭Ҥ * GD-0.6.2 ꡼ʹߥѥå줿¼ŵ̤ǽˤ󡥤 GD 饤֥ȯŸΤˤϤ줿Ruby ᡼󥰥ꥹȤγ͡ ruby-gd-0.8.0/GD.c0000644000175000017500000017213311745022735012227 0ustar paulpaul/************************************************************* GD.c - Ruby extension library to use Boutell's gd library. Originally written: Yukihiro Matsumoto (matz@ruby-lang.org) Current maintainer: Ryuichi Tamura (tam@kais.kyoto-u.ac.jp) $Date: 2001/05/30 14:06:40 $ $Revision: 1.6.2.3 $ **************************************************************/ #include "ruby.h" #include "rubyio.h" #include "version.h" #include "gd.h" #include "gdfontg.h" /* giant */ #include "gdfontl.h" /* large */ #include "gdfontmb.h" /* medium bold */ #include "gdfonts.h" /* small */ #include "gdfontt.h" /* tiny */ extern VALUE rb_io_binmode(VALUE io); extern gdImagePtr gdImageCreateFromXpm(char* ); static VALUE mGD, cImage, cFont, cPolygon; #ifdef ENABLE_GD_2_0 static VALUE is_truecolor(im) gdImagePtr im; { return im->trueColor ? Qtrue : Qfalse; } #endif /* ENABLE_GD_2_0 */ static void free_img(iptr) gdImagePtr iptr; { if (iptr) { gdImageDestroy(iptr); } } static VALUE img_s_new(klass, w, h) VALUE klass, w, h; { gdImagePtr iptr; if (NUM2INT(w)<0 || NUM2INT(h)<0) rb_raise(rb_eArgError, "Negative width/height not allowed"); iptr = gdImageCreate(NUM2INT(w), NUM2INT(h)); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_pngfname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromPng(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid PNG File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_png(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromPng(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid PNG File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } #ifdef ENABLE_GD_2_0 static VALUE img_from_giffname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGif(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid GIF File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_gif(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGif(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid GIF File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } #endif /* ENABLE_GD_2_0 */ static VALUE img_from_gdfname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGd(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Gd File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_gd(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGd(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Gd File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_gd2fname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGd2(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_gd2(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGd2(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_gd2_partfname(klass, fname, srcx, srcy, w, h) VALUE klass, fname, srcx, srcy, w, h; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGd2Part(fptr->f, NUM2INT(srcx), NUM2INT(srcy), NUM2INT(w), NUM2INT(h)); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_gd2_part(klass, f, srcx, srcy, w, h) VALUE klass, f, srcx, srcy, w, h; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromGd2Part(fptr->f, NUM2INT(srcx), NUM2INT(srcy), NUM2INT(w), NUM2INT(h)); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_xbm(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromXbm(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Xbm File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_xbmfname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromXbm(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Xbm File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } #ifdef HAVE_GDIMAGECREATEFROMXPM static VALUE img_from_xpm(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); /* need cast, and the argument is char* type */ iptr = (gdImagePtr)gdImageCreateFromXpm(fptr->path); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid XPM File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_xpmfname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); /* need cast, and the argument is char* type */ iptr = (gdImagePtr)gdImageCreateFromXpm(fptr->path); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid XPM File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } #endif #ifdef HAVE_GDIMAGECREATEFROMJPEG static VALUE img_from_jpeg(klass, f) VALUE klass, f; { OpenFile *fptr; gdImagePtr iptr; Check_Type(f, T_FILE); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromJpeg(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Jpeg File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_from_jpegfname(klass, fname) VALUE klass, fname; { VALUE f; OpenFile *fptr; gdImagePtr iptr; Check_Type(fname, T_STRING); f = rb_file_open(STR2CSTR(fname), "r"); rb_io_binmode(f); GetOpenFile(f, fptr); rb_io_check_readable(fptr); iptr = gdImageCreateFromJpeg(fptr->f); if (!iptr) rb_raise(rb_eArgError, "%s is not a valid Jpeg File", fptr->path); return Data_Wrap_Struct(klass,0,free_img,iptr); } #endif static VALUE img_destroy(img) struct RData *img; { if (img->data) { gdImageDestroy((gdImagePtr)img->data); img->data = 0; } return Qnil; } static VALUE hex2triplet(hex) VALUE hex; { VALUE rstr, gstr, bstr; VALUE ret_ary; Check_Type(hex, T_STRING); if (RSTRING(hex)->len != 7) rb_raise(rb_eArgError, "Invalid format: %s", RSTRING(hex)->ptr); rstr = rb_str_new(RSTRING(hex)->ptr + 1, 2); gstr = rb_str_new(RSTRING(hex)->ptr + 3, 2); bstr = rb_str_new(RSTRING(hex)->ptr + 5, 2); ret_ary = rb_ary_new(); rb_ary_push(ret_ary, rb_funcall(rstr, rb_intern("hex"), 0)); rb_ary_push(ret_ary, rb_funcall(gstr, rb_intern("hex"), 0)); rb_ary_push(ret_ary, rb_funcall(bstr, rb_intern("hex"), 0)); return ret_ary; } static VALUE img_color_allocate_tri(img, r, g, b) VALUE img, r, g, b; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorAllocate(im, NUM2INT(r), NUM2INT(g), NUM2INT(b)); return INT2FIX(c); } static VALUE img_color_allocate_str(img, rgbstr) VALUE img, rgbstr; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorAllocate(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2))); return INT2FIX(c); } static VALUE img_color_allocate(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, retval; if (!(argc == 1 || argc == 3)) rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "10", &rgbstr); retval = img_color_allocate_str(img, rgbstr); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "30", &r, &g, &b); retval = img_color_allocate_tri(img, r, g, b); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_color_deallocate(img, color) VALUE img, color; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageColorDeallocate(im, NUM2INT(color)); return img; } #ifdef HAVE_GDIMAGECOLORRESOLVE static VALUE img_color_resolve_tri(img, r, g, b) VALUE img, r, g, b; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorResolve(im, NUM2INT(r), NUM2INT(g), NUM2INT(b)); return INT2FIX(c); } static VALUE img_color_resolve_str(img, rgbstr) VALUE img, rgbstr; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorResolve(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2))); return INT2FIX(c); } static VALUE img_color_resolve(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, retval; if (!(argc == 1 || argc == 3)) rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "10", &rgbstr); retval = img_color_resolve_str(img, rgbstr); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "30", &r, &g, &b); retval = img_color_resolve_tri(img, r, g, b); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } #endif /* HAVE_GDIMAGECOLORRESOLVE */ static VALUE img_color_closest_tri(img, r, g, b) VALUE img, r, g, b; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorClosest(im, NUM2INT(r), NUM2INT(g), NUM2INT(b)); return INT2FIX(c); } static VALUE img_color_closest_str(img, rgbstr) VALUE img, rgbstr; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorClosest(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2))); return INT2FIX(c); } static VALUE img_color_closest(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, retval; if (!(argc == 1 || argc == 3)) rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "10", &rgbstr); retval = img_color_closest_str(img, rgbstr); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "30", &r, &g, &b); retval = img_color_closest_tri(img, r, g, b); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } extern int gdImageColorClosestHWB(gdImagePtr, int, int, int); static VALUE img_color_closestHWB_tri(img, r, g, b) VALUE img, r, g, b; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorClosestHWB(im, NUM2INT(r), NUM2INT(g), NUM2INT(b)); return INT2FIX(c); } static VALUE img_color_closestHWB_str(img, rgbstr) VALUE img, rgbstr; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorClosestHWB(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2))); return INT2FIX(c); } static VALUE img_color_closestHWB(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, retval; if (!(argc == 1 || argc == 3)) rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "10", &rgbstr); retval = img_color_closestHWB_str(img, rgbstr); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "30", &r, &g, &b); retval = img_color_closestHWB_tri(img, r, g, b); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_color_exact_tri(img, r, g, b) VALUE img, r, g, b; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorExact(im, NUM2INT(r), NUM2INT(g), NUM2INT(b)); return INT2FIX(c); } static VALUE img_color_exact_str(img, rgbstr) VALUE img, rgbstr; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorExact(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2))); return INT2FIX(c); } static VALUE img_color_exact(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, retval; if (!(argc == 1 || argc == 3)) rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "10", &rgbstr); retval = img_color_exact_str(img, rgbstr); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "30", &r, &g, &b); retval = img_color_exact_tri(img, r, g, b); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_colors_total(img) VALUE img; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorsTotal(im); return INT2FIX(c); } static VALUE img_get_pixel(img, x, y) VALUE img, x, y; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageGetPixel(im, NUM2INT(x), NUM2INT(y)); return INT2FIX(c); } static VALUE img_set_pixel(img, x, y, color) VALUE img, x, y, color; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageSetPixel(im, NUM2INT(x), NUM2INT(y), NUM2INT(color)); return img; } static VALUE img_red(img, idx) VALUE img, idx; { gdImagePtr im; int i,c; Data_Get_Struct(img, gdImage, im); i = NUM2INT(idx); c = gdImageRed(im, i); return INT2FIX(c); } static VALUE img_green(img, idx) VALUE img, idx; { gdImagePtr im; int i,c; Data_Get_Struct(img, gdImage, im); i = NUM2INT(idx); c = gdImageGreen(im, i); return INT2FIX(c); } static VALUE img_blue(img, idx) VALUE img, idx; { gdImagePtr im; int i,c; Data_Get_Struct(img, gdImage, im); i = NUM2INT(idx); c = gdImageBlue(im, i); return INT2FIX(c); } static VALUE img_rgb(img, idx) VALUE img, idx; { gdImagePtr im; VALUE ary = rb_ary_new2(3); int i, c; Data_Get_Struct(img, gdImage, im); i = NUM2INT(idx); c = gdImageRed(im, i); rb_ary_push(ary, INT2FIX(c)); c = gdImageGreen(im, i); rb_ary_push(ary, INT2FIX(c)); c = gdImageBlue(im, i); rb_ary_push(ary, INT2FIX(c)); return ary; } static VALUE img_transparent(img, idx) VALUE img, idx; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageColorTransparent(im, NUM2INT(idx)); return img; } static void image_req(img) VALUE img; { if (!rb_obj_is_kind_of(img, cImage)) { rb_raise(rb_eTypeError, "GD::Image required"); } } static VALUE img_set_blush(img, brush) VALUE img, brush; { gdImagePtr im, br; Data_Get_Struct(img, gdImage, im); image_req(brush); Data_Get_Struct(brush, gdImage, br); gdImageSetBrush(im, br); return img; } static VALUE img_set_style(argc, argv, img) int argc; VALUE *argv; VALUE img; { gdImagePtr im; int *style; int i; Data_Get_Struct(img, gdImage, im); style = ALLOCA_N(int, argc); for (i=0; ilen/2; pnt = ALLOCA_N(gdPoint, len); for (i=0; iptr[i*2]); pnt[i].y = NUM2INT(ply->ptr[i*2+1]); } gdImagePolygon(im, pnt, len, NUM2INT(c)); return img; } static VALUE img_filled_polygon(img, ply, c) VALUE img; struct RArray *ply; VALUE c; { gdImagePtr im; gdPointPtr pnt; int i, len; Data_Get_Struct(img, gdImage, im); poly_req(ply); len = ply->len/2; pnt = ALLOCA_N(gdPoint, len); for (i=0; iptr[i*2]); pnt[i].y = NUM2INT(ply->ptr[i*2+1]); } gdImageFilledPolygon(im, pnt, len, NUM2INT(c)); return img; } static VALUE img_arc(img, cx, cy, w, h, s, e, c) VALUE img, cx, cy, w, h, s, e, c; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageArc(im,NUM2INT(cx),NUM2INT(cy),NUM2INT(w),NUM2INT(h),NUM2INT(s),NUM2INT(e),NUM2INT(c)); return img; } static VALUE img_fill(img, x, y, c) VALUE img, x, y, c; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageFill(im,NUM2INT(x),NUM2INT(y),NUM2INT(c)); return img; } static VALUE img_fill_to_border(img, x, y, b, c) VALUE img, x, y, b, c; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageFillToBorder(im,NUM2INT(x),NUM2INT(y),NUM2INT(b),NUM2INT(c)); return img; } static VALUE img_copy(img, img2, dx, dy, sx, sy, w, h) VALUE img, img2, dx, dy, sx, sy, w, h; { gdImagePtr im, im2; Data_Get_Struct(img, gdImage, im); image_req(img2); Data_Get_Struct(img2, gdImage, im2); #ifdef ENABLE_GD_2_0 if (is_truecolor(im) && (!is_truecolor(im2))){ rb_raise(rb_eRuntimeError, "Copying truecolor image to palette image is not permitted"); } #endif gdImageCopy(im2, im, NUM2INT(dx), NUM2INT(dy), NUM2INT(sx), NUM2INT(sy), NUM2INT(w),NUM2INT(h)); return img; } static VALUE img_copy_resized(img, img2, dx, dy, sx, sy, dw, dh, sw, sh) VALUE img, img2, dx, dy, sx, sy, dw, dh, sw, sh; { gdImagePtr im, im2; Data_Get_Struct(img, gdImage, im); image_req(img2); Data_Get_Struct(img2, gdImage, im2); #ifdef ENABLE_GD_2_0 if (is_truecolor(im) && (!is_truecolor(im2))){ rb_raise(rb_eRuntimeError, "Copying truecolor image to palette image is not permitted"); } #endif gdImageCopyResized(im2,im,NUM2INT(dx),NUM2INT(dy),NUM2INT(sx),NUM2INT(sy),NUM2INT(dw),NUM2INT(dh),NUM2INT(sw),NUM2INT(sh)); return img; } static VALUE img_copy_merge(img, img_dest, dx, dy, sx, sy, w, h, pct) VALUE img, img_dest, dx, dy, sx, sy, w, h, pct; { gdImagePtr im, im_dest; Data_Get_Struct(img, gdImage, im); image_req(img_dest); Data_Get_Struct(img_dest, gdImage, im_dest); #ifdef ENABLE_GD_2_0 if (is_truecolor(im) && (!is_truecolor(im_dest))){ rb_raise(rb_eRuntimeError, "Copying truecolor image to palette image is not permitted"); } #endif gdImageCopyMerge(im_dest,im,NUM2INT(dx),NUM2INT(dy),NUM2INT(sx),NUM2INT(sy),NUM2INT(w),NUM2INT(h), NUM2INT(pct)); return img; } static VALUE img_copy_merge_gray(img, img_dest, dx, dy, sx, sy, w, h, pct) VALUE img, img_dest, dx, dy, sx, sy, w, h, pct; { gdImagePtr im, im_dest; Data_Get_Struct(img, gdImage, im); image_req(img_dest); Data_Get_Struct(img_dest, gdImage, im_dest); #ifdef ENABLE_GD_2_0 if (is_truecolor(im) && (!is_truecolor(im_dest))){ rb_raise(rb_eRuntimeError, "Copying truecolor image to palette image is not permitted"); } #endif gdImageCopyMergeGray(im_dest,im,NUM2INT(dx),NUM2INT(dy),NUM2INT(sx),NUM2INT(sy),NUM2INT(w),NUM2INT(h), NUM2INT(pct)); return img; } static VALUE img_palette_copy(img, img2) VALUE img, img2; { gdImagePtr im, im2; image_req(img2); Data_Get_Struct(img, gdImage, im); Data_Get_Struct(img2, gdImage, im2); gdImagePaletteCopy(im, im2); return img; } static void font_req(fnt) VALUE fnt; { if (!rb_obj_is_kind_of(fnt, cFont)) { rb_raise(rb_eTypeError, "GD::Font required"); } } static VALUE img_string(img, fnt, x, y, str, c) VALUE img, fnt, x, y, str, c; { gdImagePtr im; gdFontPtr f; Check_Type(str, T_STRING); Data_Get_Struct(img, gdImage, im); font_req(fnt); Data_Get_Struct(fnt, gdFont, f); gdImageString(im,f,NUM2INT(x),NUM2INT(y),RSTRING(str)->ptr,NUM2INT(c)); return img; } static VALUE img_string_up(img, fnt, x, y, str, c) VALUE img, fnt, x, y, str, c; { gdImagePtr im; gdFontPtr f; Check_Type(str, T_STRING); Data_Get_Struct(img, gdImage, im); font_req(fnt); Data_Get_Struct(fnt, gdFont, f); gdImageStringUp(im,f,NUM2INT(x),NUM2INT(y),RSTRING(str)->ptr,NUM2INT(c)); return img; } #ifdef HAVE_GDIMAGESTRINGTTF static VALUE img_s_string_ttf(klass, fgcolor, fontname, ptsize, angle, x, y, string) VALUE klass, fgcolor, fontname, ptsize, angle, x, y, string; { int brect[8], i; char *msg; VALUE ary = rb_ary_new2(8); Check_Type(fontname, T_STRING); Check_Type(string, T_STRING); msg = gdImageStringTTF(NULL, &brect[0], NUM2INT(fgcolor), RSTRING(fontname)->ptr, NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING(string)->ptr); for (i=0; i<8; i++) { rb_ary_push(ary, INT2FIX(brect[i])); } if (msg) { return rb_ary_new3(2, rb_str_new2(msg), ary); } else { return rb_ary_new3(2, Qnil, ary); } } static VALUE img_string_ttf(img, fgcolor, fontname, ptsize, angle, x, y, string) VALUE img, fgcolor, fontname, ptsize, angle, x, y, string; { gdImagePtr im; int brect[8], i; char *msg; VALUE ary = rb_ary_new2(8); Check_Type(fontname, T_STRING); Check_Type(string, T_STRING); Data_Get_Struct(img, gdImage, im); msg = gdImageStringTTF(im, &brect[0], NUM2INT(fgcolor), RSTRING(fontname)->ptr, NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING(string)->ptr); for (i=0; i<8; i++) { rb_ary_push(ary, INT2FIX(brect[i])); } if (msg) { return rb_ary_new3(2, rb_str_new2(msg), ary); } else { return rb_ary_new3(2, Qnil, ary); } } #endif /* HAVE_GDIMAGESTRINGTTF */ #ifdef HAVE_GDIMAGESTRINGFT static VALUE img_s_string_ft(klass, fgcolor, fontname, ptsize, angle, x, y, string) VALUE klass, fgcolor, fontname, ptsize, angle, x, y, string; { int brect[8], i; char *msg; VALUE ary = rb_ary_new2(8); Check_Type(fontname, T_STRING); Check_Type(string, T_STRING); msg = gdImageStringFT(NULL, &brect[0], NUM2INT(fgcolor), RSTRING(fontname)->ptr, NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING(string)->ptr); for (i=0; i<8; i++) { rb_ary_push(ary, INT2FIX(brect[i])); } if (msg) { return rb_ary_new3(2, rb_str_new2(msg), ary); } else { return rb_ary_new3(2, Qnil, ary); } } static VALUE img_string_ft(img, fgcolor, fontname, ptsize, angle, x, y, string) VALUE img, fgcolor, fontname, ptsize, angle, x, y, string; { gdImagePtr im; int brect[8], i; char *msg; VALUE ary = rb_ary_new2(8); Check_Type(fontname, T_STRING); Check_Type(string, T_STRING); Data_Get_Struct(img, gdImage, im); msg = gdImageStringFT(im, &brect[0], NUM2INT(fgcolor), RSTRING(fontname)->ptr, NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING(string)->ptr); for (i=0; i<8; i++) { rb_ary_push(ary, INT2FIX(brect[i])); } if (msg) { return rb_ary_new3(2, rb_str_new2(msg), ary); } else { return rb_ary_new3(2, Qnil, ary); } } #endif /* HAVE_GDIMAGESTRINGFT */ static VALUE img_char(img, fnt, x, y, ch, c) VALUE img, fnt, x, y, ch, c; { gdImagePtr im; gdFontPtr f; int ci; Data_Get_Struct(img, gdImage, im); font_req(fnt); Data_Get_Struct(fnt, gdFont, f); if (TYPE(ch) == T_STRING) { if (RSTRING(ch)->len != 1) { rb_raise(rb_eArgError, "string must be 1 byte(%d bytes)", RSTRING(ch)->len); } ci = RSTRING(ch)->ptr[0]; } else { ci = NUM2INT(ch); } gdImageChar(im,f,NUM2INT(x),NUM2INT(y),ci,NUM2INT(c)); return img; } static VALUE img_char_up(img, fnt, x, y, ch, c) VALUE img, fnt, x, y, ch, c; { gdImagePtr im; gdFontPtr f; int ci; Data_Get_Struct(img, gdImage, im); font_req(fnt); Data_Get_Struct(fnt, gdFont, f); if (TYPE(ch) == T_STRING) { if (RSTRING(ch)->len != 1) { rb_raise(rb_eArgError, "string must be 1 byte(%d bytes)", RSTRING(ch)->len); } ci = RSTRING(ch)->ptr[0]; } else { ci = NUM2INT(ch); } gdImageCharUp(im,f,NUM2INT(x),NUM2INT(y),ci,NUM2INT(c)); return img; } static VALUE img_get_interlace(img) VALUE img; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); if (gdImageGetInterlaced(im)) { return Qtrue; } return Qfalse; } static VALUE img_set_interlace(img, val) { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageInterlace(im, RTEST(val)); return img; } static VALUE img_bounds(img) VALUE img; { gdImagePtr im; VALUE ary = rb_ary_new2(2); int i; Data_Get_Struct(img, gdImage, im); i = gdImageSX(im); rb_ary_push(ary, INT2FIX(i)); i = gdImageSY(im); rb_ary_push(ary, INT2FIX(i)); return ary; } static VALUE img_bounds_safe(img, x, y) VALUE img, x, y; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); if ( gdImageBoundsSafe(im, NUM2INT(x), NUM2INT(y)) ) { return Qtrue; } else { return Qfalse; } } static VALUE img_get_transparent(img) VALUE img; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); return INT2NUM(gdImageGetTransparent(im)); } static VALUE img_width(img) VALUE img; { gdImagePtr im; int i; Data_Get_Struct(img, gdImage, im); i = gdImageSX(im); return INT2FIX(i); } static VALUE img_height(img) VALUE img; { gdImagePtr im; int i; Data_Get_Struct(img, gdImage, im); i = gdImageSY(im); return INT2FIX(i); } static VALUE img_png(img, out) VALUE img, out; { gdImagePtr im; OpenFile *fptr; FILE *f; Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); rb_io_binmode(out); GetOpenFile(out, fptr); rb_io_check_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; gdImagePng(im, f); return img; } static VALUE img_png_str(img) VALUE img; { int size; void *ptr; gdImagePtr im; VALUE imageString; Data_Get_Struct(img, gdImage, im); ptr = gdImagePngPtr(im, &size); imageString = rb_str_new(ptr, size); #ifdef ENABLE_GD_2_0 gdFree(ptr); #else free(ptr); #endif return imageString; } #ifdef ENABLE_GD_2_0 static VALUE img_gif(img, out) VALUE img, out; { gdImagePtr im; OpenFile *fptr; FILE *f; Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); rb_io_binmode(out); GetOpenFile(out, fptr); rb_io_check_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; gdImageGif(im, f); return img; } static VALUE img_gif_str(img) VALUE img; { int size; void *ptr; gdImagePtr im; VALUE imageString; Data_Get_Struct(img, gdImage, im); ptr = gdImageGifPtr(im, &size); imageString = rb_str_new(ptr, size); gdFree(ptr); return imageString; } #endif /* ENABLE_GD_2_0 */ static VALUE img_gd(img, out) VALUE img, out; { gdImagePtr im; OpenFile *fptr; FILE *f; Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); rb_io_binmode(out); GetOpenFile(out, fptr); rb_io_check_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; gdImageGd(im, f); return img; } static VALUE img_gd2(img, out, cs, fmt) VALUE img, out, cs, fmt; { OpenFile *fptr; gdImagePtr im; FILE *f; Check_Type(out, T_FILE); rb_io_binmode(out); GetOpenFile(out, fptr); rb_io_check_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; Data_Get_Struct(img, gdImage, im); gdImageGd2(im, f, NUM2INT(cs), NUM2INT(fmt)); return img; } #ifdef HAVE_GDIMAGECREATEFROMJPEG static VALUE img_jpeg(img, out, quality) VALUE img, out, quality; { gdImagePtr im; OpenFile *fptr; FILE *f; Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); rb_io_binmode(out); GetOpenFile(out, fptr); rb_io_check_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; gdImageJpeg(im, f, FIX2INT(quality)); return img; } static VALUE img_jpeg_str(img, quality) VALUE img, quality; { int size; void *ptr; gdImagePtr im; VALUE imageString; Data_Get_Struct(img, gdImage, im); ptr = gdImageJpegPtr(im, &size, FIX2INT(quality)); imageString = rb_str_new(ptr, size); #ifdef ENABLE_GD_2_0 gdFree(ptr); #else free(ptr); #endif return imageString; } #endif static VALUE img_wbmp(img, fg, out) VALUE img, out, fg; { gdImagePtr im; OpenFile *fptr; FILE *f; Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); rb_io_binmode(out); GetOpenFile(out, fptr); rb_io_check_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; gdImageWBMP(im, FIX2INT(fg), f); return img; } /* * * Poligon * */ static VALUE ply_new(klass) VALUE klass; { VALUE self = rb_ary_new(); RBASIC(self)->klass = klass; return self; } static VALUE ply_add_pt(ply, x, y) VALUE ply, x, y; { /* type check */ NUM2INT(x); NUM2INT(y); rb_ary_push(ply, x); rb_ary_push(ply, y); return ply; } static VALUE ply_to_pt(ply, dx, dy) VALUE ply, dx, dy; { VALUE x, y; /* type check */ NUM2INT(dx); NUM2INT(dy); if (RARRAY(ply)->len > 0) { x = rb_ary_entry(ply, RARRAY(ply)->len - 2); y = rb_ary_entry(ply, RARRAY(ply)->len - 1); rb_ary_push(ply, INT2NUM(NUM2INT(x) + NUM2INT(dx))); rb_ary_push(ply, INT2NUM(NUM2INT(y) + NUM2INT(dy))); } else { ply_add_pt(ply, dx, dy); } return ply; } static VALUE ply_get_pt(ply, idx) VALUE ply, idx; { int i = NUM2INT(idx); if (RARRAY(ply)->len < idx) return Qnil; i *= 2; return rb_assoc_new(rb_ary_entry(ply, i), rb_ary_entry(ply, i+1)); } static VALUE ply_set_pt(ply, idx, x, y) VALUE ply, idx, x, y; { int i = NUM2INT(idx)*2; /* type check */ NUM2INT(x); NUM2INT(y); rb_ary_store(ply, i, x); rb_ary_store(ply, i+1, y); return ply; } static VALUE ply_delete_pt(ply, idx) VALUE ply, idx; { int i = NUM2INT(idx)*2; rb_ary_delete_at(ply, INT2FIX(i)); rb_ary_delete_at(ply, INT2FIX(i+1)); return ply; } static VALUE ply_length(ply) VALUE ply; { return INT2FIX(RARRAY(ply)->len / 2); } static VALUE ply_vertices(ply) struct RArray *ply; { int i; VALUE ary = rb_ary_new2(ply->len/2); for (i = 0; ilen; i+=2) { rb_ary_push(ary, rb_assoc_new(ply->ptr[i], ply->ptr[i+1])); } return ary; } static VALUE ply_bounds(ply) struct RArray *ply; { int i, l, t, r, b; int nx, ny; if (ply->len == 0) { l = t = r = b = 0; } else { l = r = NUM2INT(ply->ptr[0]); t = b = NUM2INT(ply->ptr[1]); } for (i = 2; ilen; i+=2) { nx = NUM2INT(ply->ptr[i]); if (nx < l) l = nx; if (nx > r) r = nx; ny = NUM2INT(ply->ptr[i+1]); if (ny < t) t = ny; if (ny > b) b = ny; } return rb_ary_new3(4, INT2FIX(l), INT2FIX(t), INT2FIX(r), INT2FIX(b)); } static VALUE ply_offset(ply, vx, vy) struct RArray *ply; VALUE vx, vy; { int i, x, y, c; x = NUM2INT(vx); y = NUM2INT(vy); for (i = 0; ilen; i+=2) { c = NUM2INT(ply->ptr[i]) + x; ply->ptr[i] = INT2FIX(c); c = NUM2INT(ply->ptr[i+1]) + y; ply->ptr[i+1] = INT2FIX(c); } return (VALUE)ply; } static VALUE ply_map(argc, argv, ply) int argc; VALUE *argv; struct RArray *ply; { VALUE sl, st, sr, sb, dl, dt, dr, db; int sx, sy, dx, dy; double xmag, ymag; int i, c; i = rb_scan_args(argc,argv,"44",&sl,&st,&sr,&sb, &dl,&dt,&dr,&db); if (i == 4) { int i, l, t, r, b; int nx, ny; if (ply->len == 0) { l = t = r = b = 0; } else { l = r = NUM2INT(ply->ptr[0]); t = b = NUM2INT(ply->ptr[1]); } for (i = 2; ilen; i+=2) { nx = NUM2INT(ply->ptr[i]); if (nx < l) l = nx; if (nx > r) r = nx; ny = NUM2INT(ply->ptr[i+1]); if (ny < t) t = ny; if (ny > b) b = ny; } sx = l; sy = t; dx = NUM2INT(sl); dy = NUM2INT(st); xmag = (double)(NUM2INT(sr) - NUM2INT(sl))/(double)(r - l); ymag = (double)(NUM2INT(sb) - NUM2INT(st))/(double)(b - t); } else if (i == 8) { sx = NUM2INT(sl); sy = NUM2INT(st); dx = NUM2INT(dl); dy = NUM2INT(dt); xmag = (double)(NUM2INT(dr) - NUM2INT(dl))/ (double)(NUM2INT(sr) - NUM2INT(sl)); ymag = (double)(NUM2INT(db) - NUM2INT(dt))/ (double)(NUM2INT(sb) - NUM2INT(st)); } else { rb_raise(rb_eArgError, "wrong # of arguments (%d for 4 or 8)", argc); } for (i = 0; ilen; i+=2) { c = NUM2INT(ply->ptr[i]); c = (c-sx)*xmag+dx; ply->ptr[i] = INT2FIX(c); c = NUM2INT(ply->ptr[i+1]); c = (c-sy)*ymag+dy; ply->ptr[i+1] = INT2FIX(c); } return (VALUE)ply; } static VALUE ply_transform(ply, a, b, c, d, tx, ty) VALUE ply, a, b, c, d, tx, ty; { int i; VALUE x, y; for (i = 0; i < RARRAY(ply)->len / 2; i++) { /* x = rb_ary_entry(ply, i * 2); y = rb_ary_entry(ply, i * 2 + 1);*/ x = RARRAY(ply)->ptr[i * 2]; y = RARRAY(ply)->ptr[i * 2 + 1]; ply_set_pt(ply, INT2NUM(i), INT2NUM(NUM2DBL(a) * NUM2INT(x) + NUM2DBL(c) * NUM2INT(y) + NUM2INT(tx)), INT2NUM(NUM2DBL(b) * NUM2INT(x) + NUM2DBL(d) * NUM2INT(y) + NUM2INT(ty))); } return ply; } static VALUE ply_scale(ply, sx, sy) VALUE ply, sx, sy; { return ply_transform(ply, sx, INT2NUM(0), INT2NUM(0), sy, INT2NUM(0), INT2NUM(0)); } static VALUE fnt_create(fnt) gdFontPtr fnt; { return Data_Wrap_Struct(cFont, 0, 0, fnt); } static VALUE fnt_new(name) char *name; { if (strcmp(name, "Giant") == 0) { return fnt_create(gdFontGiant); } if (strcmp(name, "Large") == 0) { return fnt_create(gdFontLarge); } if (strcmp(name, "Medium") == 0) { return fnt_create(gdFontMediumBold); } if (strcmp(name, "Small") == 0) { return fnt_create(gdFontSmall); } if (strcmp(name, "Tiny") == 0) { return fnt_create(gdFontTiny); } rb_raise(rb_eArgError, "undefined font name `%s'", name); } static VALUE fnt_s_new(obj, name) VALUE obj; struct RString *name; { Check_Type(name, T_STRING); return fnt_new(name->ptr); } static VALUE fnt_nchars(fnt) VALUE fnt; { gdFontPtr fp; Data_Get_Struct(fnt,gdFont,fp); return INT2FIX(fp->nchars); } static VALUE fnt_offset(fnt) VALUE fnt; { gdFontPtr fp; Data_Get_Struct(fnt,gdFont,fp); return INT2FIX(fp->offset); } static VALUE fnt_width(fnt) VALUE fnt; { gdFontPtr fp; Data_Get_Struct(fnt,gdFont,fp); return INT2FIX(fp->w); } static VALUE fnt_height(fnt) VALUE fnt; { gdFontPtr fp; Data_Get_Struct(fnt,gdFont,fp); return INT2FIX(fp->h); } /* * * gd-2.0.x features : experimental * */ #ifdef ENABLE_GD_2_0 static VALUE img_s_new_tc(klass, sx, sy) VALUE klass, sx, sy; { gdImagePtr iptr; if (NUM2INT(sx)<0 || NUM2INT(sy)<0) rb_raise(rb_eArgError, "Negative width/height not allowed"); iptr = gdImageCreateTrueColor(NUM2INT(sx), NUM2INT(sy)); if (!iptr) rb_raise(rb_eRuntimeError, "Unable to allocate the new image"); return Data_Wrap_Struct(klass,0,free_img,iptr); } static VALUE img_color_allocate_alpha_tri(img, r, g, b, a) VALUE img, r, g, b, a; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorAllocateAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_allocate_alpha_str(img, rgbstr, a) VALUE img, rgbstr, a; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorAllocateAlpha(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2)), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_allocate_alpha(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, a, retval; if (!(argc == 2 || argc == 4)) rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "20", &rgbstr, &a); retval = img_color_allocate_alpha_str(img, rgbstr, a); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a); retval = img_color_allocate_alpha_tri(img, r, g, b, a); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_color_resolve_alpha_tri(img, r, g, b, a) VALUE img, r, g, b, a; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorResolveAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_resolve_alpha_str(img, rgbstr, a) VALUE img, rgbstr, a; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorResolveAlpha(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2)), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_resolve_alpha(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, a, retval; if (!(argc == 2 || argc == 4)) rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "20", &rgbstr, &a); retval = img_color_resolve_alpha_str(img, rgbstr, a); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a); retval = img_color_resolve_alpha_tri(img, r, g, b, a); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_color_closest_alpha_tri(img, r, g, b, a) VALUE img, r, g, b, a; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorClosestAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_closest_alpha_str(img, rgbstr, a) VALUE img, rgbstr, a; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorClosestAlpha(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2)), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_closest_alpha(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, a, retval; if (!(argc == 2 || argc == 4)) rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "20", &rgbstr, &a); retval = img_color_closest_alpha_str(img, rgbstr, a); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a); retval = img_color_closest_alpha_tri(img, r, g, b, a); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_color_exact_alpha_tri(img, r, g, b, a) VALUE img, r, g, b, a; { gdImagePtr im; int c; Data_Get_Struct(img, gdImage, im); c = gdImageColorExactAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_exact_alpha_str(img, rgbstr, a) VALUE img, rgbstr, a; { gdImagePtr im; int c; VALUE ary; Data_Get_Struct(img, gdImage, im); ary = hex2triplet(rgbstr); c = gdImageColorExactAlpha(im, NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2)), NUM2INT(a)); return INT2NUM(c); } static VALUE img_color_exact_alpha(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, a, retval; if (!(argc == 2 || argc == 4)) rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "20", &rgbstr, &a); retval = img_color_exact_alpha_str(img, rgbstr, a); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a); retval = img_color_exact_alpha_tri(img, r, g, b, a); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_alpha_blending(img, blending_mode) VALUE img, blending_mode; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageAlphaBlending(im, RTEST(blending_mode)); return img; } static VALUE img_alpha(img, color) VALUE img, color; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); return INT2NUM(gdImageAlpha(im, NUM2INT(color))); } static VALUE img_s_truecolor_str(rgbstr) VALUE rgbstr; { int c; VALUE ary; ary = hex2triplet(rgbstr); c = gdTrueColor(NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2))); return INT2NUM(c); } static VALUE img_s_truecolor_tri(r, g, b) VALUE r, g, b; { int c; c = gdTrueColor(NUM2INT(r), NUM2INT(g), NUM2INT(b)); return INT2NUM(c); } static VALUE img_s_truecolor(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, retval; if (!(argc == 1 || argc == 3)) rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "10", &rgbstr); retval = img_s_truecolor_str(rgbstr); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "30", &r, &g, &b); retval = img_s_truecolor_tri(r, g, b); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_s_truecolor_alpha_str(rgbstr, a) VALUE rgbstr, a; { int c; VALUE ary; ary = hex2triplet(rgbstr); c = gdTrueColorAlpha(NUM2INT(*(RARRAY(ary)->ptr)), NUM2INT(*(RARRAY(ary)->ptr+1)), NUM2INT(*(RARRAY(ary)->ptr+2)), NUM2INT(a)); return INT2NUM(c); } static VALUE img_s_truecolor_alpha_tri(r, g, b, a) VALUE r, g, b, a; { int c; c = gdTrueColorAlpha(NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a)); return INT2NUM(c); } static VALUE img_s_truecolor_alpha(argc, argv, img) int argc; VALUE *argv; VALUE img; { int i; VALUE rgbstr, r, g, b, a, retval; if (!(argc == 2 || argc == 4)) rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc); switch(TYPE(argv[0])) { case T_STRING: i = rb_scan_args(argc, argv, "20", &rgbstr, &a); retval = img_s_truecolor_alpha_str(rgbstr, a); break; case T_FIXNUM: i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a); retval = img_s_truecolor_alpha_tri(r, g, b, a); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); break; } return retval; } static VALUE img_copy_resampled(img, img2, dx, dy, sx, sy, dw, dh, sw, sh) VALUE img, img2, dx, dy, sx, sy, dw, dh, sw, sh; { gdImagePtr im, im2; Data_Get_Struct(img, gdImage, im); image_req(img2); Data_Get_Struct(img2, gdImage, im2); if (is_truecolor(im) && (!is_truecolor(im2))){ rb_raise(rb_eRuntimeError, "Copying truecolor image to palette image is not permitted"); } gdImageCopyResampled(im2, im, NUM2INT(dx), NUM2INT(dy), NUM2INT(sx), NUM2INT(sy), NUM2INT(dw), NUM2INT(dh), NUM2INT(sw), NUM2INT(sh)); return img; } static VALUE img_filled_ellipse(img, cx, cy, w, h, start, end, color) VALUE img, cx, cy, w, h, start, end, color; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageFilledEllipse(im, NUM2INT(cx), NUM2INT(cy), NUM2INT(w), NUM2INT(h), NUM2INT(color)); return img; } static VALUE img_filled_arc(img, cx, cy, w, h, start, end, color, style) VALUE img, cx, cy, w, h, start, end, color, style; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageFilledArc(im, NUM2INT(cx), NUM2INT(cy), NUM2INT(w), NUM2INT(h), NUM2INT(start), NUM2INT(end), NUM2INT(color), NUM2INT(style)); return img; } static VALUE img_is_truecolor_image(img) VALUE img; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); return is_truecolor(im); } static VALUE img_is_palette_image(img) VALUE img; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); return is_truecolor(im) ? Qfalse : Qtrue; } static VALUE img_to_palette_image(img, dither_flag, max_colors) VALUE img, dither_flag, max_colors; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageTrueColorToPalette(im, dither_flag, FIX2INT(max_colors)); return img; } static VALUE img_set_thickness(img, thickness) VALUE img, thickness; { gdImagePtr im; Data_Get_Struct(img, gdImage, im); gdImageSetThickness(im, FIX2INT(thickness)); return img; } #endif /* ENABLE_GD_2_0 */ void Init_GD() { mGD = rb_define_module("GD"); cImage = rb_define_class_under(mGD, "Image", rb_cObject); rb_define_singleton_method(cImage, "new", img_s_new, 2); rb_define_singleton_method(cImage, "newPalette", img_s_new, 2); rb_define_singleton_method(cImage, "newFromPng", img_from_png, 1); rb_define_singleton_method(cImage, "new_from_png", img_from_pngfname, 1); #ifdef ENABLE_GD_2_0 rb_define_singleton_method(cImage, "newFromGif", img_from_gif, 1); rb_define_singleton_method(cImage, "new_from_gif", img_from_giffname, 1); #endif /* ENABLE_GD_2_0 */ rb_define_singleton_method(cImage, "newFromXbm", img_from_xbm, 1); rb_define_singleton_method(cImage, "new_from_xbm", img_from_xbmfname, 1); rb_define_singleton_method(cImage, "newFromGd", img_from_gd, 1); rb_define_singleton_method(cImage, "new_from_gd", img_from_gdfname, 1); #ifdef HAVE_GDIMAGECREATEFROMXPM rb_define_singleton_method(cImage, "newFromXpm", img_from_xpm, 1); rb_define_singleton_method(cImage, "new_from_xpm", img_from_xpmfname, 1); #endif /* HAVE_GDIMAGECREATEFROMXPM */ rb_define_singleton_method(cImage, "newFromGd2", img_from_gd2, 1); rb_define_singleton_method(cImage, "new_from_gd2", img_from_gd2fname, 1); rb_define_singleton_method(cImage, "newFromGd2Part", img_from_gd2_part, 5); rb_define_singleton_method(cImage, "new_from_gd2_Part", img_from_gd2_partfname, 5); #ifdef HAVE_GDIMAGECREATEFROMJPEG rb_define_singleton_method(cImage, "newFromJpeg", img_from_jpeg, 1); rb_define_singleton_method(cImage, "new_from_jpeg", img_from_jpegfname, 1); #endif /* HAVE_GDIMAGECREATEFROMJPEG */ rb_define_method(cImage, "destroy", img_destroy, 0); rb_define_method(cImage, "colorAllocate", img_color_allocate, -1); rb_define_method(cImage, "colorDeallocate", img_color_deallocate, 1); rb_define_method(cImage, "colorClosest", img_color_closest, -1); rb_define_method(cImage, "colorClosestHWB", img_color_closestHWB, -1); rb_define_method(cImage, "colorExact", img_color_exact, -1); #ifdef HAVE_GDIMAGECOLORRESOLVE rb_define_method(cImage, "colorResolve", img_color_resolve, -1); #endif /* HAVE_GDIMAGECOLORRESOLVE */ rb_define_method(cImage, "colorsTotal", img_colors_total, 0); rb_define_method(cImage, "getPixel", img_get_pixel, 2); rb_define_method(cImage, "red", img_red, 1); rb_define_method(cImage, "green", img_green, 1); rb_define_method(cImage, "blue", img_blue, 1); rb_define_method(cImage, "rgb", img_rgb, 1); rb_define_method(cImage, "transparent", img_transparent, 1); rb_define_method(cImage, "setBrush", img_set_blush, 1); rb_define_const(mGD, "Brushed", INT2FIX(gdBrushed)); rb_define_method(cImage, "setStyle", img_set_style, -1); rb_define_const(mGD, "Styled", INT2FIX(gdStyled)); rb_define_const(mGD, "StyledBrushed", INT2FIX(gdStyledBrushed)); rb_define_method(cImage, "setTile", img_set_tile, 1); rb_define_const(mGD, "Tiled", INT2FIX(gdTiled)); rb_define_const(mGD, "Transparent", INT2FIX(gdTransparent)); rb_define_const(mGD, "GD2_FMT_COMPRESSED", INT2FIX(GD2_FMT_COMPRESSED)); rb_define_const(mGD, "GD2_FMT_RAW", INT2FIX(GD2_FMT_RAW)); rb_define_method(cImage, "setPixel", img_set_pixel, 3); rb_define_method(cImage, "line", img_line, 5); rb_define_method(cImage, "dashedLine", img_dashed_line, 5); rb_define_method(cImage, "rectangle", img_rectangle, 5); rb_define_method(cImage, "filledRectangle", img_filled_rectangle, 5); rb_define_method(cImage, "polygon", img_polygon, 2); rb_define_method(cImage, "filledPolygon", img_filled_polygon, 2); rb_define_method(cImage, "arc", img_arc, 7); rb_define_method(cImage, "fill", img_fill, 3); rb_define_method(cImage, "fillToBorder", img_fill_to_border, 4); rb_define_method(cImage, "line", img_line, 5); rb_define_method(cImage, "copy", img_copy, 7); rb_define_method(cImage, "copyResized", img_copy_resized, 9); rb_define_method(cImage, "copyMerge", img_copy_merge, 8); rb_define_method(cImage, "copyMergeGray", img_copy_merge_gray, 8); rb_define_method(cImage, "paletteCopy", img_palette_copy, 1); rb_define_method(cImage, "string", img_string, 5); rb_define_method(cImage, "stringUp", img_string_up, 5); #ifdef HAVE_GDIMAGESTRINGTTF rb_define_singleton_method(cImage, "stringTTF", img_s_string_ttf, 7); rb_define_method(cImage, "stringTTF", img_string_ttf, 7); #endif #ifdef HAVE_GDIMAGESTRINGFT rb_define_singleton_method(cImage, "stringFT", img_s_string_ft, 7); rb_define_method(cImage, "stringFT", img_string_ft, 7); #endif rb_define_method(cImage, "char", img_char, 5); rb_define_method(cImage, "charUp", img_char_up, 5); rb_define_method(cImage, "interlace", img_get_interlace, 0); rb_define_method(cImage, "interlace=", img_set_interlace, 1); rb_define_method(cImage, "getTransparent", img_get_transparent, 0); rb_define_method(cImage, "bounds", img_bounds, 0); rb_define_method(cImage, "boundsSafe", img_bounds_safe, 2); rb_define_method(cImage, "width", img_width, 0); rb_define_method(cImage, "height", img_height, 0); rb_define_method(cImage, "png", img_png, 1); rb_define_method(cImage, "pngStr", img_png_str, 0); #ifdef ENABLE_GD_2_0 rb_define_method(cImage, "gif", img_gif, 1); rb_define_method(cImage, "gifStr", img_gif_str, 0); #endif /* ENABLE_GD_2_0 */ rb_define_method(cImage, "gd2", img_gd2, 3); rb_define_method(cImage, "gd", img_gd, 1); #ifdef HAVE_GDIMAGECREATEFROMJPEG rb_define_method(cImage, "jpeg", img_jpeg, 2); rb_define_method(cImage, "jpegStr", img_jpeg_str, 1); #endif /* HAVE_GDIMAGECREATEFROMJPEG */ rb_define_method(cImage, "wbmp", img_wbmp, 2); cPolygon = rb_define_class_under(mGD, "Polygon", rb_cObject); rb_define_singleton_method(cPolygon, "new", ply_new, 0); rb_define_method(cPolygon, "addPt", ply_add_pt, 2); rb_define_method(cPolygon, "toPt", ply_to_pt, 2); rb_define_method(cPolygon, "getPt", ply_get_pt, 1); rb_define_method(cPolygon, "setPt", ply_set_pt, 3); rb_define_method(cPolygon, "deletePt", ply_delete_pt, 1); rb_define_method(cPolygon, "length", ply_length, 0); rb_define_method(cPolygon, "vertices", ply_vertices, 0); rb_define_method(cPolygon, "bounds", ply_bounds, 0); rb_define_method(cPolygon, "offset", ply_offset, 2); rb_define_method(cPolygon, "map", ply_map, -1); rb_define_method(cPolygon, "transform", ply_transform, 6); rb_define_method(cPolygon, "scale", ply_scale, 2); cFont = rb_define_class_under(mGD, "Font", rb_cObject); rb_define_singleton_method(cFont, "new", fnt_s_new, 1); rb_define_const(cFont, "GiantFont", fnt_new("Giant")); rb_define_const(cFont, "SmallFont", fnt_new("Small")); rb_define_const(cFont, "LargeFont", fnt_new("Large")); rb_define_const(cFont, "MediumFont", fnt_new("Medium")); rb_define_const(cFont, "MediumBoldFont", fnt_new("Medium")); rb_define_const(cFont, "TinyFont", fnt_new("Tiny")); rb_define_method(cFont, "nchars", fnt_nchars, 0); rb_define_method(cFont, "offset", fnt_offset, 0); rb_define_method(cFont, "width", fnt_width, 0); rb_define_method(cFont, "height", fnt_height, 0); #ifdef ENABLE_GD_2_0 rb_define_singleton_method(cImage, "newTrueColor", img_s_new_tc, 2); rb_define_method(cImage, "colorAllocateAlpha", img_color_allocate_alpha, -1); rb_define_method(cImage, "colorResolveAlpha", img_color_resolve_alpha, -1); rb_define_method(cImage, "colorClosestAlpha", img_color_closest_alpha, -1); rb_define_method(cImage, "colorExactAlpha", img_color_exact_alpha, -1); rb_define_method(cImage, "alphaBlending=", img_alpha_blending, 1); rb_define_method(cImage, "alpha", img_alpha, 1); rb_define_singleton_method(cImage, "trueColor", img_s_truecolor, -1); rb_define_singleton_method(cImage, "trueColorAlpha", img_s_truecolor_alpha, -1); rb_define_method(cImage, "copyResampled", img_copy_resampled, 9); rb_define_method(cImage, "filledEllipse", img_filled_ellipse, 7); rb_define_method(cImage, "filledArc", img_filled_arc, 8); rb_define_method(cImage, "is_trueColor?", img_is_truecolor_image, 0); rb_define_method(cImage, "is_palette?", img_is_palette_image, 0); rb_define_method(cImage, "to_paletteImage", img_to_palette_image, 2); rb_define_method(cImage, "thickness=", img_set_thickness, 1); rb_define_const(mGD, "AlphaTransparent", INT2FIX(gdAlphaTransparent)); rb_define_const(mGD, "AlphaOpaque", INT2FIX(gdAlphaOpaque)); rb_define_const(mGD, "Arc", INT2FIX(gdArc)); rb_define_const(mGD, "Chord", INT2FIX(gdChord)); rb_define_const(mGD, "Pie", INT2FIX(gdPie)); rb_define_const(mGD, "NoFill", INT2FIX(gdNoFill)); rb_define_const(mGD, "Edged", INT2FIX(gdEdged)); #endif /* ENABLE_GD_2_0 */ } ruby-gd-0.8.0/extconf.rb0000644000175000017500000000315411745022735013560 0ustar paulpaul=begin usage: ruby extconf.rb [options ...] configure options: --with-xpm : enables Xpm support --with-ttf : enables TrueType font support --with-jpeg : enables Jpeg support --with-freetype : enables FreeType 2.x support --with-gd-dir=dir --with-gd-include=dir --with-gd-lib=dir --enable-gd2_0 : enable new features provided by gd-2.0.x(beta). =end require 'mkmf' def delete_link(libname) lib_ary = $libs.split libname = '-l'+libname lib_ary.delete libname $libs = lib_ary.join " " end dir_config("gd", "/usr/local/include", "/usr/local/lib") if with_config("xpm") dir_config("X11", "/usr/X11R6/include", "/usr/X11R6/lib") end if with_config('jpeg') have_library('jpeg') end if with_config('ttf') have_library('ttf') end if with_config('xpm') have_library('X11') have_library('Xpm') end if with_config('freetype') have_library('freetype') end if have_library('z') and have_library('png') and have_library('gd', 'gdImagePng') and have_library('m') if with_config('ttf') and not have_func('gdImageStringTTF') delete_link('ttf') end have_func('gdImageColorResolve') if with_config('xpm') and not have_func('gdImageCreateFromXpm') delete_link('Xpm') delete_link('X11') end if with_config('jpeg') and not have_func('gdImageCreateFromJpeg') delete_link('jpeg') end if with_config('freetype') and not have_func('gdImageStringFT') delete_link('freetype') end if enable_config("gd2_0", false) if have_func("gdImageAlphaBlending") $CFLAGS += ' -DENABLE_GD_2_0' end end create_makefile('GD') end ruby-gd-0.8.0/Changes0000644000175000017500000000431411745022735013057 0ustar paulpaul= Changes from 0.7.4 * GD.c: added GD::Image.newFromGif, GD::Image.new_from_gif, GD::Image#gif, GD::Image#gifStr. * doc/manual.rd: documentation update. = Changes from 0.7.3 * doc/gd-intro_ja.html, doc/imgs/* : removed. * extconf.rb : new option '--enable-gd2_0' added to support for gd-2.0.1(beta). * GD::Image#newTrueColor, GD::Image#colorAllocateAlpha, GD::Image#colorResolveAlpha, GD::Image#colorClosestAlpha, GD::Image#colorExactAlpha, GD::Image#alphaBlending, GD::Image#alpha, GD::Image#trueColor, GD::Image#trueColorAlpha, GD::Image#copyResampled, GD::Image#filledEllipse, GD::Image#filledArc - new methods. They are for the new features of gd-2.0.1(beta). Accordingly, GD#Image.newPalette is an alias for GD::Image#new. * doc/manual.rd: documentation update. = Changes from 0.7.2 * Fixed typos and grammer mistakes in English documents. I thank Neil Conway for sending this patch. * GD::Image.stringFT, GD::Image#stringFT: should call gdImageStringFT(), not gdImageStringTTF()!!! I'm sorry. Thanks to YOKOKAWA Takehiro(tac@amris.co.jp). * GD::Image#JpegStr, GD::Image#PngStr: new method. Thanks to Colin Steele(colin@webg2.com). = Changes from 0.7.1 * extconf.rb: updated for gd-1.8.4. * GD.c: GD::Image.stringFT, GD::Image#stringFT: new methods. Note these methods requires the newest feature of gd-1.8.4. * extconf.rb, GD.c: should check GD::Image#colorResolve and GD::Image#stringTTF separately. Thanks to Tosh. * GD.c: added new constants GD::GD2_FMT_COMPRESSED, GD::GD2_FMT_RAW. (GD::Image::GD2_FMT_COMPRESSED, etc. is more adequate???) * GD.c: rb_str_hex():removed. rb_funcall() is utilized instead. Now works correctly for Ruby-1.4.x. * readme.rd: description for GD::Image#gd2 corrected. Thanks to nnakamura. * gd-intro_ja.html: copyright notice for some images. updated. = Changes from 0.7.0 * GD.c(GD::Image#colorAllocate, GD::Image#colorExact): the return values conformable to those of the original gd library. * GD::Image#colorAllocate, GD::Image#colorResolve, GD::Image#colorClosest, GD::Image#colorClosestHWB, GD::Image#colorExact : allow for the string like "#FF0000"(stands for "red") as an argument. * doc/gd_intro-ja.html: corrected and updated. Thanks to Tosh.