laravel - 在 Laravel 中添加图像 PHPWord
问题描述
所以我想在 Laravel 的 PHPWord 中为我的文档添加一个标题图像。所以这是我的代码
public function generateDocx()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$headerLogo = 'http://127.0.0.1:8000/img/logoAnevBulanan.png';
$section->addImage($headerLogo);
// Bunch of line to download the docx
}
而且我得到了超过 60 秒的最大执行时间,当我尝试文档中的其他方法时,我仍然遇到同样的错误。我尝试使用asset()
来自 laravel 的助手,但仍然没有工作
解决方案
尝试使用本地路径而不是 URL 获取图像
$source = file_get_contents('/path/to/my/images/earth.jpg');
$textrun->addImage($source);
参考文档:https ://phpword.readthedocs.io/en/latest/elements.html#images
推荐阅读
- css - 图片有时仅在 Chrome 移动版中尺寸错误
- javascript - 数组推送函数结果
- php - PhpPresentation imagecreatefromstring():数据不是可识别的格式 - PHP7.2
- c# - 使用 SQL_VARIANT 的实体框架
- python - 在python中运行脚本程序
- c# - c#如何将泛型类型参数转换并传递给内部函数?
- javascript - 防止机器人提交到外部服务器
- r - R Markdown 中未定义 Tex Proof 环境,生成的 Tex 文件中未定义 amsthm
- node.js - 在 PostCSS 中使用 Autoprefixer - 配置浏览器支持
- listview - 如何在 UWP 中更改 ListViewItem 占位符颜色?