我从表sys_file_reference中得到了以下裁剪值。
{"default":{"cropArea":{"height":0.7157894736842105,"width":1,"x":0,"y":0},"selectedRatio":"1:1","focusArea":null}}如何使用这些值来创建裁剪后的图像(如果您想知道,我将在一个调度程序任务中使用它)?我猜GraphicalFunctions->imageMagickConvert()做了我想要的事情,但是我似乎找不出哪个参数在哪里。
发布于 2019-11-26 23:00:12
最好使用"ImageService“。
有关如何使用它的示例可以在图像采集器中看到,例如uri.image ViewHelper:\TYPO3\CMS\Fluid\ViewHelpers\Uri\ImageViewHelper
简化后的示例如下所示:
/** @var \TYPO3\CMS\Core\Resource\FileReference $fileOrFileReference */
$fileOrFileReference = /* needs to be a File or FileReference */;
$cropString = '{...}';
// could also be from FileReference directly
//$cropString = $fileOrFileReference->getProperty('crop');
$cropVariantCollection = CropVariantCollection::create($cropString);
$cropArea = $cropVariantCollection->getCropArea('default'); // cropVariant
$processingInstructions = [
'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileOrFileReference)
];
$imageService = $this->objectManager->get(\TYPO3\CMS\Extbase\Service\ImageService::class);
$processedFile = $imageService->applyProcessingInstructions(
$fileOrFileReference,
$processingInstructions
);$cropString是您的原始json编码裁剪配置,而$fileOrFileReference是一个文件或FileReference (核心,而不是extbase)对象,它引用要对其应用裁剪的文件。
注意:如果您有一个来自sys_file_reference表的裁剪字符串,那么使用ResourceFactory直接获取FileReference对象可能会更好:
$resourceFactory = $this->objectManager->get(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
$fileReference = $resourceFactory->getFileReferenceObject($uid);然后执行上面的步骤。
编辑:如果您不在如上所示的objectManager可用的上下文中(例如,在extbase控制器中),您可以使用GeneralUtility获取ObjectManager:
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);https://stackoverflow.com/questions/59052481
复制相似问题