来自 Azure Blob 的 Imagick

Imagick from Azure Blob

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

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

下面是我的代码片段(这只是测试代码,不是生产代码):

// 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;

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

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