Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: 网址
Expand Down
28 changes: 27 additions & 1 deletion zhtmltopdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down