diff --git a/README.md b/README.md index 7400322..7a33615 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ zhtmltopdf, 把html页面转成pdf或image的php扩展 //参数2: 生成的img文件名 (可选) //参数3: 图片fmt(可选) jpeg(默认), png, bmp //参数4: 图片质量(可选) 默认80 + //参数5: 窗口宽度像素(可选) 默认1000 + //参数6: 窗口高度像素(可选) 默认1000 zhtml2img("http://www.baidu.com", "./baidu.jpg"); //参数1: 网址 diff --git a/zhtmltopdf.c b/zhtmltopdf.c index 4d5e8f4..c63b17e 100644 --- a/zhtmltopdf.c +++ b/zhtmltopdf.c @@ -225,12 +225,14 @@ PHP_FUNCTION(zhtml2img) char *fmt = NULL; char *out = NULL; long quality = 80; + long screenWidth = 1000; + long screenHeight = NULL; int url_len, fmt_len, out_len; long len; const unsigned char * data; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssl", &url, &url_len, &out, &out_len, &fmt, &fmt_len, &quality) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sslll", &url, &url_len, &out, &out_len, &fmt, &fmt_len, &quality, &screenWidth, &screenHeight) == FAILURE) { return; } @@ -268,6 +270,30 @@ PHP_FUNCTION(zhtml2img) assert(cnt == n); wkhtmltoimage_set_global_setting(gs,"quality",buffer); + // 设置宽度 + if (screenWidth < 1) { + screenWidth = 1000; + } + const int k = snprintf(NULL,0,"%ld",screenWidth); + char swBuffer[k+1]; + int swCnt = snprintf(swBuffer,k+1,"%ld",screenWidth); + swBuffer[k] = '\0'; + assert(swCnt == k); + wkhtmltoimage_set_global_setting(gs, "screenWidth", swBuffer); + + // 设置高度 + if (screenHeight) { + if (screenHeight < 1) { + screenHeight = 1000; + } + const int h = snprintf(NULL,0,"%ld",screenHeight); + char shBuffer[h+1]; + int shCnt = snprintf(shBuffer,h+1,"%ld",screenHeight); + shBuffer[h] = '\0'; + assert(shCnt == h); + wkhtmltoimage_set_global_setting(gs, "screenHeight", shBuffer); + } + c = wkhtmltoimage_create_converter(gs, NULL); if (!wkhtmltoimage_convert(c)) {