【问题标题】:How to an image respecting the image editor crop in controller? TYPO3如何在控制器中对图像编辑器进行裁剪? TYPO3
【发布时间】:2019-08-13 09:52:25
【问题描述】:

如何从控制器中的记录中获取与后端图像编辑器的裁剪设置相关的图像路径?

我当前的代码(在模型中)只给了我没有裁剪但调整尺寸的图像。

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。

【问题讨论】:

    标签: typo3 typo3-8.x


    【解决方案1】:

    我在流体的图像视图助手类中找到了解决方案。

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

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多