Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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');
    }
like image 650
Debjit Roy Avatar asked Feb 11 '26 08:02

Debjit Roy


2 Answers

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.

like image 56
Mohammad Abbas Avatar answered Feb 15 '26 14:02

Mohammad Abbas


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

like image 36
Rob Fonseca Avatar answered Feb 15 '26 13:02

Rob Fonseca