3

I'm trying to store an image from a URL using Intervention to my storage.

Here is what I tried so far(Attempt 1):

$path = 'http://f2b9x.s87.it/images/1/FR_laura-kithorizontal.gif';
$filename = basename($path);
$image = Image::make($path);
$store = $image->storeAs('image/'.$filename,'public');

But I get this error: Command (storeAs) is not available for driver (Gd).

Then I tried this (Attempt 2):

Image::make('http://f2b9x.s87.it/images/1/FR_laura-kithorizontal.gif')->save(public_path('/images/saveAsImageName.jpg'));

But I got this error: Can't write image data to path (C:\xampp\htdocs\app\public\/images/saveAsImageName.jpg)

In Attempt 2, I tried doing also this: public_path('\images\saveAsImageName.jpg') just to make sure it wasn't the backslashes causing the problem, but it gave me the same error.

Any help?

Adam Silva
  • 1,013
  • 18
  • 48
  • 1
    Does the location you're trying to save to actually exist? If so, is it writable? Also, specifically, is it writable by the user being used by your PHP? Few things to check to solve the generic "Can't write image data...". – Tim Lewis May 18 '17 at 16:36

2 Answers2

0

Try this

Image::make('http://f2b9x.s87.it/images/1/FR_laura-kithorizontal.gif')->save(public_path('images/saveAsImageName.jpg'));

Notice that I left out your first slash ("/") in the public_path() function.

Solid
  • 105
  • 2
  • 15
0

The problem was that I didn't have the directories created (thanks @Tim Lewis)

I solved it like this:

use File;

File::makeDirectory(public_path('images/kits/'.$microtime), 0775, true);

The first parameter is the path
The second parameter is the privileges given to that folder
The third parameter is normally by default false, but if true, it creates the directories recursively. Meaning that it first checks if images is created, then kits, and then (in this case) if the folder with that microtime is created.
If none exist, it creates all of them.

Adam Silva
  • 1,013
  • 18
  • 48