Skip to content

Commit

Permalink
feat: add crop parameter to asset middleware
Browse files Browse the repository at this point in the history
REHLTYEXT-89
  • Loading branch information
dvdmlln committed Sep 5, 2024
1 parent 9233f2d commit 6a9bf6c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Classes/Middleware/AssetMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Imaging\ImageManipulation\Area;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Resource\AbstractFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
Expand Down Expand Up @@ -79,11 +80,26 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$targetFileExtension === 'svg'
)
) {
$cropVariant = $queryParams['breakpoint'] ?? 'default';
$cropName = $queryParams['crop'] ?? null;
$breakpoint = $queryParams['breakpoint'] ?? null;

$cropVariants = array_filter([
implode('-', array_filter([$cropName, $breakpoint])),
$cropName,
$breakpoint,
]);

$crop = $resource->getProperty('crop') ?? '';
$cropVariantCollection = CropVariantCollection::create($crop);
$cropArea = $cropVariantCollection->getCropArea($cropVariant);

$cropArea = Area::createEmpty();

foreach ($cropVariants as $cropVariant) {
$cropArea = $cropVariantCollection->getCropArea($cropVariant);
if (!$cropArea->isEmpty()) {
break;
}
}

// Use default cropVariant if breakpoint cropVariant does not exist
if ($cropArea->isEmpty()) {
Expand Down

0 comments on commit 6a9bf6c

Please sign in to comment.