Skip to content

Commit

Permalink
Refactor code to set default extension to 'jpg'
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 8, 2023
1 parent 4ee4a40 commit 51303b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/Conversions/Actions/PerformManipulationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function execute(
}

$image = Image::useImageDriver(config('media-library.image_driver'))
->load($conversionTempFile);
->load($conversionTempFile)
->format('jpg');

$conversion->getManipulations()->apply($image);

Expand All @@ -46,7 +47,13 @@ protected function getConversionTempFileName(
): string {
$directory = pathinfo($imageFile, PATHINFO_DIRNAME);

$fileName = Str::random(32)."{$conversion->getName()}.{$media->extension}";
$extension = $media->extension;

if ($extension === '') {
$extension = 'jpg';
}

$fileName = Str::random(32)."{$conversion->getName()}.{$extension}";

return "{$directory}/{$fileName}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Conversions/ImageGenerators/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function convert(string $file, Conversion $conversion = null): string

public function requirementsAreInstalled(): bool
{
return class_exists(\Imagick::class);
return class_exists(Imagick::class);
}

public function supportedExtensions(): Collection
Expand Down
2 changes: 1 addition & 1 deletion tests/Conversions/ConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
->nonOptimized()
->getManipulations()
->toArray();
ray($manipulations);

$this->assertArrayNotHasKey('optimize', $manipulations);
});

Expand Down

0 comments on commit 51303b8

Please sign in to comment.