From d0a9b9a03fc7ae74ef8a64593ac6b592526ec4d5 Mon Sep 17 00:00:00 2001 From: pp Date: Wed, 19 May 2004 04:59:31 +0000 Subject: - initial import git-svn-id: https://siedziba.pl:790/svn/repos/php-imlib/trunk@7 455248ca-bdda-0310-9134-f4ebb693071a --- docs/api.txt | 442 +++++++++++++++++++++++++++++++++++++++++ docs/class.ImlibCliprect.php | 132 ++++++++++++ docs/class.ImlibColor.php | 94 +++++++++ docs/class.ImlibColorRange.php | 141 +++++++++++++ docs/class.ImlibDraw.php | 167 ++++++++++++++++ docs/class.ImlibImage.php | 436 ++++++++++++++++++++++++++++++++++++++++ docs/class.ImlibPoly.php | 190 ++++++++++++++++++ docs/class.ImlibText.php | 147 ++++++++++++++ docs/package.Imlib.php | 11 + 9 files changed, 1760 insertions(+) create mode 100644 docs/api.txt create mode 100644 docs/class.ImlibCliprect.php create mode 100644 docs/class.ImlibColor.php create mode 100644 docs/class.ImlibColorRange.php create mode 100644 docs/class.ImlibDraw.php create mode 100644 docs/class.ImlibImage.php create mode 100644 docs/class.ImlibPoly.php create mode 100644 docs/class.ImlibText.php create mode 100644 docs/package.Imlib.php (limited to 'docs') diff --git a/docs/api.txt b/docs/api.txt new file mode 100644 index 0000000..cdbe9c2 --- /dev/null +++ b/docs/api.txt @@ -0,0 +1,442 @@ +Documentation +============= + +Below is a brief blurb about each of the functions in the php_imlib +extension. For examples of how these are used, see the examples page. +There are also some PHP classes included with php_imlib (Which also +have examples posted on the examples page). These classfiles have been +documented using the PHPDoc documentation system. That documentation +can be found here. + +Predefined Constants +-------------------- + +IMLIB_TEXT_TO_RIGHT +IMLIB_TEXT_TO_LEFT +IMLIB_TEXT_TO_DOWN +IMLIB_TEXT_TO_UP +IMLIB_TEXT_TO_ANGLE +IMLIB_TTF_ENCODING_ISO_8859_1 +IMLIB_TTF_ENCODING_ISO_8859_2 +IMLIB_TTF_ENCODING_ISO_8859_3 +IMLIB_TTF_ENCODING_ISO_8859_4 +IMLIB_TTF_ENCODING_ISO_8859_5 +IMLIB_CHANNEL_RED +IMLIB_CHANNEL_GREEN +IMLIB_CHANNEL_BLUE +IMLIB_CHANNEL_ALPHA +IMLIB_LOAD_ERROR_NONE +IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST +IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY +IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ +IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT +IMLIB_LOAD_ERROR_PATH_TOO_LONG +IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT +IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY +IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE +IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS +IMLIB_LOAD_ERROR_OUT_OF_MEMORY +IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS +IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE +IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE +IMLIB_LOAD_ERROR_UNKNOWN + +Function List +------------- + +imlib_add_color_to_color_range +imlib_blend_image_onto_image +imlib_clone_image +imlib_create_color_range +imlib_create_cropped_image +imlib_create_cropped_scaled_image +imlib_create_image +imlib_create_rotated_image +imlib_image_orientate +imlib_create_scaled_image +imlib_dump_image +imlib_free_color_range +imlib_free_font +imlib_free_image +imlib_get_text_size +imlib_image_blur +imlib_image_draw_ellipse +imlib_image_draw_line +imlib_image_draw_polygon +imlib_image_draw_rectangle +imlib_image_fill_color_range_rectangle +imlib_image_fill_ellipse +imlib_image_fill_polygon +imlib_image_fill_rectangle +imlib_image_flip_horizontal +imlib_image_flip_vertical +imlib_image_flip_diagonal +imlib_image_format +imlib_image_get_filename +imlib_image_get_height +imlib_image_get_width +imlib_image_has_alpha +imlib_image_modify_alpha +imlib_image_set_format +imlib_image_sharpen +imlib_image_tile_horizontal +imlib_image_tile_vertical +imlib_image_tile +imlib_list_fonts +imlib_load_font +imlib_load_image +imlib_polygon_add_point +imlib_polygon_contains_point +imlib_polygon_free +imlib_polygon_get_bounds +imlib_polygon_new +imlib_save_image +imlib_text_draw +imlib_psloadfont +imlib_psfreefont +imlib_psencodefont +imlib_psextendfont +imlib_psslantfont +imlib_pstext +imlib_psbbox +imlib_get_cache_size +imlib_set_cache_size +imlib_create_filter +imlib_free_filter +imlib_image_filter +imlib_filter_set +imlib_filter_set_alpha +imlib_filter_set_red +imlib_filter_set_green +imlib_filter_set_blue +imlib_filter_constants +imlib_filter_divisors +imlib_apply_filter +imlib_modify_color_modifier_gamma +imlib_modify_color_modifier_brightness +imlib_modify_color_modifier_contrast +imlib_reset_color_modifier +imlib_apply_color_modifier +imlib_set_color_modifier +imlib_get_color_modifier + +Getting and Setting Image Parameters +------------------------------------ + +string imlib_image_format(int img) + Returns the image format of an image + +string imlib_image_get_filename(int img) + Returns the filename of an image + +int imlib_image_get_height(int img) + Returns the height of an image + +int imlib_image_get_width(int img) + Returns the width of an image + +bool imlib_image_has_alpha(int img) + Return a boolean for whether or not an image has an alpha + channel + +void imlib_image_modify_alpha(int img, int alpha) + Set the alpha channel of an image, or modify it if one was + already present + +void imlib_image_set_format(int img, string format) + Sets the image format of an image. + +Loading/Saving Functions +------------------------ + +void imlib_free_image(int img) + Free an image + +int imlib_load_image(string img[, int &err]) + Load a file into an image, optionally fetch an error parameter + +bool imlib_save_image(int img, string name[, int &err[, int quality]]) + Save an image to a file, at an optional quality level (1-100) + for jpegs. For pngs, the value will be converted to a + compression level (0-9) + +Creation Functions +------------------ + +int imlib_clone_image(int img) + Duplicate an image + +int imlib_create_color_range() + Create a new color range + +int imlib_create_cropped_image(int img, int srcx, int srcy, int srcw, + int srch) + Create an image from a cropped region of another image + +int imlib_create_cropped_scaled_image(int img, int srcx, int srcy, int + srcw, int srch, int dstw, int dsth) + Create a scaled image from a cropped region of another image + +int imlib_create_image(int w, int h) + Create a new image with the specified dimensions + +int imlib_create_rotated_image(int srcimg, int degrees[, int radians]) + Create a rotated copy of an image. If radians is specified, + degrees will be ignored. + +int imlib_create_scaled_image(int img, int dstw, int dsth) + Create a scaled copy of an image. If dstw or dsth is left + blank, the aspect ratio of the source image will be preserved. + +bool imlib_dump_image(int img[, int &err[, int quality]]) + Output an image at an optional quality setting + +Rendering Functions +------------------- + +void imlib_blend_image_onto_image(int dstimg, int srcimg, int malpha, + int srcx, int srcy, int srcw, int srch, int dstx, int dsty, int + dstw, int dsth, char dither, char blend, char alias) + Blend a rectangular area from an image onto an area of another + image, scaling as necessary + +Image Modification Functions +---------------------------- + +void imlib_image_blur(int img, int radius) + Blur an image with a given blur radius + +void imlib_image_flip_horizontal(int img) + Flip an image horizontally + +void imlib_image_flip_vertical(int img) + Flip an Imlib_Image vertically + +void imlib_image_flip_diagonal(int img) + Flip an image diagonally + +void imlib_image_orientate(int img, int stepping) +    Orientate an image 90 x steps + +void imlib_image_tile_horizontal(int img) + Tile an image horizontally + +void imlib_image_tile_vertical(int img) + Tile an image vertically + +void imlib_image_tile(int img) + Tile an image horizontally and diagonally + +void imlib_image_sharpen(int img, int radius) + Sharpen an image with a given sharpen radius + +Drawing on Images +----------------- + +bool imlib_image_draw_ellipse(int img, int xc, int yc, int w, int h, + int r, int g, int b, int a[, array cliprect]) + Draw an ellipse of the specified size and color on an image + +bool imlib_image_draw_line(int img, int x1, int y1, int x2, int y2, + int r, int g, int b, int a[, array cliprect]) + Draw a line of the specified size and color on an image + +bool imlib_image_draw_polygon(int img, int polygon, bool closed, int + r, int g, int b, int a[, array cliprect]) + Draw the defined polygon on an image + +bool imlib_image_draw_rectangle(int img, int x, int y, int w, int h, + int r, int g, int b, int a[, array cliprect]) + Draw a rectangle of the specified size and color on an image + +bool imlib_image_fill_color_range_rectangle(int im, int cr, int x, int + y, int width, int height, int angle) + Fill a rectangle with a color range at a given angle on an + image + +void imlib_image_fill_ellipse(int img, int xc, int yc, int w, int h, + int r, int g, int b, int a[, array cliprect]) + Fill an ellipse of the specified size and color on an image + +bool imlib_image_fill_polygon(int img, int polygon, int r, int g, int + b, int a[, array cliprect]) + Draw and fill the defined polygon on an image + +void imlib_image_fill_rectange(int img, int x, int y, int w, int h, + int r, int g, int b, int a[, array cliprect]) + Fill a rectangle of the specified size and color on an image + +Fonts and Text Functions +------------------------ + +void imlib_free_font(int font) + Free a font + +void imlib_get_text_size(int font, string str, int &w, int &h, int + direction) + Determines the width and height of a string if drawn with a + given font in the specified direction + +array imlib_list_fonts() + Return an array of all the fonts available in the font path + +int imlib_load_font(string fontname[, string encoding]) + Load a font + +void imlib_text_draw(int img, int font, int x, int y, string str, int + direction, int r, int g, int b, int a) + Draw a text string using a font onto an image + +T1 Functions +------------ + +These functions are almost identical to T1 functions in GD, please +consult GD documentation for more information on specific parameters. + +Please note that font resources are NOT interchangeable between GD and +imlib. + +int imlib_psloadfont(string pathname) + Load a new font from specified file + +bool imlib_psfreefont(int font_index) + Free memory used by a font + +bool imlib_psencodefont(int font_index, string filename) + To change a fonts character encoding vector + +bool imlib_psextendfont(int font_index, double extend) + Extend or or condense (if extend < 1) a font + +bool imlib_psslantfont(int font_index, double slant) + Slant a font + +array imlib_pstext(int img, string text, int font, int size, int x, int + y, int r, int g, int b, int a [, int space[, int tightness[, double + angle[, int antialias]]]]) + Rasterize a string over an image. + +array imlib_psbbox(string text, int font, int size [, int space, int + tightness, int angle]) + Return the bounding box needed by a string if rasterized + +Color Ranges +------------ + +void imlib_add_color_to_color_range(int cr, int x, int r, int g, int + b, int a) + Add a color to a color range at a specified distance from the + previous color in the range. A distance of 0 centers it + +void imlib_free_color_range(int cr) + Free a color range + +Polygons +-------- + +void imlib_polygon_add_point(int polygon, int x, int y) + Add a point to a given polygon + +bool imlib_polygon_contains_point(int polygon, int x, int y) + Check if a give point is inside a polygon + +void imlib_polygon_free(int polygon) + Free a polygon + +void imlib_polygon_get_bounds(int polygon, int &x1, int &y1, int &x2, + int &y2) + Get the bounding coords of a polygon + +int imlib_polygon_new() + Create a new polygon + +Image Cache +----------- + +void imlib_set_cache_size(int bytes) + Set the size of image cache + +int imlib_get_cache_size() + Get the size of image cache + +Filters +------- + +int imlib_create_filter(void) + Create a new filter + +void imlib_free_filter(int filter) + Free a filter + +void imlib_image_filter(int img, int filter) + Apply filter to an image + +void imlib_filter_set(int filter, int xoff, int yoff, int a, int r, int + g, int b) + Set weights for source pixel at (xoff,yoff). All components of + the destination pixel will be affected. + +void imlib_filter_set_alpha(int filter, int xoff, int yoff, int a, int r, + int g, int b) + Set weights for source pixel at (xoff,yoff). Only alpha component + of the destination pixel will be affected. + +void imlib_filter_set_red(int filter, int xoff, int yoff, int a, int r, + int g, int b) + Set weights for source pixel at (xoff,yoff). Only red component of + the destination pixel will be affected. + +void imlib_filter_set_green(int filter, int xoff, int yoff, int a, int r, + int g, int b) + Set weights for source pixel at (xoff,yoff). Only green component + of the destination pixel will be affected. + +void imlib_filter_set_blue(int filter, int xoff, int yoff, int a, int r, + int g, int b) + Set weights for source pixel at (xoff,yoff). Only blue component + of the destination pixel will be affected. + +void imlib_filter_constants(int filter, int a, int r, int g, int b) + Set filter constants + +void imlib_filter_divisors(int filter, int a, int r, int g, int b) + Set filter divisors + +External Filters +---------------- + +void imlib_apply_filter(int img, string filter, array params) + Apply external filter to an image + +Color Modifiers +--------------- + +int imlib_create_color_modifier(void) + Create a new color modifier + +void imlib_free_color_modifier(int cm) + Free a color modifier + +void imlib_modify_color_modifier_gamma(int cm, double gamma_value) + Adjust color modifier gamma + +void imlib_modify_color_modifier_brightness(int cm, double brightness_value) + Adjust color modifier brightness + +void imlib_modify_color_modifier_contrast(int cm, double contrast_value) + Adjust color modifier contrast + +void imlib_reset_color_modifier(int cm) + Reset color modifier to default (one-to-one) mapping + +void imlib_apply_color_modifier(int img, int cm[, int x, int y, int width, + int height]) + Apply color modifier to an image or its part + +void imlib_set_color_modifier(int cm, int index, int value[, int channels]) + Set color modifier value at given index for given channels (or all if + not specified) + +void imlib_get_color_modifier(int cm, int index, int &red, int &green, int + &blue, int &alpha + Get color modifier values at given index diff --git a/docs/class.ImlibCliprect.php b/docs/class.ImlibCliprect.php new file mode 100644 index 0000000..e731784 --- /dev/null +++ b/docs/class.ImlibCliprect.php @@ -0,0 +1,132 @@ + +* @package Imlib +* @access public +*/ +class ImlibCliprect extends ImlibColor +{ + /** + * The array defining the cliprect (x,y,w,h) + * + * @var array $cliprect + * @access private + */ + var $cliprect; + + /** + * A boolean that determines if a cliprect is in use or not + * + * @var bool $cliprect_inuse + */ + var $cliprect_inuse; + + /** + * ImlibCliprect constructor + * + * @access public + */ + function ImlibCliprect() { $this->cliprect_inuse = 0; } + + /** + * Get the four values of the cliprect + * + * @param int Upper left X coordinate to clip from + * @param int Upper left Y coordinate to clip from + * @param int Width of the cliprect + * @param int Height of the cliprect + * @access public + * @see set_cliprect() + */ + function get_cliprect(&$x,&$y,&$w,&$h) + { + list($x,$y,$w,$h) = $this->cliprect; + } + + /** + * Get the array that defines the cliprect (x,y,w,h) + * + * @return array Array defining the clipping rectangle + * @access public + * @see set_cliprect_array() + */ + function get_cliprect_array() + { + return $this->cliprect; + } + + /** + * Get the boolean that determines if a cliprect is in use or not + * + * @return bool True if the cliprect is in use + * @access public + * @see set_cliprect_inuse() + */ + function get_cliprect_inuse() + { + return $this->cliprect_inuse; + } + + /** + * Set the four values of the cliprect. 0 for X disables the cliprect. + * + * @param int Upper left X coordinate to clip from + * @param int Upper left Y coordinate to clip from + * @param int Width of the cliprect + * @param int Height of the cliprect + * @access public + * @see get_cliprect() + */ + function set_cliprect($x,$y,$w,$h) + { + if ($x == 0) + { + $this->cliprect = 0; + $this->cliprect_inuse = 0; + return; + } + $this->cliprect_inuse = 1; + $this->cliprect = Array($x,$y,$w,$h); + } + + /** + * Set the array that defines the cliprect (x,y,w,h) + * + * @param array Array that defines the cliprect + * @access public + * @see get_cliprect_array() + */ + function set_cliprect_array($arr) + { + if ($arr[0] == 0) + { + $this->cliprect = 0; + $this->cliprect_inuse = 0; + return; + } + $this->cliprect_inuse = 1; + $this->cliprect = $arr; + } + + /** + * Set the boolean that determines if the cliprect is in use + * + * @param bool True to enable, false to disable + * @access public + * @see get_cliprect_inuse() + */ + function set_cliprect_inuse($set) + { + $this->cliprect_inuse = $set; + } +}; + +?> diff --git a/docs/class.ImlibColor.php b/docs/class.ImlibColor.php new file mode 100644 index 0000000..b15e664 --- /dev/null +++ b/docs/class.ImlibColor.php @@ -0,0 +1,94 @@ + +* @package Imlib +* @access public +*/ +class ImlibColor +{ + /** + * The array defining the color (r,g,b,a) + * + * @var array $color + * @access private + */ + var $color; + + /** + * ImlibColor constructor + * + * @access public + */ + function ImlibColor() + { + $this->color = 0; + } + + /** + * Get the four color components as by-reference variables + * + * @param int &$r Red + * @param int &$g Blue + * @param int &$b Green + * @param int &$a Alpha + * @return mixed False if a color isn't set, the color array otherwise + * @access public + */ + function get_color(&$r,&$g,&$b,&$a) + { + if ($this->color) + list($r,$g,$b,$a) = $this->color; + else + return false; + + return $this->color; + } + + /** + * Get the color array currently defined, if it is defined + * + * @return mixed False if a color isn't set, the color array otherwise + * @access public + */ + function get_color_array() + { + if (!$this->color) + return false; + + return $this->color; + } + + /** + * Set the current color using the four components + * + * @param int Red + * @param int Blue + * @param int Green + * @param int Alpha + * @access public + */ + function set_color($r,$g,$b,$a) + { + $this->color = Array($r,$g,$b,$a); + } + + /** + * Set the current color using an array of 4 elements (r,g,b,a) + * + * @param array Color array + * @access public + */ + function set_color_array($arr) + { + $this->color = $arr; + } +}; + +?> diff --git a/docs/class.ImlibColorRange.php b/docs/class.ImlibColorRange.php new file mode 100644 index 0000000..6f01dd2 --- /dev/null +++ b/docs/class.ImlibColorRange.php @@ -0,0 +1,141 @@ + +* @package Imlib +* @access public +*/ +class ImlibColorRange extends ImlibCliprect +{ + /** + * Resource id# of the current color range + * + * @access private + */ + var $cr; + + /** + * Resource id# of the image to draw on + * + * @access private + */ + var $im; + + /** + * ImlibColorRange constructor + * + * @access public + */ + function ImlibColorRange() + { + $this->cr = 0; + $this->im = 0; + } + + /** + * Add a color to the color range at distance $x. + * + * A distance of 0 will center it between the previous color and the end. + * $x is ignored for the first color. + * + * @param int Distance from the previous color + * @param int Red + * @param int Blue + * @param int Green + * @param int Alpha + * @access public + */ + function add_color($x,$r,$g,$b,$a) + { + if (!is_resource($this->cr)) + return false; + + imlib_add_color_to_color_range($this->cr,$x,$r,$g,$b,$a); + } + + /** + * Add a color to the color range at distance $x. + * + * A distance of 0 will center it between the previous color and the end. + * $x is ignored for the first color. + * + * @param int Distance from the previous color + * @param array Color array (r,g,b,a) + * @access public + */ + function add_color_array($x,$arr) + { + list($r,$g,$b,$a) = $arr; + $this->add_color($x,$r,$g,$b,$a); + } + + /** + * Create a new color range + * + * @return int Resource id# of the new color range + * @access public + */ + function create() + { + if (is_resource($this->cr)) + return false; + + return $this->cr = imlib_create_color_range(); + } + + /** + * Free the current color range + * + * @access public + */ + function free() + { + if (!is_resource($this->cr)) + return false; + + imlib_free_color_range($this->cr); + unset($this->cr); + } + + /** + * Fill the current image with a rectangle using the current color range + * + * The color range will be filled in the specified box at angle $angle + * + * @param int Upper-left X coordinate of the box + * @param int Upper-left Y coordinate of the box + * @param int Width of the box + * @param int Height of the box + * @param int Angle to rotate the color range (degrees) + * @access public + */ + function fill_rectangle($x,$y,$w,$h,$angle) + { + if (!is_resource($this->im) || !is_resource($this->cr)) + return false; + + if ($this->cliprect_inuse) + return imlib_image_fill_color_range_rectangle($this->im,$this->cr, + $x,$y,$w,$h,$angle,$this->get_cliprect_array()); + else + return imlib_image_fill_color_range_rectangle($this->im,$this->cr, + $x,$y,$w,$h,$angle); + } + + /** + * Set the image to draw the color range on + * + * @param int Resource id# of the image + * @access public + */ + function set_image($im) + { + if (is_resource($im)) + $this->im = $im; + } +}; + +?> diff --git a/docs/class.ImlibDraw.php b/docs/class.ImlibDraw.php new file mode 100644 index 0000000..4c24a0b --- /dev/null +++ b/docs/class.ImlibDraw.php @@ -0,0 +1,167 @@ + +* @package Imlib +* @access public +*/ +class ImlibDraw extends ImlibCliprect +{ + /** + * Resource id# of the image to draw on + * + * @access private + */ + var $im; + + /** + * ImlibDraw constructor + * + * @access public + */ + function ImlibDraw() + { + $this->cliprect = 0; + $this->cliprect_inuse = 0; + $this->color = 0; + $this->im = 0; + } + + /** + * Callback for drawing everything + * + * Since all the drawing functions work the same way, this function + * does all the work. It takes four ints, often x,y,w,h, and passes + * them to the specified function. + * + * @param int First param + * @param int Second param + * @param int Third param + * @param int Fourth param + * @param string The name of the function to call + * @return bool False if no image is set yet + * @access private + */ + function _draw_something($x,$y,$w,$h,$cb) + { + if (!is_resource($this->im)) + return false; + + if (!$this->get_color($r,$g,$b,$a)) + list($r,$g,$b,$a) = Array(255,255,255,255); + + $cbname = 'imlib_image_' . $cb; + + if ($this->cliprect_inuse) + return $cbname($this->im,$x,$y,$w,$h,$r,$g,$b,$a, + $this->get_cliprect_array()); + else + return $cbname($this->im,$x,$y,$w,$h,$r,$g,$b,$a); + } + + /** + * Draw an ellipse + * + * @param int Center X coordinate + * @param int Center Y coordinate + * @param int Ellipse horizontal amplitude + * @param int Ellipse vertical amplitude + * + * @return bool False if no image is set yet + * @access public + */ + function draw_ellipse($x,$y,$w,$h) + { + return $this->_draw_something($x,$y,$w,$h,'draw_ellipse'); + } + + /** + * Draw a line + * + * @param int First X coordinate + * @param int First Y coordinate + * @param int Second X coordinate + * @param int Second Y coordinate + * + * @return bool False if no image is set yet + * @access public + */ + function draw_line($x1,$y1,$x2,$y2) + { + return $this->_draw_something($x1,$y1,$x2,$y2,'draw_line'); + } + + /** + * Draw a rectangle + * + * @param int Upper left X coordinate + * @param int Upper left Y coordinate + * @param int Width + * @param int Height + * + * @return bool False if no image is set yet + * @access public + */ + function draw_rectangle($x,$y,$w,$h) + { + return $this->_draw_something($x,$y,$w,$h,'draw_rectangle'); + } + + /** + * Fill an ellipse + * + * @param int Center X coordinate + * @param int Center Y coordinate + * @param int Ellipse horizontal amplitude + * @param int Ellipse vertical amplitude + * + * @return bool False if no image is set yet + * @access public + */ + function fill_ellipse($x,$y,$w,$h) + { + return $this->_draw_something($x,$y,$w,$h,'fill_ellipse'); + } + + /** + * Fill a rectangle + * + * @param int Upper left X coordinate + * @param int Upper left Y coordinate + * @param int Width + * @param int Height + * + * @return bool False if no image is set yet + * @access public + */ + function fill_rectangle($x,$y,$w,$h) + { + return $this->_draw_something($x,$y,$w,$h,'fill_rectangle'); + } + + /** + * Get the current image resource id# + * + * @access public + */ + function get_image() + { + return $this->im; + } + + /** + * Set the image resource id# to draw on + * + * @param int Image resource id# + * @access public + */ + function set_image($im) + { + $this->im = $im; + } +}; + +?> diff --git a/docs/class.ImlibImage.php b/docs/class.ImlibImage.php new file mode 100644 index 0000000..abb0462 --- /dev/null +++ b/docs/class.ImlibImage.php @@ -0,0 +1,436 @@ + +* @package Imlib +* @access public +*/ +class ImlibImage +{ + /** + * The image resource id# + * + * @var integer $id + * @see create(), get_id() + * @access private + */ + var $id; + + /** + * ImlibImage constructor + * + * @access public + */ + function ImlibImage() { $this->id = 0; } + + /** + * Callback for functions which query the current instance's attributes + * + * @param string The name of the function to call + * @return mixed String or int + * @access private + */ + function _get_cb($cb) + { + if (!is_resource($this->id)) + return false; + + $cbname = 'imlib_image_' . $cb; + return $cbname($this->id); + } + + /** + * Callback for functions which flip or tile the current instance + * + * @param string The name of the function to call + * @access private + */ + function _no_param_cb($cb) + { + if (!is_resource($this->id)) + return false; + + $cbname = 'imlib_image_' . $cb; + return $cbname($this->id); + } + + /** + * Blend a region of the current image onto the region of another ImlibImage + * + * @param int Resource id# of the destination image + * @param bool Merge alpha + * @param int Upper left source X coordinate + * @param int Upper left source Y coordinate + * @param int Source width + * @param int Source height + * @param int Upper left destination X coordinate + * @param int Upper left destination Y coordinate + * @param int Destination width + * @param int Destination height + * @param bool Dither + * @param bool Blend + * @param bool Alias + * @access public + */ + function blend_onto_image($dst,$alpha,$sx,$sy,$sw,$sh,$dx,$dy,$dw,$dh, + $dither,$blend,$alias) + { + if (!is_resource($this->id) || !is_resource($dst)) + return false; + + imlib_blend_image_onto_image($dst,$this->id,$alpha,$sx,$sy,$sw,$sh, + $dx,$dy,$dw,$dh,$dither,$blend,$alias); + } + + /** + * Blur an image with a given blur radius + * + * @param int Blur radius + * @access public + */ + function blur($r) + { + imlib_image_blur($this->id,$r); + } + + /** + * Create a clone of the current instance, return a new ImlibImage + * + * @return object ImlibImage + * @access public + */ + function create_clone() + { + if (!is_resource($this->id)) + return false; + + $clone = new ImlibImage(); + $clone->id = imlib_clone_image($this->id); + + return $clone; + } + + /** + * Create a cropped ImlibImage from a region of the current instance, return a new ImlibImage + * + * @param int Upper left X coordinate to crop from + * @param int Upper left Y coordinate to crop from + * @param int Width to crop + * @param int Height to crop + * @return object ImlibImage + * @access public + */ + function create_cropped($sx,$sy,$sw,$sh) + { + if (!is_resource($this->id)) + return false; + + $crop = new ImlibImage(); + $crop->id = imlib_create_cropped_image($this->id,$sx,$sy,$sw,$sh); + + return $crop; + } + + /** + * Create a cropped, scaled ImlibImage from a region of the current instance, return a new ImlibImage + * + * @param int Upper left X coordinate to crop from + * @param int Upper left Y coordinate to crop from + * @param int Width to crop + * @param int Height to crop + * @param int Width to scale the cropped region to + * @param int Height to scale the cropped region to + * @return object ImlibImage + * @access public + */ + function create_cropped_scaled($sx,$sy,$sw,$sh,$dw,$dh) + { + if (!is_resource($this->id)) + return false; + + $thumb = new ImlibImage(); + $thumb->id = imlib_create_cropped_scaled_image($this->id, + $sx,$sy,$sw,$sh, $dw,$dh); + return $thumb; + } + + /** + * Create an image resource to use with this instance + * + * @param int Width of the image + * @param int Height of the image + * @return int Resource id# that was created + * @access public + * @see get_id(), $id + */ + function create($width,$height) + { + if (is_resource($this->id)) + return false; + + return $this->id = imlib_create_image($width,$height); + } + + /** + * Create a rotated ImlibImage, return a new ImlibImage + * + * If radians is specified, degrees will be ignored. + * + * @param float Angle to rotate the image + * @param float Radians to rotate the image + * @return object ImlibImage + * @access public + */ + function create_rotated($degrees,$radians=0.0) + { + if (!is_resource($this->id)) + return false; + + if ($radians) + $num = $radians; + else + $num = $degrees; + + $rotated = new ImlibImage(); + $rotated->id = imlib_create_rotated_image($this->id,$num); + + return $rotated; + } + + /** + * Create a scaled ImlibImage, return a new ImlibImage + * + * If $height is not specified, it will be calculated from the dimensions + * of the current image, so that the aspect ratio is preserved. + * + * @param integer Width to scale the new image to + * @param integer Height to scale the new image to (Optional) + * @return object ImlibImage + * @access public + */ + function create_scaled($width,$height=0) + { + if (!is_resource($this->id)) + return false; + + $scaled = new ImlibImage(); + $scaled->id = imlib_create_scaled_image($this->id,$width,$height); + + return $scaled; + } + + /** + * Output the raw image data of the current instance to stdout + * + * @param integer Quality or compression level to use + * @access public + */ + function dump($quality=75) + { + if (!is_resource($this->id)) + return false; + + if (!imlib_dump_image($this->id,&$err,$quality)) + return false; + else + return true; + } + + /** + * Flip the current image diagonally + * + * @access public + */ + function flip_diagonal() { return $this->_no_param_cb('flip_diagonal'); } + + /** + * Flip the current image horizontally + * + * @access public + */ + function flip_horizontal() { return $this->_no_param_cb('flip_horizontal'); } + + /** + * Flip the current image vertically + * + * @access public + */ + function flip_vertical() { return $this->_no_param_cb('flip_vertical'); } + + /** + * Free the current instance and image resource + * + * @access public + */ + function free() + { + if (!is_resource($this->id)) + return false; + + imlib_free_image($this->id); + $this->id = 0; + } + + /** + * Get the current filename, if it's set + * + * @return mixed Filename string or false. + * @access public + */ + function get_filename() { return $this->_get_cb('get_filename'); } + + /** + * Get the current image format. The default is png. + * + * @return string Image format + * @access public + */ + function get_format() { return $this->_get_cb('format'); } + + /** + * Get the current image's height + * + * @return integer Image height + * @access public + */ + function get_height() { return $this->_get_cb('get_height'); } + + /** + * Get the current image's resource id# + * + * @return integer Current resource id# + * @access public + * @see $id, create() + */ + function get_id() { return $this->id; } + + /** + * Get the current image's width + * + * @return integer Image width + * @access public + */ + function get_width() { return $this->_get_cb('get_width'); } + + /** + * Check if the image has an alpha channel + * + * @return boolean + * @access public + */ + function has_alpha() + { + if (!is_resource($this->id)) + return false; + + return imlib_image_has_alpha($this->id); + } + + /** + * Set the alpha channel of an image + * + * @param int The alpha level to set for the image + * @access public + */ + function modify_alpha($alpha) + { + if (!is_resource($this->id)) + return false; + + imlib_image_modify_alpha($this->id,$alpha); + } + + /** + * Load an image file into the current instance + * + * @param string Filename + * @param integer Load error number. 0 for no error. + * @return integer Resource id# or false if load failed + * @access public + */ + function load($infile,$err=0) + { + if (is_resource($this->id)) + return false; + + $this->id = imlib_load_image_with_error_return($infile,&$err); + if (!is_resource($this->id) || $err) + return false; + else + return true; + } + + /** + * Save the current instance to a file + * + * @param string Filename + * @param integer Quality or compression level to use + * @return bool False if the save failed + * @access public + */ + function save($outfile,$quality=75) + { + if (!is_resource($this->id)) + return false; + + if (!imlib_save_image($this->id,$outfile,&$err,$quality)) + return false; + else + return true; + } + + /** + * Set the image format for the current instance + * + * @param string File format + * @access public + */ + function set_format($format) + { + if (!is_resource($this->id)) + return false; + + return imlib_image_set_format($this->id,$format); + } + + /** + * Sharpen an image with a given sharpen radius + * + * @param int Sharpen radius + * @access public + */ + function sharpen($r) + { + imlib_image_sharpen($this->id,$r); + } + + /** + * Seamlessly tile the current image both horizontally and vertically + * + * @access public + */ + function tile() { return $this->_no_param_cb('tile'); } + + /** + * Seamlessly tile the current image horizontally + * + * @access public + */ + function tile_horizontal() { return $this->_no_param_cb('tile_horizontal'); } + + /** + * Seamlessly tile the current image vertically + * + * @access public + */ + function tile_vertical() { return $this->_no_param_cb('tile_vertical'); } +}; + +?> diff --git a/docs/class.ImlibPoly.php b/docs/class.ImlibPoly.php new file mode 100644 index 0000000..698c752 --- /dev/null +++ b/docs/class.ImlibPoly.php @@ -0,0 +1,190 @@ + +* @package Imlib +* @access public +*/ +class ImlibPoly extends ImlibCliprect +{ + /** + * Resource id# of the image to draw on + * + * @access private + */ + var $im; + + /** + * The resource id# of the current polygon + * + * @access private + */ + var $poly; + + /** + * ImlibPoly constructor + * + * @access public + */ + function ImlibPoly() + { + $this->cliprect = 0; + $this->cliprect_inuse = 0; + $this->color = 0; + $this->im = 0; + $this->poly = 0; + } + + /** + * Add a point to the current polygon + * + * @param int X coordinate + * @param int Y coordinate + * @return bool False if there is no polygon set + * @access public + */ + function add_point($x,$y) + { + if (!is_resource($this->poly)) + return false; + + imlib_polygon_add_point($this->poly,$x,$y); + } + + /** + * Checks if the current polygon contains a given point + * + * @param int X coordinate + * @param int Y coordinate + * @return bool True if it does, false otherwise + * @access public + */ + function contains_point($x,$y) + { + if (!is_resource($this->poly)) + return false; + + return imlib_polygon_contains_point($this->poly,$x,$y); + } + + /** + * Draw the current polygon on the current image + * + * @param integer If true, the polygon will be drawn with the endpoints connected + * @return bool False if there is no polygon or image set + * @access public + */ + function draw($closed=1) + { + if (!is_resource($this->im) || !is_resource($this->poly)) + return false; + + if (!$this->get_color($r,$g,$b,$a)) + list($r,$g,$b,$a) = Array(255,255,255,255); + + if ($this->cliprect_inuse) + imlib_image_draw_polygon($this->im,$this->poly,$closed,$r,$g,$b,$a, + $this->get_cliprect_array()); + else + imlib_image_draw_polygon($this->im,$this->poly,$closed,$r,$g,$b,$a); + } + + /** + * Fill the current polygon on the current image + * + * @return bool False if there is no polygon or image set + * @access public + */ + function fill() + { + if (!is_resource($this->im) || !is_resource($this->poly)) + return false; + + if (!$this->get_color($r,$g,$b,$a)) + list($r,$g,$b,$a) = Array(255,255,255,255); + + if ($this->cliprect_inuse) + imlib_image_fill_polygon($this->im,$this->poly,$r,$g,$b,$a, + $this->get_cliprect_array()); + else + imlib_image_fill_polygon($this->im,$this->poly,$r,$g,$b,$a); + } + + /** + * Free the current polygon + * + * @return bool False if there is no polygon or image set + * @access public + */ + function free() + { + if (!is_resource($this->poly)) + return false; + + imlib_polygon_free($this->poly); + $this->poly = 0; + } + + /** + * Get the bounds of the polygon + * + * @param int Upper left X coordinate + * @param int Upper left Y coordinate + * @param int Lower right X coordinate + * @param int Lower right Y coordinate + * @return bool False if there is no polygon or image set + * @access public + */ + function get_bounds(&$x1,&$y1,&$x2,&$y2) + { + if (!is_resource($this->poly)) + return false; + + imlib_polygon_get_bounds($this->poly,&$x1,&$y1,&$x2,&$y2); + } + + /** + * Get the current image resource id# + * + * @return int Current image resource id# + * @access public + */ + function get_image() + { + return $this->im; + } + + /** + * Create a new polygon + * + * @return int Resource id# of the new polygon + * @access public + */ + function new_poly() + { + if (is_resource($this->poly)) + return false; + + return $this->poly = imlib_polygon_new(); + } + + /** + * Set the image resource id# to draw on + * + * @param int Image resource id# + * @access public + */ + function set_image($im) + { + $this->im = $im; + } +}; + +?> diff --git a/docs/class.ImlibText.php b/docs/class.ImlibText.php new file mode 100644 index 0000000..4bc7273 --- /dev/null +++ b/docs/class.ImlibText.php @@ -0,0 +1,147 @@ + +* @package Imlib +* @access public +*/ +class ImlibText extends ImlibColor +{ + /** + * Resource id# of the currently loaded font + * + * @access private + */ + var $fnt; + + /** + * Resource id# of the image to draw on + * + * @access private + */ + var $im; + + /** + * ImlibText constructor + * + * @access public + */ + function ImlibText() + { + $this->fnt = 0; + $this->im = 0; + } + + /** + * Draw a text string onto the current image + * + * @param int X coordinate of the upper left corner of the string + * @param int Y coordinate of the upper left corner of the string + * @param string Text string to draw + * @param int Direction of the text + * @return bool False if no font is loaded + * @access public + */ + function draw($x,$y,$str,$dir=IMLIB_TEXT_TO_RIGHT) + { + if (!is_resource($this->fnt) || !is_resource($this->im)) + return false; + + // If we don't have a color set yet, we'll default to white + if (!$this->get_color($r,$g,$b,$a)) + list($r,$g,$b,$a) = Array(255,255,255,255); + + return imlib_text_draw($this->im,$this->fnt,$x,$y,$str,$dir, + $r,$g,$b,$a); + } + + /** + * Free the currently loaded font + * + * @return bool False if no font is loaded + * @access public + */ + function free() + { + if (!is_resource($this->fnt)) + return false; + + imlib_free_font($this->fnt); + $this->fnt = 0; + } + + /** + * Get the current image resource id# + * + * @return integer Image resource id# + * @access public + */ + function get_image() + { + return $this->im; + } + + /** + * Get the width and height of a given string if it were drawn + * + * @param string String to measure + * @param int &$w Width the string would be + * @param int &$h Height the string would be + * @param int Direction to measure the string + * @return bool False if no font is loaded + * @access public + */ + function get_size($str,&$w,&$h,$dir=IMLIB_TEXT_TO_RIGHT) + { + if (!is_resource($this->fnt)) + return false; + + return imlib_get_text_size($this->fnt,$str,&$w,&$h,$dir); + } + + /** + * Load a font + * + * If the font is in the font path, it can be referred to by font name, + * and the path does not need to be specified. Otherwise, it must be + * referred to by filename. + * + * @param string Path, or current directory if passed blank + * @param string Font name + * @param int Font size + * @return bool False if no font is loaded + * @access public + */ + function load($path,$font,$size) + { + $fontdata = ''; + + if (is_resource($this->fnt)) + return false; + + if ($path) + $fontdata = $path; + $fontdata .= $font . '/' . $size; + + return $this->fnt = imlib_load_font($fontdata); + } + + /** + * Set the image resource id# to draw on + * + * @param int Image resource id# + * @access public + */ + function set_image($im) + { + $this->im = $im; + } +}; + +?> diff --git a/docs/package.Imlib.php b/docs/package.Imlib.php new file mode 100644 index 0000000..96eb3c3 --- /dev/null +++ b/docs/package.Imlib.php @@ -0,0 +1,11 @@ + -- cgit v1.2.3