【问题标题】:Imagick from Azure Blob来自 Azure Blob 的 Imagick
【发布时间】:2020-01-23 17:54:49
【问题描述】:

我有一个 PHP 站点,它当前从 Azure Blob 中提取图像,使用 file_put_contents 将其写入磁盘,然后 imagick 使用 readImageFile 从磁盘读取文件。我宁愿这个活在内存中,也不愿被写入磁盘,然后从磁盘读取。我怎样才能做到这一点?当我尝试 ReadImageBlob 时,出现以下错误:

Warning: Imagick::readimageblob() expects parameter 1 to be string, resource given in <file> <line>

下面是我的代码的 sn-p(这只是测试代码,不是生产代码):

// Get Data from Azure Storage Blob
$blob = $blobClient->getBlob($containerName, $documentPath);

// Get TIF file from Blob and convert to PDF
$im = new imagick();
$im->readImageBlob($blob->getContentStream());
$im->setImageFormat('pdf');

// Echo as PDF
header('Content-Type: application/pdf');
echo $im;

【问题讨论】:

    标签: php azure-blob-storage imagick


    【解决方案1】:

    您应该能够使用 stream_get_contents 从您拥有的流中读取字符串。示例:

    $im->readImageBlob(stream_get_contents($blob->getContentStream()));
    

    【讨论】:

    • 非常感谢! stream_get_contents() 是缺失的部分!
    • 我刚刚意识到一些事情..这样做只会显示最后一页 PDF 页面出于某种原因..所以我将不得不深入研究。如果我弄清楚了,我会报告,但如果您已经知道,请随时添加任何内容!
    • 没关系.. 这是因为我在发布之前清理了我的代码。我做了一个快速的谷歌搜索,发现了一个我几个月前问过的问题。stackoverflow.com/questions/54539023/…
    猜你喜欢
    • 2020-12-10
    • 1970-01-01
    • 2020-12-03
    • 2016-11-18
    • 2018-06-20
    • 2015-08-13
    • 1970-01-01
    • 2017-03-08
    • 2012-08-23
    相关资源
    最近更新 更多