diff --git a/src/API/ConversionOptionsInterface.php b/src/API/ConversionOptionsInterface.php index 7f8e1a4..6af7531 100644 --- a/src/API/ConversionOptionsInterface.php +++ b/src/API/ConversionOptionsInterface.php @@ -2,20 +2,24 @@ namespace AmaTeam\Image\Projection\API; -use AmaTeam\Image\Projection\API\Conversion\FilterInterface; +use AmaTeam\Image\Projection\API\Framework\ProcessingOptionsInterface; +use AmaTeam\Image\Projection\API\Type\SourceOptionsInterface; +use AmaTeam\Image\Projection\API\Type\TargetOptionsInterface; interface ConversionOptionsInterface { - const INTERPOLATION_NONE = 'none'; - const INTERPOLATION_BILINEAR = 'bilinear'; + /** + * @return SourceOptionsInterface + */ + public function getSource(); /** - * @return string + * @return TargetOptionsInterface */ - public function getInterpolationMode(); + public function getTarget(); /** - * @return FilterInterface[] + * @return ProcessingOptionsInterface */ - public function getFilters(); + public function getProcessing(); } diff --git a/src/API/Framework/ProcessingOptionsInterface.php b/src/API/Framework/ProcessingOptionsInterface.php new file mode 100644 index 0000000..9c2e239 --- /dev/null +++ b/src/API/Framework/ProcessingOptionsInterface.php @@ -0,0 +1,19 @@ +source; + } + + /** + * @param SourceOptionsInterface $source + * @return $this + */ + public function setSource($source) + { + $this->source = $source; + return $this; + } /** - * @return string + * @return TargetOptionsInterface */ - public function getInterpolationMode() + public function getTarget() { - return $this->interpolationMode; + return $this->target; } /** - * @param string $interpolationMode + * @param TargetOptionsInterface $target * @return $this */ - public function setInterpolationMode($interpolationMode) + public function setTarget($target) { - $this->interpolationMode = $interpolationMode; + $this->target = $target; return $this; } /** - * @return FilterInterface[] + * @return ProcessingOptionsInterface */ - public function getFilters() + public function getProcessing() { - return $this->filters; + return $this->processing; } /** - * @param FilterInterface[] $filters + * @param ProcessingOptionsInterface $processing * @return $this */ - public function setFilters($filters) + public function setProcessing($processing) { - $this->filters = $filters; + $this->processing = $processing; return $this; } } diff --git a/src/Framework/Converter.php b/src/Framework/Converter.php index 1dc6651..f6822a2 100644 --- a/src/Framework/Converter.php +++ b/src/Framework/Converter.php @@ -47,7 +47,7 @@ public function createConversions( $context = ['source' => $source, 'targets' => $targets]; $message = 'Converting {source} to targets {targets}'; $this->logger->debug($message, $context); - $reader = $this->getReader($source); + $reader = $this->getReader($source, $options); $pipelines = []; foreach ($targets as $target) { $pipelines[] = $this @@ -71,21 +71,25 @@ public function createConversion( ) { $context = ['source' => $source, 'target' => $target]; $message = 'Converting {source} to target {target}'; + $options = $options ?: new ConversionOptions(); $this->logger->debug($message, $context); - $reader = $this->getReader($source); + $reader = $this->getReader($source, $options); return $this->instantiateConversion($reader, $target, $options); } /** * @param SpecificationInterface $source + * @param ConversionOptionsInterface $options * @return ReaderInterface */ - private function getReader(SpecificationInterface $source) - { + private function getReader( + SpecificationInterface $source, + ConversionOptionsInterface $options = null + ) { return $this ->registry ->getHandler($source->getType()) - ->createReader($source); + ->createReader($source, $options); } /** diff --git a/src/Framework/ProcessingOptions.php b/src/Framework/ProcessingOptions.php new file mode 100644 index 0000000..1377d5e --- /dev/null +++ b/src/Framework/ProcessingOptions.php @@ -0,0 +1,55 @@ +processors; + } + + /** + * @param ProcessorInterface[] $processors + * @return $this + */ + public function setProcessors($processors) + { + $this->processors = $processors; + return $this; + } + + /** + * @return ListenerInterface[] + */ + public function getListeners() + { + return $this->listeners; + } + + /** + * @param ListenerInterface[] $listeners + * @return $this + */ + public function setListeners($listeners) + { + $this->listeners = $listeners; + return $this; + } +} diff --git a/src/Type/AbstractHandler.php b/src/Type/AbstractHandler.php index 2f13ae3..d4ab03d 100644 --- a/src/Type/AbstractHandler.php +++ b/src/Type/AbstractHandler.php @@ -2,10 +2,10 @@ namespace AmaTeam\Image\Projection\Type; -use AmaTeam\Image\Projection\API\ConversionOptionsInterface; use AmaTeam\Image\Projection\API\SpecificationInterface; +use AmaTeam\Image\Projection\API\Type\SourceOptionsInterface; use AmaTeam\Image\Projection\API\Tile\TileInterface; -use AmaTeam\Image\Projection\API\Type\ReaderOptionsInterface; +use AmaTeam\Image\Projection\API\Type\TargetOptionsInterface; use AmaTeam\Image\Projection\API\Type\ValidatingMappingInterface; use AmaTeam\Image\Projection\Constants; use AmaTeam\Image\Projection\Framework\Validation\ValidationException; @@ -60,9 +60,9 @@ public function __construct( */ public function createReader( SpecificationInterface $specification, - ReaderOptionsInterface $options = null + SourceOptionsInterface $options = null ) { - $options = $options ?: new ReaderOptions(); + $options = $options ?: new SourceOptions(); $loader = new Loader($this->imageManager, $this->filesystem); $pattern = $specification->getPattern(); $tiles = $loader->load($pattern); @@ -91,12 +91,13 @@ public function createReader( public function createGenerator( ReaderInterface $source, SpecificationInterface $target, - ConversionOptionsInterface $options = null + TargetOptionsInterface $options = null ) { if (!$target->getSize()) { $message = 'Provided specification doesn\'t contain it\'s size'; throw new BadMethodCallException($message); } + $options = $options ?: new TargetOptions(); $mapping = $this->getMapping(); $context = ['target' => $target,]; $this->logger->debug('Creating tile generator for {target}', $context); @@ -111,7 +112,7 @@ public function createGenerator( * @param SpecificationInterface $specification * @param MappingInterface $mapping * @param TileInterface[][][] $tiles - * @param ReaderOptionsInterface $options + * @param SourceOptionsInterface $options * * @return ReaderInterface */ @@ -119,7 +120,7 @@ protected function instantiateReader( SpecificationInterface $specification, MappingInterface $mapping, array $tiles, - ReaderOptionsInterface $options + SourceOptionsInterface $options ) { $mode = $options->getInterpolationMode(); if ($mode === Constants::INTERPOLATION_BILINEAR) { diff --git a/src/Type/Registry.php b/src/Type/Registry.php index 858a0dc..29c864f 100644 --- a/src/Type/Registry.php +++ b/src/Type/Registry.php @@ -2,6 +2,7 @@ namespace AmaTeam\Image\Projection\Type; +use AmaTeam\Image\Projection\API\RegistryInterface; use AmaTeam\Image\Projection\Image\Adapter\Discovery; use AmaTeam\Image\Projection\API\Image\ImageFactoryInterface; use AmaTeam\Image\Projection\Filesystem\Factory; @@ -14,7 +15,7 @@ use Psr\Log\NullLogger; use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; -class Registry +class Registry implements RegistryInterface { /** * @var FilesystemInterface @@ -112,13 +113,13 @@ public function findType($type) } /** - * @param string $name + * @param string $type * @param HandlerInterface $handler * @return HandlerInterface */ - public function register($name, HandlerInterface $handler) + public function register($type, HandlerInterface $handler) { - $this->registry[$name] = $handler; + $this->registry[$type] = $handler; return $handler; } diff --git a/src/Type/ReaderOptions.php b/src/Type/SourceOptions.php similarity index 61% rename from src/Type/ReaderOptions.php rename to src/Type/SourceOptions.php index 8419596..a9d97c3 100644 --- a/src/Type/ReaderOptions.php +++ b/src/Type/SourceOptions.php @@ -2,12 +2,15 @@ namespace AmaTeam\Image\Projection\Type; -use AmaTeam\Image\Projection\API\Type\ReaderOptionsInterface; -use AmaTeam\Image\Projection\Constants; +use AmaTeam\Image\Projection\API\Type\SourceOptionsInterface; +use AmaTeam\Image\Projection\API\Type\Interpolation; -class ReaderOptions implements ReaderOptionsInterface +class SourceOptions implements SourceOptionsInterface { - private $interpolationMode = Constants::INTERPOLATION_BILINEAR; + /** + * @var string + */ + private $interpolationMode = Interpolation::BILINEAR; /** * @return string diff --git a/src/Type/TargetOptions.php b/src/Type/TargetOptions.php new file mode 100644 index 0000000..b149650 --- /dev/null +++ b/src/Type/TargetOptions.php @@ -0,0 +1,103 @@ +filters; + } + + /** + * @param FilterInterface[] $filters + * @return $this + */ + public function setFilters($filters) + { + $this->filters = $filters; + return $this; + } + + /** + * @return string + */ + public function getFormat() + { + return $this->format; + } + + /** + * @param string $format + * @return $this + */ + public function setFormat($format) + { + $this->format = $format; + return $this; + } + + /** + * @return float + */ + public function getQuality() + { + return $this->quality; + } + + /** + * @param float $quality + * @return $this + */ + public function setQuality($quality) + { + $this->quality = $quality; + return $this; + } + + /** + * @return float + */ + public function getCompression() + { + return $this->compression; + } + + /** + * @param float $compression + * @return $this + */ + public function setCompression($compression) + { + $this->compression = $compression; + return $this; + } +}