Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux wkhtmltoimage将html转换为图像Perl和Centos_Linux_Perl_Centos_Wkhtmltoimage - Fatal编程技术网

Linux wkhtmltoimage将html转换为图像Perl和Centos

Linux wkhtmltoimage将html转换为图像Perl和Centos,linux,perl,centos,wkhtmltoimage,Linux,Perl,Centos,Wkhtmltoimage,我正在尝试使用Perl模块将html和web页面转换为图像。下面的脚本和代码可以从命令行运行,但如果从浏览器调用脚本,则无法运行 Update: If I run the script from the shell as a root user, it runs without error, if I switch to the domain user where the script is located, I get that error, seems it is executable p

我正在尝试使用Perl模块将html和web页面转换为图像。下面的脚本和代码可以从命令行运行,但如果从浏览器调用脚本,则无法运行

Update:

If I run the script from the shell as a root user, it runs without
error, if I switch to the domain user where the script is located,
I get that error, seems it is executable permissions for domain owner.
错误是:

error running '/usr/local/bin/wkhtmltoimage': '/usr/local/bin/wkhtmltoimage http://yahoo.com 
/home/xxxx/public_html/pdfwebkit/output.png' died with signal 11, with coredump at 
/usr/local/perl-5.18.1/lib/site_perl/5.18.1/MooseX/Role/Cmd.pm line 128.
MooseX::Role::Cmd::run(WKHTMLTOPDF=HASH(0x2714260), "http://yahoo.com", 
"/home/xxxx/public_html/pdfwebkit/output.png") called at /usr/local/
perl-5.18.1/lib/site_perl/5.18.1/WKHTMLTOPDF.pm line 645 WKHTMLTOPDF::generate(WKHTMLT
OPDF=HASH(0x2714260)) called at htmltoimage.cgi line xxx main::convert_using_WKHTMLTOPDF_image("http://yahoo.com", 
"/home/xxxx/public_html/pdfwebkit/output.png") called at htmltoimage.cgi line xx
我使用的代码是:

#!/usr/bin/perl
#!C:\perl\bin\perl.exe
print "Content-type: text/html;charset=utf-8\n\n";
use File::Spec::Functions;
use File::Basename;
BEGIN {
    $|=1;
    use CGI::Carp qw(fatalsToBrowser set_message);
    sub handle_errors {
        #print "Content-type: text/html;charset=utf-8\n\n";
        my $msg = shift;
        print qq!<h1><font color="red">Software Error</font></h1>!;
        print qq!<p>$msg</p>!;
    }
    set_message(\&handle_errors);
}

$|=1;
my ($Script, $Bin);
if ($ENV{SCRIPT_FILENAME}) {
    ($Script, $Bin) = fileparse($ENV{SCRIPT_FILENAME});
}
else {
    ($Script, $Bin) = fileparse(__FILE__);
}

use WKHTMLTOPDF;

    my $outfile = catfile ($Bin, 'output.jpg');
    print "Converting url to image file $outfile...<br>\n";
    convert_using_WKHTMLTOPDF_image('http://yahoo.com', $outfile);
    print "Finished...<br>\n";
    exit;

sub convert_using_WKHTMLTOPDF_image {
    my ($page, $output) = @_;
    my $pdf = new WKHTMLTOPDF;
    my $bin = '/usr/local/bin/wkhtmltoimage';
    #my $bin = 'C:/Program Files/wkhtmltopdf/bin/wkhtmltoimage.exe';
    $pdf->bin_name($bin);
    $pdf->_input_file($page);
    $pdf->_output_file($output);
    #$pdf->grayscale(1);
    $pdf->generate;
}

sub convert_html_to_image_direct {
    my ($page, $output) = @_;
    my $bin = '/usr/local/bin/wkhtmltoimage --quiet ';
    my $out = `$bin $page $output`;
    print "out: $out<br>\n";
    return $out;
}
我使用Centos 6服务器进行了测试(在IE 11/Win 8.1中),运行良好,只需对我希望保存它的文件夹的路径做一点更改

我的输出是 正在将url转换为图像文件/home/user/./bitterruth.jpg。。。 完成


这正是您所期望的…

是bin文件的权限还是web服务器用户权限?我的服务器是Centos 6上的Apache。在命令行上,我在3个不同的URL中有2个尝试了这个脚本,但都没有出现错误!我所做的更改如下所示:my$outfile=catfile(“/home/./../outputfolder/”,'output.jpg');使用_WKHTMLTOPDF_图像(',“$outfile”)转换_;我没有使用$Script,$Bin!至于权限,我有0755的输出文件夹,而0744也可以。确保您的脚本具有0755的权限!脚本有0755,它运行并打印上述错误。我不知道发生了什么事。
# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.11.0_rc1-static-amd64.tar.bz2
# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
# tar xvjf wkhtmltoimage-0.11.0_rc1-static-amd64.tar.bz2
# tar xvjf wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
# chown root:root wkhtmltopdf-amd64
# chown root:root wkhtmltoimage-amd64
# mv wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
# mv wkhtmltoimage-amd64 /usr/bin/wkhtmltoimage

// dependencies
# yum install -y libXrender libXext openssl openssl-devel fontconfig