Inkscape,convert,htmltoimage合成图片对比

  1. Inkscape

源图大小  4.62M

    public function inkscapeImage(){

        //tiff 264870.34277344ms

        //time=60582.803955078ms,分辨率:6000x23226,size=58.6M

        // real    0m29.425s

        // user    0m28.805s

        // sys     0m0.547s

        $beginTime = microtimeFloat();

        $svg = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';

        $svg .= '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="3000px" height="13000px" xml:space="default" viewbox="0 0 3000 14000">'

        $x = 10;

        $y = 10;

        for($i=0;$i<=59;$i++){

            $h = intval($i/4);

            $l = $i%4;

            $x = 10+(($l)*727);

            $y = $h*10+($h*720);

            $svg .= '<image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/tmp/N690071-4XZJZY-1-HCMB008-StandardSize-300DPI-NO1-Style_H-1-printArea-12537975.png"  preserveAspectRatio="none" x="'.$x.'" y="'.$y.'" width="727" height="720" />';

        }

        $svg .= '</svg>';

        $name = '/tmp/inkscapeImage'.time().'.svg';

        file_put_contents($name,$svg);

        $DataHelper = new DataHelper();

        $inkscapePath = $DataHelper->getInkscapePath();

        $shell = $inkscapePath.' '.$name.' -d 150 -e /tmp/inkscapeImage.png';

        echo $shell;

        exec($shell);

        dump(microtimeFloat()-$beginTime);die;

    }

生成

格式:  PNG,tiff(两种格式一样)

Dpi:   150,

WH:  10000*38710px,

Size: 318M

Time:260S

Cpu:98%(inkscape占满一个逻辑cpu)

开通两个inkscape进程和wkthmltoimage情况下,inkscape占用210%的cpu

开通三个inkscape进程,inkscape占用300%cpu上下

  1. Convert

    public function compositeToImg(){

        // $imagick = new \Imagick('/tmp/compositeToimg.png');

        // dump($imagick->getImageResolution());die;

        // real    0m46.566s

        // user    2m41.471s

        // sys     0m14.048s

        set_time_limit(0);

        $beginTime = microtimeFloat();

        $shell = 'convert -size 6000x600000 xc:none -density 150x150 ';

        $x = 10;

        $y = 10;

        $file = ' /tmp/N690071-4XZJZY-1-HCMB008-StandardSize-300DPI-NO1-Style_H-1-printArea-12537975.png';

        for($i=0;$i<=1628;$i++){

            $h = intval($i/4);

            $l = $i%4;

            $x = 10+(($l)*1453);

            $y = $h*10+($h*1441);

            $shell .= $file.' -geometry +'.$x.'+'.$y.' -composite ';

        }

        $shell .= ' /tmp/compositeToimg150dpi.png';

        exec($shell);

        echo $shell;

        // $image = new \Imagick('/tmp/compositeToimg.tiff');

        // $image->setImageResolution(300,300);

        // // $image->resampleImage(300,300,\Imagick::FILTER_UNDEFINED,1);

        // $image->writeImage('/tmp/out1.tiff');

        echo microtimeFloat()-$beginTime;

    }

生成

格式:  PNG,tiff(两种格式一样)

Dpi:   150,300

WH:  6000*23226px,

Size: 150DPI---1G,300DPI---1G

Time:26S(150dpi和300dpi耗时差不多)

Cpu:150%(convert占满一个逻辑cpu)

test环境下   

一个covert 157%

两个covert 300%

三个379%

4个448%(耗时分别是57s,60s,61s,46s)

沙盒206环境,cpu基本未工作情况下,同时开4个covert进程情况如下(逻辑cpu总个数72个),占用cpu 2700%

总耗时系统并行执行时间12s

real    0m12.827s

user    1m34.951s

sys     0m3.846s

  1. wkhtmltoimage 

    public function getHtmlImage(){

        set_time_limit(0);

        //time=37582.413818359 ,分辨率:6000x23226,size=532M

        // real    0m15.409s

        // user    0m13.602s

        // sys     0m1.598s

        $beginTime = microtimeFloat();

        $html = '<div style="text-align:center;">';

        for($i=1;$i<=64;$i++){

            if($i%4==1){

                $html .= '<div style="Margin:10px">';

            }

            $html .= '<img src="/tmp/N690071-4XZJZY-1-HCMB008-StandardSize-300DPI-NO1-Style_H-1-printArea-12537975.png" width="1453" height="1441">';

            if($i%4==0){

                $html .= "</div>";

            }

        }

        $html .= "</div>";

        // echo $html;die;

        $name = '/tmp/srouce'.time().'.html';

        file_put_contents($name,$html);

        $shell = '/usr/sbin/wkhtmltoimage --disable-smart-width --width 6000 '.$name.' /tmp/htmltoimage1.png';

        echo $shell;

        exec($shell,$rs);

        $image = new \Imagick('/tmp/htmltoimage1.png');

        $image->setImageResolution(150,150);

        $image->resampleImage(150,150,\Imagick::FILTER_UNDEFINED,1);

        $image->writeImage('/tmp/htmltoimagedpi.png');

        echo  microtimeFloat()-$beginTime;die;

    }

格式:  png

Dpi:   150

WH:  6000*23226px,

Size: 150DPI---1G,

Time:107s

Cpu:97%(wkhtmltoimage占满一个逻辑cpu)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值