Skip to content

Commit

Permalink
[BUGFIX] Respect crop of FileReference objects in getImgResource
Browse files Browse the repository at this point in the history
ContentObjectRenderer::getImgResource is used for the content objects
IMAGE, IMG_RESOURCE, as well as GIFBUILDER to process images.

When it is passed a FileReference object, it should respect the crop
settings of this reference, same as when it is passed a reference UID
plus the treatIdAsReference config.

Resolves: #101810
Releases: main, 12.4, 11.5
Change-Id: I399106399ec283561c00fa5cf61d6c7fe2871e49
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80928
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
fwg authored and sbuerk committed Sep 8, 2023
1 parent 739664f commit f277d01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Expand Up @@ -4039,6 +4039,7 @@ public function mailto_makelinks($data, $conf)
public function getImgResource($file, $fileArray)
{
$importedFile = null;
$fileReference = null;
if (empty($file) && empty($fileArray)) {
return null;
}
Expand All @@ -4059,6 +4060,7 @@ public function getImgResource($file, $fileArray)
if ($file instanceof File) {
$fileObject = $file;
} elseif ($file instanceof FileReference) {
$fileReference = $file;
$fileObject = $file->getOriginalFile();
} else {
try {
Expand Down Expand Up @@ -4105,7 +4107,7 @@ public function getImgResource($file, $fileArray)
$processingConfiguration['noScale'] = $this->stdWrapValue('noScale', $fileArray ?? []);
$processingConfiguration['additionalParameters'] = $this->stdWrapValue('params', $fileArray ?? []);
$processingConfiguration['frame'] = (int)$this->stdWrapValue('frame', $fileArray ?? []);
if (isset($fileReference)) {
if ($fileReference instanceof FileReference) {
$processingConfiguration['crop'] = $this->getCropAreaFromFileReference($fileReference, $fileArray);
} else {
$processingConfiguration['crop'] = $this->getCropAreaFromFromTypoScriptSettings($fileObject, $fileArray);
Expand Down
Expand Up @@ -740,4 +740,27 @@ public function imageLinkWrapWrapsTheContentAsConfigured(string $content, array
self::assertSame($expectedParams, $jsonDecodedArray);
}
}

/**
* @test
*/
public function getImgResourceRespectsFileReferenceObjectCropData(): void
{
$this->importCSVDataSet(__DIR__ . '/DataSet/FileReferences.csv');
$fileReferenceData = [
'uid' => 1,
'uid_local' => 1,
'crop' => '{"default":{"cropArea":{"x":0,"y":0,"width":0.5,"height":0.5},"selectedRatio":"NaN","focusArea":null}}',
];
$fileReference = new FileReference($fileReferenceData);

$subject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$result = $subject->getImgResource($fileReference, []);

$expectedWidth = 512;
$expectedHeight = 341;

self::assertEquals($expectedWidth, $result[0]);
self::assertEquals($expectedHeight, $result[1]);
}
}
Expand Up @@ -8,3 +8,6 @@
"sys_file_reference",,,,,,,,,,,,,,,,,,,,
,"uid","pid","title","uid_local","uid_foreign","sys_language_uid","l10n_parent","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","deleted","tablenames","fieldname","sorting_foreign","table_local","description","alternative","link","l10n_diffsource"
,1,1,"T3BOARD",1,297,0,0,0,0,0,0,0,"tt_content","image",2,"sys_file",,,,
"sys_file_metadata",,,,,,,,,,,,,,,,,,,,,
,uid,pid,sys_language_uid,l10n_parent,l10n_state,t3_origuid,l10n_diffsource,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_stage,file,title,width,height,description,alternative,categories
,1,0,0,0,,0,,0,0,0,0,1,,1024,683,,,0,

0 comments on commit f277d01

Please sign in to comment.