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
67 changes: 67 additions & 0 deletions app/Support/Converters/Image/JpgToPngConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Support\Converters\Image;

use App\Support\Converters\Contracts\Converter;
use App\Support\Converters\OptionsValidator;

final class JpgToPngConverter implements Converter
{
public function __construct(
private readonly OptionsValidator $optionsValidator,
) {}

public function key(): string
{
return 'jpg:png';
}

public function sourceFormat(): string
{
return 'jpg';
}

public function targetFormat(): string
{
return 'png';
}

public function label(): string
{
return 'PNG';
}

public function description(): string
{
return 'Convert photo to lossless PNG image';
}

public function optionsSchema(): array
{
return [
[
'key' => 'resize',
'type' => 'select',
'label' => 'Resize',
'default' => 'original',
'options' => [
['value' => 'original', 'label' => 'Original'],
['value' => '1920', 'label' => '1920 px'],
['value' => '1280', 'label' => '1280 px'],
['value' => 'custom', 'label' => 'Custom'],
],
],
[
'key' => 'remove_metadata',
'type' => 'toggle',
'label' => 'Remove metadata',
'default' => true,
],
];
}

public function validateOptions(array $options): array
{
return $this->optionsValidator->validate($this->optionsSchema(), $options);
}
}
27 changes: 27 additions & 0 deletions tests/Unit/Converters/Image/JpgToPngConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use App\Support\Converters\Image\JpgToPngConverter;
use App\Support\Converters\OptionsValidator;

it('defines jpg to png converter capability', function () {
$converter = app(JpgToPngConverter::class);

expect($converter->key())->toBe('jpg:png');
expect($converter->sourceFormat())->toBe('jpg');
expect($converter->targetFormat())->toBe('png');
expect($converter->label())->toBe('PNG');
expect($converter->description())->not->toBeEmpty();
});

it('provides valid default options for jpg to png', function () {
$converter = app(JpgToPngConverter::class);

$options = app(OptionsValidator::class)->validate(
$converter->optionsSchema(),
[]
);

expect($options)->toHaveKey('resize');
expect($options)->toHaveKey('remove_metadata');
expect($options)->not->toHaveKey('transparency');
});