Skip to content

Commit

Permalink
Allow Image::save() to be used without file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 29, 2023
1 parent d4c1311 commit b459723
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Intervention\Image;

use Countable;
use Intervention\Gif\Exception\EncoderException;
use Traversable;
use Intervention\Image\Analyzers\ColorspaceAnalyzer;
use Intervention\Image\Analyzers\HeightAnalyzer;
Expand Down Expand Up @@ -261,7 +262,19 @@ public function save(?string $path = null, int $quality = 75): ImageInterface
{
$path = is_null($path) ? $this->origin()->filePath() : $path;

$this->encodeByPath($path, $quality)->save($path);
if (is_null($path)) {
throw new EncoderException('Could not determine file path to save.');
}

try {
// try to determine encoding format by file extension of the path
$encoded = $this->encodeByPath($path, $quality);
} catch (EncoderException) {
// fallback to encoding format by media type
$encoded = $this->encodeByMediaType(quality: $quality);
}

$encoded->save($path);

return $this;
}
Expand Down

0 comments on commit b459723

Please sign in to comment.