python页面转图片_网页转图片_技术分享 - SegmentFault 思否

将一段文字转成图片,比如常用的长微博工具 这里用 PHP 来处理。

text2pic

composer require dsgygb/text2pic

touch test.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);

wkhtmltopdf

地址 下载后有 2 个工具 wkhtmltoimage 和 wkhtmltopdf 分别是将网页转图片和pdf 的,具体使用参考

#生成图片 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('

Bill

You owe me money, dude.

', '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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值