Search code examples
laravelintervention

Intervention\Image\Exception\NotSupportedException Encoding format (tmp) is not supported


I am using the Intervention package with Laravel 5.6, the issue I am getting whenever I am uploading a file I have been presented with the error Encoding format(tmp) is not supported. I have my gdd2 extension enabled also. This is the code where I have used.

public function store(Request $request)
    {
        $this->validate($request , [
            'name'          => 'required|unique:categories',
            'description'   =>  'max:355',
            'image'         =>  'required|image|mimes:jpeg,bmp,png,jpg'
        ]);

        // Get Form Image
        $image = $request->file('image');
        $slug = str_slug($request->name);
        if (isset($image))
        {
            $currentDate = Carbon::now()->toDateString();
            $imageName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
            // Check if Category Dir exists
            if (!Storage::disk('public')->exists('category'))
            {
                Storage::disk('public')->makeDirectory('category');
            }
            // Resize image for category and upload
            $categoryImage = Image::make($image)->resize(1600,479)->save();
            Storage::disk('public')->put('category/'.$imageName, $categoryImage);

            // Check if Category Slider Dir exists
            if (!Storage::disk('public')->exists('category/slider'))
            {
                Storage::disk('public')->makeDirectory('category/slider');
            }

            // Resize image for category slider and upload
            $categorySlider = Image::make($image)->resize(500,333)->save();
            Storage::disk('public')->put('category/slider/'.$imageName, $categorySlider);

        }
        else
        {
            $imageName = 'default.png';
        }

        $category = new Category();
        $category->name = $request->name;
        $category->slug = $slug;
        $category->description = $request->description;
        $category->image = $imageName;

        $category->save();
        Toastr::success('Category Saved Successfully','Success');
        return redirect()->route('admin.category.index');
    }

Solution

  • The Intervention image save() method requires a filename so it knows what file format (jpg, png, etc..) to save your image in.

    The reason you are getting the error is it does not know what encoding to save the temporary image object (tmp) in.

    Here is an example

    ->save('my-image.jpg', 90)
    

    There is also a optional second parameter that controls the quality output. The above outputs at 90% quality.

    http://image.intervention.io/api/save