0

I am working on an app in Laravel which uses Intervention Image library and Imagick to upload and resize images on the fly. Following is my code:

public function saveImage($directory, $imageObject) {
        $imageFile = $imageObject->store('app/'.$directory);

        $filename = str_replace('app/'.$directory.'/','',$imageFile);        
        $imageObject = Storage::get($imageFile);

        $img = Image::make($imageObject);
        $img->resize(null, 40, function ($constraint) {
            $constraint->aspectRatio();
        });
        $imageFile = $img->stream();

        Storage::put('app/'.$directory.'/'.$filename, $imageFile->__toString());

        // $img->save($imagePath);

        return $filename;
    }

However the problem occurs on the line Image::make($imageObject). The only error which Heroku returns is 503 Service Unavailable. Please help.

SanketR
  • 1,182
  • 14
  • 35

1 Answers1

0

Imagick is a library that needs to be installed on the machine. From heroku docs:

The following built-in extensions have been built “shared” and can be enabled through composer.json (internal identifier names given in parentheses):

Add the code from this answer to your composer.json-https://stackoverflow.com/a/35660753/2460352:

...
"require": {
     "ext-imagick": "*",
     ...
    }
}
Skarlinski
  • 2,419
  • 11
  • 28
  • Then you need more robust logging to identify your problem https://devcenter.heroku.com/articles/php-logging This link has a section about forcing laravel to output errors – Skarlinski Mar 25 '18 at 14:36
  • That helped. I updated environment variable in Heroku and found the php errors throwing up right on my screen. The issue was with gd library not installed, although I had set to use Imagick in config/image.php – SanketR Mar 26 '18 at 03:20