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

Debjit Roy picture Debjit Roy · Apr 27, 2018 · Viewed 10.9k times · Source

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');
    }

Answer

Mohammad Abbas picture Mohammad Abbas · Jun 8, 2018

You don't need to use the save() function on the Intervention\Image class as you are saving the file to your public disc via the Storage Facade.

Simply replace the line

$categoryImage = Image::make($image)->resize(1600,479)->save();

with

$categoryImage = Image::make($image)->resize(1600,479)->stream();

to avoid having to store the image to the temp folder under a .tmp extension. Laravel Storage Facade will handle the stream created by Intervention\Image and store the file to the public disk.