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.
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": "*",
...
}
}