#if HAVE_GD_BUNDLED
PHP_FE(imagelayereffect, NULL)
PHP_FE(imagecolormatch, NULL)
+ PHP_FE(imagexbm, NULL)
#endif
/* gd filters */
#ifdef HAVE_GD_BUNDLED
}
/* }}} */
+/* {{{ proto int imagexbm(int im, string filename [, int foreground])
+ Output XBM image to browser or file */
+#if HAVE_GD_BUNDLED
+PHP_FUNCTION(imagexbm)
+{
+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
+}
+#endif
+/* }}} */
+
#ifdef HAVE_GD_GIF_CREATE
/* {{{ proto bool imagegif(resource im [, string filename])
Output GIF image to browser or file */
-#include "php_gd.h"
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Stanislav Malyshev <stas@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+#include "php_gd.h"
#define CTX_PUTC(c,ctx) ctx->putC(ctx, c)
efree(ctx);
}
}
-
+
+/* {{{ _php_image_output_ctx */
static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
{
zval **imgind, **file, **quality;
int q = -1, i;
gdIOCtx *ctx;
- /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
+ /* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
+ * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
+ * from imagey<type>().
+ */
+ if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) {
+ WRONG_PARAM_COUNT;
+ }
if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE)
{
WRONG_PARAM_COUNT;
fn = Z_STRVAL_PP(file);
if (argc == 3) {
convert_to_long_ex(quality);
- q = Z_LVAL_PP(quality);
+ q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */
}
}
case PHP_GDIMG_TYPE_JPG:
(*func_p)(im, ctx, q);
break;
+ case PHP_GDIMG_TYPE_XBM:
case PHP_GDIMG_TYPE_WBM:
- for(i=0; i < gdImageColorsTotal(im); i++) {
- if(gdImageRed(im, i) == 0) break;
- }
- (*func_p)(im, i, ctx);
+ if (argc < 3) {
+ for(i=0; i < gdImageColorsTotal(im); i++) {
+ if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
+ }
+ q = i;
+ }
+ if (image_type == PHP_GDIMG_TYPE_XBM) {
+ (*func_p)(im, fn, q, ctx);
+ } else {
+ (*func_p)(im, q, ctx);
+ }
break;
default:
(*func_p)(im, ctx);
RETURN_TRUE;
}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h);
gdImagePtr gdImageCreateFromXbm(FILE *fd);
+void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out);
gdImagePtr gdImageCreateFromXpm (char *filename);
#define MAX_XBM_LINE_SIZE 255
-gdImagePtr
-gdImageCreateFromXbm (FILE * fd)
+/* {{{ gdImagePtr gdImageCreateFromXbm */
+gdImagePtr gdImageCreateFromXbm(FILE * fd)
{
char fline[MAX_XBM_LINE_SIZE];
char iname[MAX_XBM_LINE_SIZE];
gdImageDestroy(im);
return 0;
}
+/* }}} */
+
+/* {{{ gdCtxPrintf */
+void gdCtxPrintf(gdIOCtx * out, const char *format, ...)
+{
+ char *buf;
+ int len;
+ va_list args;
+
+ va_start(args, format);
+ len = vspprintf(&buf, 0, format, args);
+ va_end(args);
+ out->putBuf(out, buf, len);
+ efree(buf);
+}
+/* }}} */
+
+/* {{{ gdImageXbmCtx */
+void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
+{
+ int x, y, c, b, sx, sy, p;
+ char *name, *f;
+ size_t i, l;
+
+ name = file_name;
+ if ((f = strrchr(name, '/')) != NULL) name = f+1;
+ if ((f = strrchr(name, '\\')) != NULL) name = f+1;
+ name = estrdup(name);
+ if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0';
+ if ((l = strlen(name)) == 0) {
+ efree(name);
+ name = estrdup("image");
+ } else {
+ for (i=0; i<l; i++) {
+ /* only in C-locale isalnum() would work */
+ if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) {
+ name[i] = '_';
+ }
+ }
+ }
+
+ gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image));
+ gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image));
+ gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name);
+
+ efree(name);
+
+ b = 1;
+ p = 0;
+ c = 0;
+ sx = gdImageSX(image);
+ sy = gdImageSY(image);
+ for (y = 0; y < sy; y++) {
+ for (x = 0; x < sx; x++) {
+ if (gdImageGetPixel(image, x, y) == fg) {
+ c |= b;
+ }
+ if ((b == 128) || (x == sx && y == sy)) {
+ b = 1;
+ if (p) {
+ gdCtxPrintf(out, ", ");
+ if (!(p%12)) {
+ gdCtxPrintf(out, "\n ");
+ p = 12;
+ }
+ }
+ p++;
+ gdCtxPrintf(out, "0x%02X", c);
+ c = 0;
+ } else {
+ b <<= 1;
+ }
+ }
+ }
+ gdCtxPrintf(out, "};\n");
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
PHP_FUNCTION(imagelayereffect);
PHP_FUNCTION(imagecolormatch);
PHP_FUNCTION(imagefilter);
+PHP_FUNCTION(imagexbm);
#endif
PHP_GD_API int phpi_get_le_gd(void);