網頁轉圖片

將一段文字轉成圖片,好比經常使用的長微博工具 這裏用 PHP 來處理。php

text2pic

composer require dsgygb/text2pic
touch test.php
<?php
require 'vendor/autoload.php';

$transform = new Text2pic\Transform('by text2pic');
$result = $transform->generate("hello world");
print_r($result);
#中文字體路徑 /c/windows/fonts/sihei.ttf
$transform=new Text2pic\Transform($by,$uploadsPath,$uploadsUrl,$fontPath);

clipboard.png

wkhtmltopdf

地址 下載後有 2 個工具 wkhtmltoimage 和 wkhtmltopdf 分別是將網頁轉圖片和pdf 的,具體使用參考html

#生成圖片 https://gist.github.com/vibbow/5702882
/user/bin/wkhtmltoimage http://www.baidu.com/ baidu.jpg
#php 調用 使用絕對路徑
$r=shell_exec("/user/bin/wkhtmltoimage http://www.baidu.com/ baidu.jpg");
$r=shell_exec("/user/bin/wkhtmltoimage -q {$filename}.html {$filename}.jpg");

phpwkhtmltopdf

# 一個 PHP 庫 https://github.com/mikehaertl/phpwkhtmltopdf  
composer require mikehaertl/phpwkhtmltopdf
require './vendor/autoload.php';
use mikehaertl\wkhtmlto\Image;

// You can pass a filename, a HTML string, an URL or an options array to the constructor
$image = new Image('/path/to/page.html');
$image->saveAs('/path/to/page.png');//保存

// ... or send to client for inline display
$image->send();//瀏覽器顯示

// ... or send to client as file download
$image->send('page.png');//瀏覽器顯示並下載

#另一個庫 https://github.com/knplabs/snappy
use Knp\Snappy\Pdf as newpdf; 
$snappy = new newpdf('wkhtmltopdf');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
// echo $snappy->getOutput('http://www.github.com');
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', 'bill-123.pdf');

more

小人舉牌圖片生成 https://github.com/jokin1999/HoldUpSign
https://stackoverflow.com/questions/5663814/how-do-i-get-wkhtmltopdf-to-execute-via-php 
http://www.jianshu.com/p/4d65857ffe5e
http://yuncode.net/code/c_51dd01a4d547f26
https://github.com/niklasvh/html2canvas 
網頁保存爲圖片及高清截圖的優化https://segmentfault.com/a/1190000011425316
相關文章
相關標籤/搜索