Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neos Media Imagor Support #5316

Draft
wants to merge 2 commits into
base: 8.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface ImageAdjustmentInterface extends AdjustmentInterface
*
* @param ImageInterface $image
* @return ImageInterface
* !!! only called when using Imagine, not called when using Imagor (or other image proxies)
*/
public function applyToImage(ImageInterface $image);

Expand All @@ -34,6 +35,7 @@ public function applyToImage(ImageInterface $image);
*
* @param ImageVariant $imageVariant
* @return void
* !!! only called when using Imagine, not called when using Imagor (or other image proxies)
*/
public function setImageVariant(ImageVariant $imageVariant);

Expand All @@ -42,6 +44,7 @@ public function setImageVariant(ImageVariant $imageVariant);
*
* @param ImageInterface $image
* @return boolean
* !!! only called when using Imagine, not called when using Imagor (or other image proxies)
*/
public function canBeApplied(ImageInterface $image);
}
8 changes: 4 additions & 4 deletions Neos.Media/Classes/Domain/Model/DimensionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
trait DimensionsTrait
{
/**
* @var integer
* @var integer|null
* @ORM\Column(nullable=true)
*/
protected $width = 0;

/**
* @var integer
* @var integer|null
* @ORM\Column(nullable=true)
*/
protected $height = 0;

/**
* Width of the image in pixels
*
* @return integer
* @return integer|null
*/
public function getWidth()
{
Expand All @@ -43,7 +43,7 @@ public function getWidth()
/**
* Height of the image in pixels
*
* @return integer
* @return integer|null
*/
public function getHeight()
{
Expand Down
4 changes: 2 additions & 2 deletions Neos.Media/Classes/Domain/Model/ImageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ interface ImageInterface extends ResourceBasedInterface
/**
* Width of the image in pixels
*
* @return integer
* @return integer|null
*/
public function getWidth();

/**
* Height of the image in pixels
*
* @return integer
* @return integer|null
*/
public function getHeight();

Expand Down
26 changes: 20 additions & 6 deletions Neos.Media/Classes/Domain/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
use Neos\Media\Domain\Model\Thumbnail;
use Neos\Media\Domain\Model\ThumbnailConfiguration;
use Neos\Media\Domain\Repository\AssetRepository;
use Neos\Media\Domain\Service\Imagor\ImagorService;
use Neos\Media\Domain\Strategy\AssetUsageStrategyInterface;
use Neos\Media\Exception\AssetServiceException;
use Neos\Media\Exception\AssetVariantGeneratorException;
use Neos\Media\Exception\ThumbnailServiceException;
use Neos\RedirectHandler\Storage\RedirectStorageInterface;
use Neos\Utility\Arrays;
use Neos\Utility\MediaTypes;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -103,12 +103,22 @@ class AssetService
*/
protected $imageService;

/**
* @Flow\Inject
*/
protected ImagorService $imagorService;

/**
* @Flow\Inject
* @var AssetVariantGenerator
*/
protected $assetVariantGenerator;

/**
* @Flow\InjectConfiguration("imagor.enabled")
*/
protected bool $isImagorEnabled = false;

/**
* Returns the repository for an asset
*
Expand All @@ -131,17 +141,21 @@ public function getRepository(AssetInterface $asset): RepositoryInterface
* Calculates the dimensions of the thumbnail to be generated and returns the thumbnail URI.
* In case of Images this is a thumbnail of the image, in case of other assets an icon representation.
*
* @param AssetInterface $asset
* @param ThumbnailConfiguration $configuration
* @param ActionRequest $request Request argument must be provided for asynchronous thumbnails
* @param AssetInterface $asset
* @param ThumbnailConfiguration $configuration
* @param ActionRequest|null $request Request argument must be provided for asynchronous thumbnails
* @return array|null Array with keys "width", "height" and "src" if the thumbnail generation work or null
* @throws AssetServiceException
* @throws ThumbnailServiceException
* @throws MissingActionNameException
* @throws HttpException
* @throws MissingActionNameException
* @throws ThumbnailServiceException
*/
public function getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null): ?array
{
if($asset instanceof ImageInterface && $this->isImagorEnabled) {
return $this->imagorService->getThumbnailUriAndSize($asset, $configuration);
}

$thumbnailImage = $this->thumbnailService->getThumbnail($asset, $configuration);
if (!$thumbnailImage instanceof ImageInterface) {
return null;
Expand Down
8 changes: 8 additions & 0 deletions Neos.Media/Classes/Domain/Service/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ protected function applyAdjustments(ImageInterface $image, array $adjustments, &
if (!$adjustment instanceof ImageAdjustmentInterface) {
throw new ImageServiceException(sprintf('Could not apply the %s adjustment to image because it does not implement the ImageAdjustmentInterface.', get_class($adjustment)), 1381400362);
}

// TODO this is called when running ./flow site:import!!
// $imagineAdjustmentApplier = self::findImagineAdjustmentApplier($adjustment);

if ($adjustment->canBeApplied($image)) {
$image = $adjustment->applyToImage($image);
$adjustmentsApplied = true;
Expand All @@ -303,6 +307,10 @@ protected function applyAdjustments(ImageInterface $image, array $adjustments, &
return $image;
}

private static function findImagineAdjustmentApplier(ImageAdjustmentInterface $adjustment): ImageAdjustmentInterface
{
}

/**
* Detects whether the given GIF image data contains more than one frame
*
Expand Down
Loading
Loading