Class | GD2::Image |
In: |
lib/gd2/image.rb
|
Parent: | Object |
Image is the abstract base class for Image::IndexedColor and Image::TrueColor.
Image objects are created either as a blank array of pixels:
image = Image::IndexedColor.new(width, height) image = Image::TrueColor.new(width, height)
or by loading image data from a file or a string containing one of the supported image formats:
image = Image.load(file) image = Image.load(string)
or by importing image data from a file given by its pathname:
image = Image.import(filename)
After manipulating an image, it can be exported to a string in one of the supported image formats:
image.jpeg(quality = nil) image.png(level = nil) image.gif image.wbmp(fgcolor) image.gd image.gd2(fmt = FMT_COMPRESSED)
or to a file in a format determined by the filename extension:
image.export(filename, options = {})
new | -> | [] |
palette | [R] | The Palette object for this image |
Import an image from a file with the given filename. The :format option or the file extension is used to determine the image type (jpeg, png, gif, wbmp, gd, gd2, xbm, or xpm). The resulting image will be either of class Image::TrueColor or Image::IndexedColor.
If the file format is gd2, it is optionally possible to extract only a part of the image. Use options :x, :y, :width, and :height to specify the part of the image to import.
Load an image from a file or a string. The image type is detected automatically (JPEG, PNG, GIF, WBMP, or GD2). The resulting image will be either of class Image::TrueColor or Image::IndexedColor.
Create a new image of the specified dimensions. The default image class is Image::TrueColor; call this method on Image::IndexedColor instead if a palette image is desired.
Set whether colors should be alpha blended with existing colors when pixels are modified. Alpha blending is not available for IndexedColor images.
Return true if colors will be alpha blended into the image when pixels are modified. Returns false if colors will be copied verbatim into the image without alpha blending when pixels are modified.
Return the current clipping rectangle. Use Image#with_clipping to temporarily modify the clipping rectangle.
Compare this image with another image. Returns 0 if the images are identical, otherwise a bit field indicating the differences. See the GD2::CMP_* constants for individual bit flags.
Copy a portion of another image to this image. If src_w and src_h are specified, the indicated portion of the source image will be resized (and resampled) to fit the indicated dimensions of the destination.
Copy a portion of another image to this image, rotating the source portion first by the indicated angle (in radians). The dst_x and dst_y arguments indicate the center of the desired destination, and may be floating point.
Export this image to a file with the given filename. The image format is determined by the :format option, or by the file extension (jpeg, png, gif, wbmp, gd, or gd2). Returns the size of the written image data. Additional options are as arguments for the Image#jpeg, Image#png, Image#wbmp, or Image#gd2 methods.
Encode and return data for this image in GIF format. Note that GIF only supports palette images; TrueColor images will be automatically converted to IndexedColor internally in order to create the GIF. Use Image#to_indexed_color to control this conversion more precisely.
Encode and return data for this image in JPEG format. The quality argument should be in the range 0–95, with higher quality values usually implying both higher quality and larger sizes.
Merge a portion of another image into this one by the amount specified as pct (a percentage). A percentage of 1.0 is identical to Image#copy_from; a percentage of 0.0 is a no-op. Note that alpha channel information from the source image is ignored.
Consolidate duplicate colors in this image, and eliminate all unused palette entries. This only has an effect on IndexedColor images, and is rather expensive. Returns the number of palette entries deallocated.
Encode and return data for this image in PNG format. The level argument should be in the range 0–9 indicating the level of lossless compression (0 = none, 1 = minimal but fast, 9 = best but slow).
Resize this image to the given dimensions. If resample is true, the image pixels will be resampled; otherwise they will be stretched or shrunk as necessary without resampling.
Like Image#rotate! except a new image is returned.
Rotate this image by the given angle (in radians) about the given axis coordinates. Note that some of the edges of the image may be lost.
Sharpen this image by pct (a percentage) which can be greater than 1.0. Transparency/alpha channel are not altered. This has no effect on IndexedColor images.
Return this image as an IndexedColor image, creating a copy if necessary. colors indicates the maximum number of palette colors to use, and dither controls whether dithering is used.
Encode and return data for this image in WBMP format. WBMP currently supports only black and white images; the specified fgcolor will be used as the foreground color (black), and all other colors will be considered “background” (white).
Temporarily set the clipping rectangle during the execution of a block. Pixels outside this rectangle will not be modified by drawing or copying operations.