阅读背景:

AWS S3 PNG图像无法与FPDF一起使用

来源:互联网 

On my PHP FPDF script

在我的PHP FPDF脚本上

<?php
...
$mypdf->Image("https://s3-ap-southeast-1.amazonaws.com/mybucket/path/to/the/image/file.png", null, null, 150, 150);
...
?>

and it causes errors. However when I try to do the same thing but with a different image not hosted on S3, it works.

它会导致错误。然而,当我尝试做同样的事情,但有一个不在S3上托管的不同图像,它的工作原理。

How is this possible that S3 does not work with FPDF?

这怎么可能S3不能与FPDF一起使用?

1 个解决方案

#1


1  

I was having the same problem and I after some digging in the fpdf source figured out the issue was with fopen(). In order to use this method with an S3 image you need to use an S3 Stream Wrapper. This requires the AWS SDK for PHP or you could also roll your own if really wanted to.

我遇到了同样的问题,经过fpdf源码的挖掘,我发现问题出在fopen()上。要将此方法与S3映像一起使用,您需要使用S3 Stream Wrapper。这需要适用于PHP的AWS开发工具包,或者如果您真的想要,也可以自行编写。

My code looks like this

我的代码看起来像这样

$credentials = new Aws\Credentials\Credentials('KEY','SECRET');
$client = new Aws\S3\S3Client([
    'version'=>'latest',
    'region'      => 'REGION',
    'credentials' => $credentials
]);
$client->registerStreamWrapper();

// Link to file
$url = 's3://bucket/key';

// add background image
$fpdf->Image($url, 0, 0, $fpdf->GetPageWidth(), $fpdf->GetPageHeight());

分享到: