Proper treatment of cropping instructions
This commit is contained in:
@@ -27,6 +27,8 @@ namespace EP\EpProducts\Traits;
|
|||||||
* This copyright notice MUST APPEAR in all copies of the script!
|
* This copyright notice MUST APPEAR in all copies of the script!
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||||
|
use TYPO3\CMS\Core\Resource\FileReference;
|
||||||
use TYPO3\CMS\Core\Resource\FileRepository;
|
use TYPO3\CMS\Core\Resource\FileRepository;
|
||||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||||
|
|
||||||
@@ -63,20 +65,20 @@ trait ImageServiceTrait
|
|||||||
*/
|
*/
|
||||||
public function getImages($uid)
|
public function getImages($uid)
|
||||||
{
|
{
|
||||||
if (!isset(self::$cache[$uid])) {
|
if (!isset(static::$cache[$uid])) {
|
||||||
$original = $this->fileRepository->findByRelation(
|
$original = $this->fileRepository->findByRelation(
|
||||||
$this->table,
|
$this->table,
|
||||||
$this->field,
|
$this->field,
|
||||||
$uid
|
$uid
|
||||||
);
|
);
|
||||||
$resized = $this->generateResizedImages($original);
|
$resized = $this->generateResizedImages($original);
|
||||||
self::$cache[$uid] = [
|
static::$cache[$uid] = [
|
||||||
'original' => $original,
|
'original' => $original,
|
||||||
'resized' => $resized,
|
'resized' => $resized,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$cache[$uid];
|
return static::$cache[$uid];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +92,7 @@ trait ImageServiceTrait
|
|||||||
{
|
{
|
||||||
foreach ($images as $image)
|
foreach ($images as $image)
|
||||||
{
|
{
|
||||||
$intructions['crop'] = $image->getProperty('crop');
|
$instructions['crop'] = $this->getCroppingInfo($image, $instructions);
|
||||||
$processedImage = $this->imageService->applyProcessingInstructions($image, $instructions);
|
$processedImage = $this->imageService->applyProcessingInstructions($image, $instructions);
|
||||||
$resized[$version][] = [
|
$resized[$version][] = [
|
||||||
'url' => $this->imageService->getImageUri($processedImage, true),
|
'url' => $this->imageService->getImageUri($processedImage, true),
|
||||||
@@ -102,4 +104,17 @@ trait ImageServiceTrait
|
|||||||
return $resized;
|
return $resized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FileReference $image
|
||||||
|
* @param array $processingInstructions
|
||||||
|
* @return null|\TYPO3\CMS\Core\Imaging\ImageManipulation\Area
|
||||||
|
*/
|
||||||
|
protected function getCroppingInfo(FileReference $image, array $processingInstructions)
|
||||||
|
{
|
||||||
|
$cropString = $image->getProperty('crop');
|
||||||
|
$cropVariantCollection = CropVariantCollection::create((string) $cropString);
|
||||||
|
$cropVariant = $processingInstructions['cropVariant'] ?: 'default';
|
||||||
|
$cropArea = $cropVariantCollection->getCropArea($cropVariant);
|
||||||
|
return $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user