0

有没有办法为现有的图像关系触发cropVariants的生成或更新?

我的用例:我想确保图像始终遵循特定的纵横比。因此,我为图像定义了一个名为“myCropVariant”的cropVariant,例如在页面和一些自定义表格中。这基本上工作正常,我在“创建图像关系”对话框中看到一个新向导,我可以在其中选择cropArea,即使我不单击该向导,cropVariant 图像以及cropVariant 数据库记录也会尽快创建当我保存父记录时,使用图像的中心作为裁剪区域。前端输出也可以正常使用

<f:image cropVariant="myCropVariant"/>

问题是:我将大量内容从另一个网站导入数据库(使用自定义迁移 CLI 命令)。这也包括图像;我已经创建了相应的sys_file记录和参考。图像在前端渲染得很好,但没有使用cropVariant。那是因为它在数据库中不存在,因为没有人点击后端中导入的内容。现在从 TYPO3 外部通过迁移脚本创建它们在理论上是可能的,但会非常讨厌(因为需要知道图像尺寸等等),所以我通过 CLI 或其他东西通过 TYPO3 寻找最佳实践相似的。

4

1 回答 1

0
// get crop variant conf directly from TCA
$cropVariants = $GLOBALS['TCA']['tx_myext_domain_model_example']['columns']['attachments']['config']['overrideChildTca']['types'][2]['columnsOverrides']['crop']['config']['cropVariants'];

// extend for default cropArea configuration
foreach ($cropVariants as &$variant) {
    $variant['cropArea'] = ['x' => 0.0, 'y' => 0.0, 'width' => 1.0, 'height' => 1.0];
}

// init variants
$cropVariantCollection = CropVariantCollection::create('', $cropVariants);

// apply configuration to TYPO3\CMS\Core\Resource\File
$processedCollection = $cropVariantCollection->applyRatioRestrictionToSelectedCropArea($file);

// get json string from variants ({"desktop":{"cropArea":{"x":0,"y":0.125,"width":1,"height":0.75},"selectedRatio":"16:9","focusArea":null}})
$cropValue = (string)$processedCollection;

// save e.g. via dataHandler to sys_file_reference
于 2021-12-02T21:37:02.510 回答