我正在使用 amazon s3 来存储我的图像。现在我有 3 个不同的文件夹 - 临时的一个到不接受的图片,一个用于接受,一个用于带水印的一个。
当照片被接受时,它会被复制到接受和加水印的文件夹中,并从临时文件夹中删除。
问题出在带水印的文件夹上,因为我需要添加水印。在进行中的工作中,我模拟了添加水印的方法,如下所示:
protected function addWatermark($product)
{
$filterName = 'watermark';
$this->imagineFilterManager->getFilter($filterName)
->apply($this->imagine->open($product->getFilePath()))
->save($path, array('format' => "png"));
}
这很好。但问题是 - 模拟正在处理上传的文件,而 FilePath 是图像的临时文件路径。
现在我需要从 amazon s3 检索图像,将其传递给imagineFilterManager 并保存回 amazon s3 位置。问题在于检索照片。
我试过这样:读取方法:
public function read($path)
{
return $this->fileSystem->read($path);
}
protected function addWatermark($product)
{
var_dump('addWatermark');
$filterName = 'watermark';
$path = $this->getShopPicturePath($product);
$file = $this->staticContentAdapter->read($path);
$file = imagecreatefromstring($file);
$this->imagineFilterManager->getFilter($filterName)
->apply($this->imagine->open($file))
->save($path, array('format' => "png"));
var_dump('filtered');exit;
}
但在此之后 $this-imagine-open() 返回
文件资源 ID #141 不存在
对我来说奇怪的是,我可以仅使用路径将图像文件保存在 s3 上:
->save($path, array('format' => "png"));
但无法仅使用路径打开文件:
->apply($this->imagine->open($file->getFilePath()))
它抛出异常
文件 watermarked/asd_asd.png 不存在。