To show your code, wrap it in three backticks:
```
// code
```
I have this problem! I am using intervention/image to resize a image then I want to call the store method (that is built in to laravel, automatically hashes the filename and saves it to the storage folder) But this is throwing an error cannot call store on imagemagick
Please! for anyone trying to help I don't know how to display may code in pretty black boxes, If you tell my how I will be happy to display my code!
To show your code, wrap it in three backticks:
```
// code
```
The thumbnails episode covers how to work with intervention image and store.
To display formatted code, place three backticks on the line before and line after the code block:

// Like this!
You can also click the link at the lower right corner of the textarea to see all the formatting options:

public function store(Request $request)
{
$myTheory = new MyTheory();
$myTheory->title = $request->get('title');
$myTheory->user_id = Auth::id();
$myTheory->description = $request->get('description');
$myTheory->hypothesis = $request->get('hypothesis');
$myTheory->video = $request->get('video');
//store image coverphoto and write path to database
if ($request->file('image')->isValid()){
$image = $request->file('image');
$manager = new ImageManager(array('driver' => 'imagick'));
$image = $manager->make($image)->resize(320,240);
$img = $image->save('coverphoto.jpg');
$myTheory->image = "1";
}
$myTheory->save();
return redirect()->route('mytheories.index')
->with('message', 'You have successfully posted a new experiment!');
}
The above code works but what I want to achieve is the follwing that does not work
//store image coverphoto and write path to database
if ($request->file('image')->isValid()){
$image = $request->file('image');
$manager = new ImageManager(array('driver' => 'imagick'));
$image = $manager->make($image)->resize(320,240);
$path = $image->store('coverphoto');
//$img = $image->save('coverphoto.jpg');
//$myTheory->image = "1";
$myTheory->image = $path;
I usually store the photo first, then alter it and resave it. Something like this:
$imagePath = $request->file('photo')->store('/path');
$image = Image::make(Storage::get($imagePath))->resize(320,240);
Storage::put($imagePath, $image);
Then I store the image path on the model the image belongs too.
In your case, you are hardcoding the image name so new images will overwrite your old one.
I did what you suggested and I am successfull at storing the correct imagePath but unsucessfull at saving an image. in the storage folder the file is created with a hashed filename, but upon opneing the file there is nothing in it?
<?php
namespace App\Http\Controllers;
use Storage;
use Image;
use Gate;
use Auth;
use App\MyTheory;
use Illuminate\Http\Request;
class MyTheoriesController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$myTheories = MyTheory::where('user_id', Auth::user()->id)->get();
return view('mytheories.index')->with('myTheories', $myTheories);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('mytheories.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$myTheory = new MyTheory();
$myTheory->title = $request->get('title');
$myTheory->user_id = Auth::id();
$myTheory->description = $request->get('description');
$myTheory->hypothesis = $request->get('hypothesis');
$myTheory->video = $request->get('video');
//store image coverphoto and write path to database
if ($request->file('image')->isValid()){
/*
$image = $request->file('image');
$manager = new ImageManager(array('driver' => 'imagick'));
$image = $manager->make($image)->resize(320,240);
$img = $image->save('coverphoto.jpg');
$myTheory->image = "1";
*/
$imagePath = $request->file('image')->store('coverphotos');
$image = Image::make(Storage::get($imagePath))->resize(320,240);
Storage::put($imagePath,$image);
$myTheory->image = $imagePath;
}
$myTheory->save();
return redirect()->route('mytheories.index')
->with('message', 'You have successfully posted a new experiment!');
}
When you say there is nothing in it, do you mean in the browser or in the actual file in the storage directory?
Everything works I can save the correct file path to the DB and I am creating a jpeg file to the storage/coverphotos folder, and the filename of the jpeg file is hashed, the only problem is that , the hashedfilename,jpeg, does not contain the resized image!
I have tried shuffling the code around and making it work but to no avail!
It seems that the last procedure is correct and that the problem might be with the get request but I could be off on this one, because I don't know how to fix!
Thanks in advance for anyone that is willing to help!
Big ups to all the small guys working day and night to learn a new craft without any formal training and getting this far! If anyone is interested If you want to install imagick on a lunix box used with homestead see video! It really helps ! https://youtu.be/q3c6O85_LoA
In the storage directory there is nothing. It saves a jpeg file, but there is nothing no picture only empty space!!! Don't know how to better explain it!
Try saving it without the resize.
$imagePath = $request->file('image')->store('coverphotos');
// $image = Image::make(Storage::get($imagePath))->resize(320,240);
// Storage::put($imagePath,$image);
Do you see anything?
...watch the video I linked to...
I have tried without resize then it saves the file correctly I have a full jpeg in the file, only when resize is used I get no output
@willvincent, Thanks I did watch the video it is a bit broad for the specific problem , but maby you know of a solution. It seems most of the conditions are satisfactory and I am getting everything done except the small point about having content in the jpeg file...
@zachleigh! THANK YOU! Every second a developer is helping a fellow student he is not earing the $$$ and I know what time is worth!! THANKS.
It looks like a lot of people have this problem if they have whitespace in a config file. Try making this route:
Route::get('/test-empty-response', function() { return ''; });
Then visit the route '/test-empty-response'. If you inspect it with dev tools it should be completely empty. Do you see any spaces?
I have a complete empty page!
@gustav1105 Think I got it. Try this:
$image = Image::make(Storage::get($imagePath))->resize(320,240)->encode();
The resize method doesnt return the image, but the encode method does.
Please or to participate in this conversation.