I did a memory_get_usage() before line 142, and it was 138356 so it isn’t anything else that’s eating up some memory. Not sure what my next step is to fix this. Thoughts?
getimagesize can read the dimensions of a SWF file as long as the canvas isn’t empty.
What happens if you increase the memory_limit even more?
I don’t think it’s wise to rely on memory_get_usage() in this manner as the compiled bytecode may have many more steps between your last memory_get_usage() and when it actually tries to read the dimensions of the file. Perhaps it loads the entire file into memory (+/- 8Mb) and then unzips it and tries to read the canvas (even more memory).
An increase in memory does actually solve the problem. I have it up to 30M right now. It doesn’t seem there’s an easier way to get the dimensions of a swf, so I guess memory increases will have to do. I just found it curious that the error message PHP gave wasn’t really accurate.
The source code confirms this too, cheers Immerse.
static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
{
char *temp;
int itype = 0;
struct gfxinfo *result = NULL;
if (!stream) {
RETURN_FALSE;
}
itype = php_getimagetype(stream, NULL TSRMLS_CC);
switch( itype) {
case IMAGE_FILETYPE_GIF:
result = php_handle_gif(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_JPEG:
if (info) {
result = php_handle_jpeg(stream, *info TSRMLS_CC);
} else {
result = php_handle_jpeg(stream, NULL TSRMLS_CC);
}
break;
case IMAGE_FILETYPE_PNG:
result = php_handle_png(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_SWF:
result = php_handle_swf(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_SWC:
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
result = php_handle_swc(stream TSRMLS_CC);
#else
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled");
#endif
break;
case IMAGE_FILETYPE_PSD:
result = php_handle_psd(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_BMP:
result = php_handle_bmp(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_TIFF_II:
result = php_handle_tiff(stream, NULL, 0 TSRMLS_CC);
break;
case IMAGE_FILETYPE_TIFF_MM:
result = php_handle_tiff(stream, NULL, 1 TSRMLS_CC);
break;
case IMAGE_FILETYPE_JPC:
result = php_handle_jpc(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_JP2:
result = php_handle_jp2(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_IFF:
result = php_handle_iff(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_WBMP:
result = php_handle_wbmp(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_XBM:
result = php_handle_xbm(stream TSRMLS_CC);
break;
case IMAGE_FILETYPE_ICO:
result = php_handle_ico(stream TSRMLS_CC);
break;
default:
case IMAGE_FILETYPE_UNKNOWN:
break;
}
if (result) {
array_init(return_value);
add_index_long(return_value, 0, result->width);
add_index_long(return_value, 1, result->height);
add_index_long(return_value, 2, itype);
spprintf(&temp, 0, "width=\\"%d\\" height=\\"%d\\"", result->width, result->height);
add_index_string(return_value, 3, temp, 0);
if (result->bits != 0) {
add_assoc_long(return_value, "bits", result->bits);
}
if (result->channels != 0) {
add_assoc_long(return_value, "channels", result->channels);
}
add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1);
efree(result);
} else {
RETURN_FALSE;
}
}
/* }}} */