【问题标题】:Generate TYPO3 cropVariants for images from CLI为来自 CLI 的图像生成 TYPO3 cropVariants
【发布时间】:2020-11-27 09:10:27
【问题描述】:

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

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

<f:image cropVariant="myCropVariant"/>

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

【问题讨论】:

  • TBH 除非您还集成机器学习过程以自动检测图像的相关部分,否则我不知道如何实现这一点。否则,您只能获得锚定在 (0,0) ... 的作物变体
  • 不必那么复杂;当我没有在后端向导中选择特定的裁剪区域时,TYPO3 也只是将其放置在图像的中心而不是 (0,0),这样就可以了。

标签: typo3 fal


【解决方案1】:
// 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 2016-05-01
    • 2017-06-01
    相关资源
    最近更新 更多