3

I can't figure it out. When I resize the uploaded image like so,

public function up(Request $request) {

    $user = $request->user();
    $image= $request->file('images');
        if(!empty(($image))){
        $files = Input::file('images');
        foreach($files as $file) {
            if(!empty($file)){
    $new_file = Image::make($file)->resize(200,200);
    var_dump($new_file);exit;

var_dump returns this:

object(Intervention\Image\Image)#241 (9) {
object(Intervention\Image\Imagick\Driver)#242 (2) {
["decoder"] object(Intervention\Image\Imagick\Decoder)#243 (1) {
}
["encoder"] object(Intervention\Image\Imagick\Encoder)#244 (4) {
["result"] NULL
["image"] NULL
["format"] NULL
["quality"] NULL
}
}
object(Imagick)#237 (0) {
}
["backups":protected] array(0) {
}
["encoded"] ""
["mime"] "image/jpeg"
["dirname"] "/Applications/MAMP/tmp/php"
["basename"] "phpJcAyxV"
["extension"] NULL
["filename"] "phpJcAyxV"
}

result, image,format,quality is all null. What am I missing here?

UPDATE this is the HTML:

{!! Form::open(array('action'=>'FileController@up','files'=>true,))!!}
<div class='row'>
      <div class='col-md-2'>
        {!! Form::label('images','Profile Picture')!!}
        </div>
    <div class='col-md-2 profile-pic'>
      @if(isset($pic)) 
      <img src='{{$pic}}'/>
      @else 
      <img src='/images/user-icon.jpg'/>
      @endif
    </div>
    <div class='col-md-6'>
        {!! Form::file('images[]') !!}
        {!! Form::hidden('category','profile')!!}
        {!! Form::submit('Upload',['class'=>'form-control btn btn-md btn-info','style'=>'width:100px; margin-top:50px;'])!!}
    </div>
</div>
{!! Form::close()!!}

Maybe I shouldn't use an array?

jackjoesmith
  • 951
  • 4
  • 20
  • 33
  • Are you passing in multiple files? Can you post your HTML as well? Because I can see a few things you could fix, but it depends on what you sending to the server. – Thomas Kim Nov 12 '15 at 03:03
  • I'm only passing in one file, but I use an array anyway. I have another form that actually uploads more than 1 file at a time, so I would like to know how to resize them as array objects – jackjoesmith Nov 12 '15 at 03:23

2 Answers2

1

Okay, so I took a closer look at your question. The encoder values are null because you just haven't set them. I'm assuming you weren't planning on encoding them. You still do have an image. Your server successfully received it. It just means you didn't encode it.

Also, in this code:

public function up(Request $request) {

    $user = $request->user();
    $image= $request->file('images');

    if(!empty(($image))) {
        $files = Input::file('images');

You don't need to use the Input facade to grab the images because you already got all the images when you did $request->file('images');.

In other words, Input::file('images') is exactly the same thing as $request->file('images').

Also, instead of checking whether or not it's empty, I think it's a little more readable to use the hasFile method, so I think something like this is more readable:

public function up(Request $request) {

    $user = $request->user();

    if($request->hasFile('images')) {

        $files = $request->file('images');

Overall, it would just be:

public function up(Request $request) {

    $user = $request->user();

    if($request->hasFile('images')) {

        $files = $request->file('images');

        foreach ($files as $file) {
            $new_file = Image::make($file)->resize(200,200);
        }
    }
}

Once again, when you dd($new_file) the encoder properties will still be false, but you still have an image. For example, if you return $new_file->response();, you should see the image in the new size that you set.

If you do want to encode your image, the Intervention Image package provides an encode method.

$new_file = Image::make($file)->resize(200,200)->encode();
Thomas Kim
  • 15,326
  • 2
  • 52
  • 42
0

By some reason, this work for me:

I have a current image in the filesystem, I was rotating but nothing happens, I check in source from google dev options and saw the same error you got.

object(Intervention\Image\Image)#716 (9) {
  ["driver":protected]=>
  object(Intervention\Image\Gd\Driver)#718 (2) {
    ["decoder"]=>
    object(Intervention\Image\Gd\Decoder)#719 (1) {
      ["data":"Intervention\Image\AbstractDecoder":private]=>
      NULL
    }
    ["encoder"]=>
    object(Intervention\Image\Gd\Encoder)#720 (4) {
      ["result"]=>
      NULL
      ["image"]=>
      NULL
      ["format"]=>
      NULL
      ["quality"]=>
      NULL
    }
  }

In the controller:

public function rotatePhoto($id)
{
        $photo = BookPublicationPhoto::find($id);
        $image_url = storage_path().'/cache/img/publication/'.$photo->published_book_id.'/'.$photo->image_file_name;
        $img = Image::make($image_url);
        // rotate image 90 degrees clockwise
        $img->rotate(-45);
        var_dump($img);
        $response['mensaje'] = "No tienes los permisos para eliminar ésta foto";
}

And the solution is add $img->save(); after the $img->rotate(-45); the action(rotate, resize..)

DOCS

Luigi Lopez
  • 1,037
  • 10
  • 23