2

Problem with laravel Image:

I have my code to store the image and it is:

$img = Image::make(asset('public/storage/assets/'.$product->image));

$img->insert(asset('template/images/logo-1000frases-w.png'), 'bottom-left', 10, 10);

$img->save(public_path('public/storage/assets/'.$product->image));

I add a watermark on the image and then I store it.

The problem is.. when I try to store the image it says:

Unable to init from given url (http://138.197.121.221/public/storage/assets/ijTdImC4dIcobYa1QSDA59oDiF8J8e0FjQS1EG3n.jpeg).

But I have the correct path... public, storage, assets, all of them exist; I wonder what could it be?

Thanks!

4
  • public path starts from from public/ folder you need to remove public/ from asset(). Commented Jul 1, 2017 at 5:13
  • Hmmm it still shows the problema :/ Commented Jul 1, 2017 at 5:18
  • 1
    You should use storage_path() not public_path() for example: $img->save(storage_path('assets/'.$product->image)); Commented Jul 1, 2017 at 5:35
  • Image::make() requires path as parameter no URL Commented Jul 1, 2017 at 8:30

2 Answers 2

2

you may upload your imgae in laravel 5 using this way

        $image=$request->file('image');
        $fileName=$image->getClientOriginalName();
        $path = $image->move('storage/assets/',$fileName); 
        $folderPath=url('/).''.'/uploads/blog/'.''.$fileName;

image is your key for request image. $folderPath variable is use for save in your database table. This may work for you

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

2 Comments

This does not attempt to answer what was wrong in the original question.
Thanks! it gave me some ideas.
0

I could get a solution:

$file = $request->file('image');
$fileName = time() . '-' . $file->getClientOriginalName();
$path = $file->move('storage/assets/',$fileName); 

Then:

$img = Image::make($path);
$img->insert(asset('template/images/logo-1000frases-w.png'), 'bottom-left', 10, 10);
$img->save(public_path('storage/assets/'.$product->image));

And this is it! :D

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.