Skip to content
Merged
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ S3_PATH_STYLE_ENDPOINT=1

# Compression
IMAGE_COMPRESSION=75
AVIF_COMPRESSION=85

# HTTP fetch
FETCH_TIMEOUT=10
Expand Down
3 changes: 3 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ params:
s3_access_key: ${ssm:/cdn-php/prod/s3-access-key}
s3_secret_key: ${ssm:/cdn-php/prod/s3-secret-key}
image_compression: ${ssm:/cdn-php/prod/image-compression}
avif_compression: ${ssm:/cdn-php/prod/avif-compression}
force_token: ${ssm:/cdn-php/prod/force-token}

dev:
Expand All @@ -29,6 +30,7 @@ params:
s3_access_key: ${ssm:/cdn-php/dev/s3-access-key}
s3_secret_key: ${ssm:/cdn-php/dev/s3-secret-key}
image_compression: ${ssm:/cdn-php/dev/image-compression}
avif_compression: ${ssm:/cdn-php/dev/avif-compression}
force_token: ${ssm:/cdn-php/dev/force-token}

provider:
Expand Down Expand Up @@ -80,6 +82,7 @@ functions:
LOG_STREAM: php://stderr
LOG_LEVEL: ${param:log_level}
IMAGE_COMPRESSION: ${param:image_compression}
AVIF_COMPRESSION: ${param:avif_compression}

package:
patterns:
Expand Down
7 changes: 7 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class Container
private const string KEY_STORAGE_PATH = 'storage_path';
private const string KEY_CACHE_TTL = 'cache_ttl';
private const string KEY_IMAGE_COMPRESSION = 'image_compression';
private const string KEY_AVIF_COMPRESSION = 'avif_compression';
private const string KEY_FETCH_TIMEOUT = 'fetch_timeout';
private const string KEY_FETCH_MAX_SIZE = 'fetch_max_size';
private const string KEY_FETCH_ALLOW_REDIRECTS = 'fetch_allow_redirects';
Expand Down Expand Up @@ -235,13 +236,19 @@ private function bootCache(): void
private function bootImageProcessor(): void
{
$this->add(self::KEY_IMAGE_COMPRESSION, (int) $this->getEnv('IMAGE_COMPRESSION'));
$avifCompressionEnv = $this->getEnv('AVIF_COMPRESSION');
$this->add(
self::KEY_AVIF_COMPRESSION,
null !== $avifCompressionEnv ? (int) $avifCompressionEnv : $this->get(self::KEY_IMAGE_COMPRESSION),
);
$this->add(
ImageProcessor::class,
new ImageProcessor(
$this->get(FilesystemAdapter::class),
$this->get(UrlFilesystemAdapter::class),
$this->get(LoggerInterface::class),
$this->get(self::KEY_IMAGE_COMPRESSION),
$this->get(self::KEY_AVIF_COMPRESSION),
),
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Processor/ImageProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(
private readonly UrlFilesystemAdapter $urlFilesystemAdapter,
private readonly LoggerInterface $logger,
private readonly int $imageCompression,
private readonly int $avifCompression,
) {
}

Expand Down Expand Up @@ -59,7 +60,8 @@ public function process(
],
);

$glideParams = [...$params->toArray(), 'q' => $this->imageCompression];
$quality = true === $outputAvif ? $this->avifCompression : $this->imageCompression;
$glideParams = [...$params->toArray(), 'q' => $quality];

if (true === $outputAvif) {
$glideParams['fm'] = 'avif';
Expand Down
Loading