3
@@ -46,33 +46,6 @@ static void _php_image_output_ctxfree(st
7
-static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) {
9
- php_stream * stream = (php_stream *)ctx->data;
11
- php_stream_write(stream, &ch, 1);
14
-static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l)
16
- php_stream * stream = (php_stream *)ctx->data;
18
- return php_stream_write(stream, (void *)buf, l);
21
-static void _php_image_stream_ctxfree(struct gdIOCtx *ctx)
26
- php_stream_close((php_stream *) ctx->data);
34
/* {{{ _php_image_output_ctx */
35
static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
37
@@ -81,12 +54,11 @@ static void _php_image_output_ctx(INTERN
39
long quality, basefilter;
42
int argc = ZEND_NUM_ARGS();
46
- zval *to_zval = NULL;
49
/* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
50
* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
51
@@ -103,7 +75,7 @@ static void _php_image_output_ctx(INTERN
55
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z/!ll", &imgind, &to_zval, &quality, &basefilter) == FAILURE) {
56
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|p!ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) {
60
@@ -117,21 +89,19 @@ static void _php_image_output_ctx(INTERN
64
- if (argc > 1 && to_zval != NULL) {
65
- if (Z_TYPE_P(to_zval) == IS_RESOURCE) {
66
- php_stream_from_zval_no_verify(stream, &to_zval);
67
- if (stream == NULL) {
70
- } else if (Z_TYPE_P(to_zval) == IS_STRING) {
71
- stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
72
- if (stream == NULL) {
76
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream");
77
+ if (argc > 1 && file_len) {
78
+ if (strlen(file) != file_len) {
81
+ PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");
83
+ fp = VCWD_FOPEN(file, "wb");
85
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", file, strerror(errno));
89
+ ctx = gdNewFileCtx(fp);
91
ctx = emalloc(sizeof(gdIOCtx));
92
ctx->putC = _php_image_output_putc;
93
@@ -145,14 +115,6 @@ static void _php_image_output_ctx(INTERN
98
- ctx = emalloc(sizeof(gdIOCtx));
99
- ctx->putC = _php_image_stream_putc;
100
- ctx->putBuf = _php_image_stream_putbuf;
101
- ctx->gd_free = _php_image_stream_ctxfree;
102
- ctx->data = (void *)stream;
106
case PHP_GDIMG_CONVERT_WBM:
108
@@ -189,11 +151,12 @@ static void _php_image_output_ctx(INTERN