3

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');
    }
Debjit Roy
  • 35
  • 1
  • 1
  • 4

7 Answers7

7

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.

Mohammad Abbas
  • 556
  • 1
  • 4
  • 11
3

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

Rob Fonseca
  • 3,671
  • 2
  • 17
  • 13
0

Saw this somewhere and it worked for me

$image->save('foo' . $img->getClientOriginalExtension());
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

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

 $categoryImage = Image::make($image)->resize(1600,479)->save( $imageName,90);
Vega
  • 27,856
  • 27
  • 95
  • 103
0

I've solved this by

Trimming my file path, i was using this script inside laravel Artisan Console.

$img->save(trim('public/uploads/images/thumbnails/'.$subFolder.'/'.$filename));
0

Rather you use stream its working without error

$categoryImage = Image::make($image)->resize(1600,479)->save(); 
Gaslan
  • 808
  • 1
  • 20
  • 27
Julfikar Haidar
  • 93
  • 2
  • 10
0
  1. $categoryImage = Image::make($image)->resize(1600,479)->save(); Storage::disk('public')->put('category/'.$imageName, $categoryImage);

change to

Image::make($image)->resize(1600, 479)->save(storage_path('app/public/category').'/'.$imagename);
$categorySlider = Image::make($image)->resize(500,333)->save();
Storage::disk('public')->put('category/slider/'.$imageName, $categorySlider);

change to

Image::make($image)->resize(500, 333)->save(storage_path('app/public/category/slider/') .$imagename);
General Grievance
  • 4,555
  • 31
  • 31
  • 45