Holo
Holo

Reputation: 597

Resizing images using Laravel and the Intervention package

I am trying to manipulate images in Laravel using intervention I have followed all the required set up to use imagick. I use vagrant with centOS and it all shows everything is working as it should via phpinfo ();

When I run the following (snippit from the controller)

public function store()
{
    //Get all the user fields 

    $user = new User;

    $user->username = Input::get('username');
    $user->name = Input::get('name');
    $user->email = Input::get('email');
    $user->gender = Input::get('gender');
    $user->country = Input::get('country');
    $user->website = Input::get('website');
    $user->bio = Input::get('bio');

    //Check for and store user image

    if (Input::HasFile('image'))

    {
        $image = Image::make(Input::file('image'));

        $name = time() . '-' . $image->getClientOriginalName();

        $image->resize(100, 100);

        $image = $image->move(public_path() . '/images/avatars/', $name);

        $user->image = $name;


    }

    $user->save();

    return redirect('/admin/users');

}

It does everything I expect but resize the image. It get the image from the Input, assigns the new name and saves it in the right place. When I view it on the page it is simply the original size.

It does all this without error, so I am unsure whether the issue is with my code or on the server side.

Any help appreciated.

Upvotes: 0

Views: 439

Answers (2)

Holo
Holo

Reputation: 597

Dammit, it was server side, the memory set on vagrant was the issue, i.e not enough of it!

Upvotes: 0

maztch
maztch

Reputation: 1697

I had same problem, and solved it using Request class and not Input.

use Request;
// or depends of your app config
// use Illuminate\Http\Request;
...
if (Request::hasFile('image'))
{
    $image = Image::make(Request::file('image'));
...

Note: in laravel5 docs they not use Intput anymore: http://laravel.com/docs/5.0/requests and also is a good idea use the dependency injection so you can extend it and add rules and validations if needed...

Upvotes: 1

Related Questions