如何在控制器中尊重图像编辑器的图像? TYPO3

时间:2019-08-13 09:52:25

标签: typo3 typo3-8.x

如何从控制器中的记录中获取图像路径,同时又要遵守后端图像编辑器中的裁剪设置?

我当前的代码(在模型中)仅给我提供了没有裁切但尺寸已调整的图像。

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。

1 个答案:

答案 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);
    }