Diego Cespedes
Diego Cespedes

Reputation: 1353

Laravel 5.2 - Intervation image, save base64 input images

i'm passing to my controller input with images base64, i'm using intervation image to resize, use canvas, save images. but i have some problem with decode image base64:

ErrorException in PostController.php line 163: base64_decode() expects parameter 1 to be string, array given

public function creaPost(Request $request){
    $image_array = $request->input('image'); // input image base64
    $contare = count($image_array);

    for($i = 0; $i < $contare; $i++) {

                        $file = base64_decode($image_array[$i]);

                        if (!empty($file)) {


                        $background = Image::canvas(550, 550);
                        $image2 = Image::make($file)->encode('jpg', 100)-                    >resize(550, 550, function ($c) {
                        $c->aspectRatio();
                        $c->upsize();
                        });
                        ... my code...etc..
                        $store_path->save(); 

                        } 
    }
}

the line $file = base64_decode($image_array[$i]); return the error, i don't know how can i decode well my array images.

MAYBE CAN HELP if i do:

$image_array = $request->input('image');
return dd($image_array[1]);

return this: enter image description here

Upvotes: 1

Views: 3208

Answers (1)

piotr
piotr

Reputation: 1282

Use

foreach($image_array as $key => $image) {
    $file = base64_decode($image);

Error occurs cause in your for loop you are using numeric values, but your $image_arrayhas non-numeric indexes. First index wasn't 0 but dsdas.PNG

Upvotes: 2

Related Questions