Attached are the diffs from gd.c and php_gd.h that add a new function to PHP:
int ImageRawRectangle (int im, int x, int y, int x_size, int y_size, string
data)
ImageRawRectangle() translates the data string into a rectangle of size x_size
b y_size in the image im. The data string represents the image data in normal
scanline format (left-to-right, top-to-bottom). If the image is palletted, the
function expects a string of bytes x_size * y_size, each representing an index
of a pixel. If the image is true color, the function expects a string of bytes
x_size * y_size *4. Each group of four bytes represents the Alpha, Red, Green,
and Blue components of a pixel.
Example 1. Storing a fill pattern in the PHP source.
<?PHP
header ("Content-type: image/png");
$checkerFillData = chr(0x00).chr(0xff).chr(0x00).chr(0x00) . chr
(0x00).chr(0xff).chr(0x00).chr(0x00) . chr(0x00).chr(0xff).chr(0x00).chr
(0x00) . chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr(0x00).chr(0x80).chr
(0x80).chr(0x80) . chr(0x00).chr(0x80).chr(0x80).chr(0x80).
chr(0x00).chr(0xff).chr(0x00).chr(0x00) . chr(0x00).chr
(0xff).chr(0x00).chr(0x00) . chr(0x00).chr(0xff).chr(0x00).chr(0x00) . chr
(0x00).chr(0x80).chr(0x80).chr(0x80) . chr(0x00).chr(0x80).chr(0x80).chr
(0x80) . chr(0x00).chr(0x80).chr(0x80).chr(0x80).
chr(0x00).chr(0xff).chr(0x00).chr(0x00) . chr(0x00).chr
(0xff).chr(0x00).chr(0x00) . chr(0x00).chr(0xff).chr(0x00).chr(0x00) . chr
(0x00).chr(0x80).chr(0x80).chr(0x80) . chr(0x00).chr(0x80).chr(0x80).chr
(0x80) . chr(0x00).chr(0x80).chr(0x80).chr(0x80).
chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr(0x00).chr
(0x80).chr(0x80).chr(0x80) . chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr
(0x00).chr(0xff).chr(0x00).chr(0x00) . chr(0x00).chr(0xff).chr(0x00).chr
(0x00) . chr(0x00).chr(0xff).chr(0x00).chr(0x00).
chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr(0x00).chr
(0x80).chr(0x80).chr(0x80) . chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr
(0x00).chr(0xff).chr(0x00).chr(0x00) . chr(0x00).chr(0xff).chr(0x00).chr
(0x00) . chr(0x00).chr(0xff).chr(0x00).chr(0x00).
chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr(0x00).chr
(0x80).chr(0x80).chr(0x80) . chr(0x00).chr(0x80).chr(0x80).chr(0x80) . chr
(0x00).chr(0xff).chr(0x00).chr(0x00) . chr(0x00).chr(0xff).chr(0x00).chr
(0x00) . chr(0x00).chr(0xff).chr(0x00).chr(0x00);
$checkerFillImage = ImageCreateTrueColor(6, 6);
ImageRawRectangle($checkerFillImage, 0, 0, 6, 6, $checkerFillData);
$im = ImageCreateTrueColor(200, 100);
ImageSetTile($im, $checkerFillImage);
ImageFilledEllipse ($im, 100, 50, 150, 75, IMG_COLOR_TILED);
ImagePng ($im);
?>
Example 2. Reading raw pixel data from disk.
Example 3. Storing icons in the PHP source.
Please respond with comments, revisions or suggestions. I would like to see
these changes incorporated into the next official PHP build.
Thanks!
---------------------------------------------
This message was sent using netINS Webmail.
Don't settle for less, get netINS!
http://netINS.net
*** php-4.1.1/ext/gd/gd.c.orig Fri Nov 16 06:02:30 2001
--- php-4.1.1/ext/gd/gd.c Fri Feb 22 04:14:30 2002
***************
*** 163,168 ****
--- 163,169 ----
PHP_FE(imagefill,
NULL)
PHP_FE(imagefilledpolygon, NULL)
PHP_FE(imagefilledrectangle, NULL)
+ PHP_FE(imagerawrectangle, NULL)
PHP_FE(imagefilltoborder, NULL)
PHP_FE(imagefontwidth, NULL)
PHP_FE(imagefontheight, NULL)
***************
*** 1973,1978 ****
--- 1974,2041 ----
RETURN_TRUE;
}
/* }}} */
+
+ /* {{{ proto int imagerawrectangle(int im, int x, int y, int x_size, int y_size,
+string str)
+ Draw a rectangle filled with pixels represented by raw pixel data in the string*/
+ PHP_FUNCTION(imagerawrectangle)
+ {
+ zval **IM, **x, **y, **x_size, **y_size, **str;
+ gdImagePtr im;
+ long _x, _y, _x_size, _y_size, x_count, y_count, pixel_start;
+ int col;
+ char *_str;
+
+
+ if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x, &y,
+&x_size, &y_size, &str) == FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
+
+ convert_to_long_ex(x);
+ convert_to_long_ex(y);
+ convert_to_long_ex(x_size);
+ convert_to_long_ex(y_size);
+ convert_to_string_ex(str);
+
+ _x = Z_LVAL_PP(x);
+ _y = Z_LVAL_PP(y);
+ _x_size = Z_LVAL_PP(x_size);
+ _y_size = Z_LVAL_PP(y_size);
+
+ _str = Z_STRVAL_PP(str);
+
+ #if HAVE_LIBGD20
+ if (gdImageTrueColor(im)) {
+ if (Z_STRLEN_PP(str) == (_x_size * _y_size * 4)) {
+ for (y_count = 0; y_count < _y_size; y_count++) {
+ for (x_count = 0; x_count < _x_size; x_count++) {
+ pixel_start = (_x_size * y_count + x_count) *
+4;
+ col = gdTrueColorAlpha((unsigned
+char)_str[pixel_start + 1], (unsigned char)_str[pixel_start + 2], (unsigned
+char)_str[pixel_start + 3], (unsigned char)_str[pixel_start]);
+ gdImageSetPixel(im, _x + x_count, _y +
+y_count, col);
+ }
+ }
+ } else {
+ php_error(E_ERROR, "%s(): Data is the wrong length, expecting
+four bytes (ARGB) per pixel", get_active_function_name(TSRMLS_C));
+ }
+ } else {
+ #endif
+ if (Z_STRLEN_PP(str) == (_x_size * _y_size)) {
+ for (y_count = 0; y_count < _y_size; y_count++) {
+ for (x_count = 0; x_count < _x_size; x_count++) {
+ gdImageSetPixel(im, _x + x_count, _y +
+y_count, (unsigned char)_str[_x_size * y_count + x_count]);
+ }
+ }
+ } else {
+ php_error(E_ERROR, "%s(): Data is the wrong length, expecting
+one byte (index) per pixel", get_active_function_name(TSRMLS_C));
+ }
+ #if HAVE_LIBGD20
+ }
+ #endif
+
+ RETURN_TRUE;
+ }
+ /* }}} */
/* {{{ proto int imagearc(int im, int cx, int cy, int w, int h, int s, int e, int
col)
Draw a partial ellipse */
*** php-4.1.1/ext/gd/php_gd.h.orig Fri Aug 24 15:07:07 2001
--- php-4.1.1/ext/gd/php_gd.h Fri Feb 22 04:17:09 2002
***************
*** 125,130 ****
--- 125,131 ----
PHP_FUNCTION(imagefill);
PHP_FUNCTION(imagefilledpolygon);
PHP_FUNCTION(imagefilledrectangle);
+ PHP_FUNCTION(imagerawrectangle);
PHP_FUNCTION(imagefilltoborder);
PHP_FUNCTION(imagefontwidth);
PHP_FUNCTION(imagefontheight);
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php