方案
php+PhantomJS
1 2 3 4 5 6 7 8 9 |
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2 cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/ #run cd phantomjs-2.1.1-linux-x86_64/examples phantomjs rasterize.js http://www.colorcun.com/seller ttt.png |
#中文处理
“微软雅黑”字体库
1 2 3 4 5 6 7 |
http://ftp-idc.pconline.com.cn/59889cb7eaf618e4904763837f8a5f4d/pub/download/201010/yaheiFont_CHS.zip mkdir /usr/share/fonts/win cp msyh.ttf msyhbd.ttf /usr/share/fonts/win/ cd /usr/share/fonts/win mkfontscale mkfontdir fc-cache |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php if (isset($_GET['url'])) { set_time_limit(0); $url = trim($_GET['url']); $filePath = md5($url).'.png'; if (is_file($filePath)) { exit($filePath); } //如果不加这句就会报错“Fatal: [Errno 2] No such file or directory; did you install phantomjs?”,详情参考http://mengkang.net/87.html putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs"); $command = "phantomjs phantomjs.js {$url} {$filePath}"; @exec($command); exit($filePath); } ?> |
方案
结论未跑通
方案
What we need to convert html to image
- HTML2PDF utility (Free)
- imagick php extension (Pre-Installed on most server)
安装 html2pdf
1 2 3 4 5 6 7 |
wget https://github.com/spipu/html2pdf/archive/v4.5.1.tar.gz tar -zxvf v4.5.1.tar.gz yum install composer ##切换成国内镜像 composer config -g repo.packagist composer https://packagist.phpcomposer.com cd /alidata/server/html2pdf-4.5.1 composer install |
安装 ImageMagick
ftp://ftp.imagemagick.org/pub/ImageMagick/
1 2 3 4 5 6 |
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-7.0.2-10.tar.gz tar -zxvf ImageMagick-7.0.2-10.tar.gz cd ImageMagick-7.0.2-10 ./configure --prefix=/usr/local/imagemagick make make install |
安装 php imagick
安装imagick扩展时需要PHP >= 5.1.3,ImageMagick >= 6.2.4
从http://pecl.php.net/package/imagick找到imagick的最新的stable版本
1 2 3 4 5 6 7 |
wget http://pecl.php.net/get/imagick-3.4.0.tgz tar -zxvf imagick-3.4.0.tgz cd imagick-3.4.0 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick make && make install ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226 |