如何从控制器中的记录中获取图像路径,同时又要遵守后端图像编辑器中的裁剪设置?
我当前的代码(在模型中)仅给我提供了没有裁切但尺寸已调整的图像。
public function getImageUrl($imageResource)
{
return $imageResource->getOriginalResource()->getOriginalFile()->getPublicUrl();
}
public function getSmallImage($imageResource)
{
$image = $this->imageService->getImage($this->getImageUrl($imageResource), null, false);
$processingInstructions = [
'maxWidth' => 500,
'maxHeight' => 500
];
$processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
return $this->imageService->getImageUri($processedImage);
}
public function getSmallImage($imageResource)
{
$image = $this->imageService->getImage($this->getImageUrl($imageResource), null, false);
$processingInstructions = [
'maxWidth' => 500,
'maxHeight' => 500
];
$processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
return $this->imageService->getImageUri($processedImage);
}
我必须将农作物喂到$processingInstructions
吗?在哪里找到农作物?
我正在使用TYPO3 8.7。
答案 0 :(得分:0)
我在流体的图像查看助手类中找到了解决方案。
public function getSmallImage($imageResource)
{
$image = $this->imageService->getImage($this->getImageUrl($imageResource), null, false);
$cropVariantCollection = \TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection::create((string)$imageResource->getOriginalResource()->getProperty('crop'));
$cropArea = $cropVariantCollection->getCropArea('default');
$processingInstructions = [
'maxWidth' => 500,
'maxHeight' => 500,
'crop' => $cropArea->makeAbsoluteBasedOnFile($image),
];
$processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
return $this->imageService->getImageUri($processedImage);
}