Skip to content

Commit

Permalink
Switch to varidic encoder options
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Mar 26, 2024
1 parent 4b2891f commit 0dc258c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 14 additions & 14 deletions src/Encoders/FileExtensionEncoder.php
Expand Up @@ -11,17 +11,17 @@

class FileExtensionEncoder extends AutoEncoder
{
protected array $options = [];

/**
* Create new encoder instance to encode to format of given file extension
*
* @param null|string $extension Target file extension for example "png"
* @param int $quality
* @return void
*/
public function __construct(
public ?string $extension = null,
public int $quality = self::DEFAULT_QUALITY
) {
public function __construct(public ?string $extension = null, mixed ...$options)
{
$this->options = $options;
}

/**
Expand Down Expand Up @@ -52,15 +52,15 @@ protected function encoderByFileExtension(?string $extension): EncoderInterface
}

return match (strtolower($extension)) {
'webp' => new WebpEncoder(quality: $this->quality),
'avif' => new AvifEncoder(quality: $this->quality),
'jpeg', 'jpg' => new JpegEncoder(quality: $this->quality),
'bmp' => new BmpEncoder(),
'gif' => new GifEncoder(),
'png' => new PngEncoder(),
'tiff', 'tif' => new TiffEncoder(quality: $this->quality),
'jp2', 'j2k', 'jpf', 'jpm', 'jpg2', 'j2c', 'jpc', 'jpx' => new Jpeg2000Encoder(quality: $this->quality),
'heic', 'heif' => new HeicEncoder(quality: $this->quality),
'webp' => new WebpEncoder(...$this->options),
'avif' => new AvifEncoder(...$this->options),
'jpeg', 'jpg' => new JpegEncoder(...$this->options),
'bmp' => new BmpEncoder(...$this->options),
'gif' => new GifEncoder(...$this->options),
'png' => new PngEncoder(...$this->options),
'tiff', 'tif' => new TiffEncoder(...$this->options),
'jp2', 'j2k', 'jpf', 'jpm', 'jpg2', 'j2c', 'jpc', 'jpx' => new Jpeg2000Encoder(...$this->options),
'heic', 'heif' => new HeicEncoder(...$this->options),
default => throw new EncoderException('No encoder found for file extension (' . $extension . ').'),
};
}
Expand Down
28 changes: 14 additions & 14 deletions src/Encoders/MediaTypeEncoder.php
Expand Up @@ -12,17 +12,17 @@

class MediaTypeEncoder extends AbstractEncoder
{
protected array $options = [];

/**
* Create new encoder instance
*
* @param null|string $mediaType Target media type for example "image/jpeg"
* @param int $quality
* @return void
*/
public function __construct(
public ?string $mediaType = null,
public int $quality = self::DEFAULT_QUALITY
) {
public function __construct(public ?string $mediaType = null, mixed ...$options)
{
$this->options = $options;
}

/**
Expand Down Expand Up @@ -50,29 +50,29 @@ protected function encoderByMediaType(string $mediaType): EncoderInterface
{
return match (strtolower($mediaType)) {
'image/webp',
'image/x-webp' => new WebpEncoder(quality: $this->quality),
'image/x-webp' => new WebpEncoder(...$this->options),
'image/avif',
'image/x-avif' => new AvifEncoder(quality: $this->quality),
'image/x-avif' => new AvifEncoder(...$this->options),
'image/jpeg',
'image/jpg',
'image/pjpeg' => new JpegEncoder(quality: $this->quality),
'image/pjpeg' => new JpegEncoder(...$this->options),
'image/bmp',
'image/ms-bmp',
'image/x-bitmap',
'image/x-bmp',
'image/x-ms-bmp',
'image/x-win-bitmap',
'image/x-windows-bmp',
'image/x-xbitmap' => new BmpEncoder(),
'image/gif' => new GifEncoder(),
'image/x-xbitmap' => new BmpEncoder(...$this->options),
'image/gif' => new GifEncoder(...$this->options),
'image/png',
'image/x-png' => new PngEncoder(),
'image/tiff' => new TiffEncoder(quality: $this->quality),
'image/x-png' => new PngEncoder(...$this->options),
'image/tiff' => new TiffEncoder(...$this->options),
'image/jp2',
'image/jpx',
'image/jpm' => new Jpeg2000Encoder(quality: $this->quality),
'image/jpm' => new Jpeg2000Encoder(...$this->options),
'image/heic',
'image/heif', => new HeicEncoder(quality: $this->quality),
'image/heif', => new HeicEncoder(...$this->options),
default => throw new EncoderException('No encoder found for media type (' . $mediaType . ').'),
};
}
Expand Down

0 comments on commit 0dc258c

Please sign in to comment.