1

I am using Laravel Image Intervention to resize an image upload field on my form.

This is the error I receive on upload - I am running on Valet.

Command (Extension) is not available for driver (Gd).

The following works fine without Image::make

      use Image;
      ...

      $authorID = Auth::user()->id;
      $file = request()->file('ts_image');
      if($file) {
      $file = Image::make($file)->resize(300, 300);

      $fileExtension = $file->extension();
      $unique_name = md5($file. time()).'.'.$fileExtension;
      //
      $fileImg = $file->storeAs('/public/images/' . $authorID, $unique_name);

Any ideas? Thanks!

Edit:

When dd($file) this is what is returned:

Image {#667 ▼
  #driver: Driver {#668 ▼
    +decoder: Decoder {#669 ▼
      -data: null
    }
    +encoder: Encoder {#670 ▼
      +result: null
      +image: null
      +format: null
      +quality: null
    }
  }
  #core: gd resource @16 ▼
    size: "300x300"
    trueColor: true
  }
  #backups: []
  +encoded: ""
  +mime: "image/jpeg"
  +dirname: "/private/var/tmp"
  +basename: "phpBPRGuD"
  +extension: null
  +filename: "phpBPRGuD"
}
8
  • As its uploaded file it wont have an extension, from what im seeing by googling that error this and this you may need to use $file->mime() and then match it. Commented Nov 11, 2018 at 20:26
  • @LawrenceCherone hmm interesting, when dd($image) I do seem to get the mime type back. See updated question. Commented Nov 11, 2018 at 21:01
  • Yeah as said above, extension is null so its not available, the extension method is only a getter. So you prob need to just match out the mime, though im not sure how safe it is just to trust it. Commented Nov 11, 2018 at 21:05
  • 1
    np, cryptic error though as its got nothing to do with it being gd, good luck Commented Nov 11, 2018 at 21:10
  • 1
    You can just create it if it does not exist i.e 3v4l.org/ERu0p Commented Nov 11, 2018 at 21:21

1 Answer 1

2

I used intervention to save my images into the database. I was working with laravel and i had to save images of different size, large, medium and small. this how it works for me

      if ($request->hasFile('image')) {
        $image_tmp = Input::file('image');
        if ($image_tmp->isValid()) {

            $extension = $image_tmp->getClientOriginalExtension();
            $filename = rand(111, 99999) . '.' . $extension;
            $large_image_path = 'images/backend_images/products/large/' . $filename;
            $medium_image_path = 'images/backend_images/products/medium/' . $filename;
            $small_image_path = 'images/backend_images/products/small/' . $filename;
            //resize image
            Image::make($image_tmp)->save($large_image_path);
            Image::make($image_tmp)->resize(600, 600)->save($medium_image_path);
            Image::make($image_tmp)->resize(300, 300)->save($small_image_path);
            $product->image = $filename;

        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.