承接 assisted-mindfulness/browsershot 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

assisted-mindfulness/browsershot

Composer 安装命令:

composer require assisted-mindfulness/browsershot

包简介

Convert a webpage to an image or pdf using headless Chrome

README 文档

README

Tests

The package can convert a webpage to an image or PDF. The conversion is done behind the screens by Google Chrome. This package has been tested on MacOS and Ubuntu. If you use another OS your mileage may vary. Chrome should be installed on your system.

On a Forge provisioned Ubuntu server you can install the latest stable version of Chrome like this:

sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get -f install
sudo apt-get install google-chrome-stable

Also, if necessary, you need to install additional resources, such as fonts for displaying emoji:

sudo apt-get install fonts-noto-color-emoji

Installation

This package can be installed through Composer.

composer require assisted-mindfulness/browsershot

Usage

In all examples it is assumed that you imported this namespace at the top of your file

use AssistedMindfulness\Browsershot\Browsershot;

Here's the easiest way to create an image of a webpage:

Browsershot::url('https://example.com')->save($pathToImage);

Browsershot will make an educated guess where Google Chrome is located. If Chrome can not be found on your system you can manually set its location:

Browsershot::url('https://example.com')
   ->setChromePath($pathToChrome)
   ->save($pathToImage);

By default the screenshot will be a png and it's size will match the resolution you use for your desktop. Want another size of screenshot? No problem!

Browsershot::url('https://example.com')
    ->windowSize(640, 480)
    ->save($pathToImage);

You can also capture the webpage at higher pixel densities by passing a device scale factor value of 2 or 3. This mimics how the webpage would be displayed on a retina/xhdpi display.

Browsershot::url('https://example.com')
    ->deviceScaleFactor(2)
    ->save($pathToImage);

If, for some reason, you want to set the user agent Google Chrome should use when taking the screenshot you can do so:

Browsershot::url('https://example.com')
    ->userAgent('My Special Snowflake Browser 1.0')
    ->save($pathToImage);

The default timeout of Browsershot is set to 60 seconds. Of course, you can modify this timeout:

Browsershot::url('https://example.com')
    ->timeout(120)
    ->save($pathToImage);

Browsershot will save a pdf if the path passed to the save method has a pdf extension.

// a pdf will be saved
Browsershot::url('https://example.com')->save('example.pdf');

Alternatively you can explicitly use the savePdf method:

Browsershot::url('https://example.com')->savePdf('example.pdf');

Browsershot also can get the body of an html page after JavaScript has been executed:

Browsershot::url('https://example.com')
    ->bodyHtml(); // returns the html of the body

You can also use an arbitrary html input, simply replace the url method with html:

Browsershot::html('<h1>Hello world!!</h1>')
    ->save('example.pdf');

License

The MIT License (MIT). Please see License File for more information.

This is a fork of the spatie/browsershot project which does not require Node and Puppeteer to be installed on your web server.

assisted-mindfulness/browsershot 适用场景与选型建议

assisted-mindfulness/browsershot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 539.21k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2022 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「browser」 「pdf」 「convert」 「headless」 「webpage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 assisted-mindfulness/browsershot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 assisted-mindfulness/browsershot 我们能提供哪些服务?
定制开发 / 二次开发

基于 assisted-mindfulness/browsershot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 539.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-12