1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-10 16:04:04 +02:00

Allow Image::save() to be used without file extension

This commit is contained in:
Oliver Vogel
2023-12-29 17:05:40 +01:00
parent d4c13112ac
commit b4597236d4

View File

@@ -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;
@@ -261,7 +262,19 @@ final class Image implements ImageInterface, Countable
{
$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;
}