mercredi 9 novembre 2016

Can't resize same file in 2 seperate formats . Intervention Image - Laravel

Using: Laravel 5.2 , Intervention Image http://image.intervention.io/

I have a form with the possibility to upload an image. This image gets resized and stored on my server . This all works perfectly , but i recently had the need to make a second image size. So i did the following:

Controller

// Resize uploaded thumbnail and return the temporary file path
        $thumbnail = $request->file('thumbnail');
        $thumbnail_url = $this->storeTempImage($thumbnail,350,230);
        $video_thumbnail_url = $this->storeTempImage($thumbnail,1140,640);

StoreTempImage Method

  public function storeTempImage($uploadedImage, $width, $height) 
    {
        //resize and save image to temporary storage
        $originalName = $uploadedImage->getClientOriginalName();
        $name = time() . $originalName;
        $uploadedImage->move('images/temp/', $name);

        Image::make("images/temp/{$name}")->fit($width, $height, function ($constraint) {
            $constraint->upsize();
        })->save("images/temp/{$name}");

        return "images/temp/{$name}";
    }

After i post the form my first image gets correctly saved, but after that it throws an error:

The file "myfile.jpg" was not uploaded due to an unknown error.

What i've tried

  1. My first idea was that the time() function was not specific enough and that the file had the same name. So i changed time() to microtime(true)

  2. I made 2 seperate methods for the image sizes

Both solutions didn't work and threw the same error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire