Intervention/image · error · Intervention\Image\Exceptions\EncoderException

Unable to determine path for saving

Error message

Unable to determine path for saving

What it means

save() with no path argument tries to reuse the file path stored in the image's origin. Images that never came from a file — created with ImageManager::create(), decoded from a binary string, base64 data, a stream, or a data URI — have no origin path, so there is nothing to determine and an EncoderException is thrown. The library refuses to guess a write location.

Source

Thrown at src/Image.php:313

     * {@inheritdoc}
     *
     * @see ImageInterface::save()
     *
     * @throws InvalidArgumentException
     * @throws EncoderException
     * @throws DirectoryNotFoundException
     * @throws FileNotWritableException
     * @throws StreamException
     * @throws NotSupportedException
     */
    public function save(?string $path = null, mixed ...$options): ImageInterface
    {
        if ($path === '') {
            throw new InvalidArgumentException('Argument $path must not be an empty string');
        }

        if (is_null($path) && is_null($this->origin()->filePath())) {
            throw new EncoderException('Unable to determine path for saving');
        }

        $path = is_null($path) ? $this->origin()->filePath() : $path;

        try {
            // try to determine encoding format by file extension of the path
            $encoded = $this->encode(new FilePathEncoder($path, ...$options));
        } catch (EncoderException) {
            // fallback to encoding format by media type
            $encoded = $this->encode(new MediaTypeEncoder(null, ...$options));
        }

        $encoded->save($path);

        return $this;
    }

    /**

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Pass an explicit output path: $image->save('/storage/thumbs/foo.jpg')
  2. If you have the source file, read from the path (not from its contents) so the origin is recorded: $manager->read($uploadedFile->getPathname())
  3. Chain ->encode('png') and handle the EncodedImage result yourself when no filesystem path is wanted

Example fix

// before
$image = $manager->read($request->file('avatar')->getContent());
$image->save(); // EncoderException: no origin path

// after
$image = $manager->read($request->file('avatar')->getPathname());
$image->save(); // rewrites the uploaded file, or pass an explicit path
Defensive patterns

Strategy: validation

Validate before calling

$path = $image->origin()->filePath();
if ($path === null) {
    $path = $outputDirectory . '/' . $filename . '.jpg';
}
$image->save($path);

Type guard

function hasOriginPath(ImageInterface $image): bool
{
    return $image->origin()->filePath() !== null;
}

Try / catch

try {
    $image->save();
} catch (EncoderException $e) {
    $image->save('/tmp/fallback-' . uniqid() . '.jpg');
}

Prevention

When it happens

Trigger: $manager->create(100, 100)->save();, $manager->read($binaryString)->save();, or any image whose origin()->filePath() is null, with save() called without arguments. save('/path.jpg') with a real path never triggers this.

Common situations: Generating thumbnails/derivatives from uploaded file contents (Laravel UploadedFile ->getContent() gives a string, not a path), creating canvases or watermarks programmatically, or refactoring code that previously always loaded from a file path.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/84d8c2b524f019a9. Report an issue: GitHub.