returning long string from gd php function?
| From: | (Carlos A. Pero) | Date: | Sun, 25 Jun 2000 00:15:16 +0000 |
| Subject: | returning long string from gd php function? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-22253@lists.php.net to get a copy of this message | ||
I've created a new function in the gd library and in php_gd to read and
write comment blocks in the gif file (I have a Unisys license). The gd
library for this reading and writing works fine, as proven by command-line
gd utilities. The trouble I am having is reading a long (more than 2000
characters) comment out of a file and returning it to a PHP script. I'm not
much of a C programmer, I just modify things by imitating other functions.
Here is the function in ext/gd/gd.c
/* im, comment */
/* {{{ proto int imagecomment(int im [, string c])
Add or delete the comment */
PHP_FUNCTION(imagecomment)
{
zval **IM, **C = NULL;
gdImagePtr im;
unsigned char *string = NULL;
unsigned char *output = NULL;
unsigned char *input = NULL;
int argc;
GDLS_FETCH();
argc = ARG_COUNT(ht);
switch(argc) {
case 1:
if (zend_get_parameters_ex(1, &IM) == FAILURE) {
WRONG_PARAM_COUNT;
}
break;
case 2:
if (zend_get_parameters_ex(2, &IM, &C) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(C);
break;
default:
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", GDG(le_gd));
php_error(E_WARNING, "Comment3: =%s=", im->comment);
if (argc == 2) {
string = ( unsigned char *) (*C)->value.str.val;
gdImageComment( im, string );
}
/* output = gdImageGetComment( im ); */
output = im->comment;
php_error(E_WARNING, "Comment4: =%d=%s=", strlen(output), output);
RETVAL_STRINGL(output, strlen(output), 1);
}
/* }}} */
I'm really kind of lost at the end. I'm not sure whether to call
gdImageGetComment, or just use im->comment as coded above. And I don't know
what is the best what to assign or pass around long strings. Comment3 does
indeed show the comment line intact, the trouble is returning it
effectively. Again, for comments less than 2000 characters or so, it works.
Larger (up to 10,000) gives a garbled comment back to the script, presumably
because enough memory wasn't allocated or something.
Could someone maybe please describe the way this output should be defined,
populated, and returned?
Thanks.