Imagick on heroku - is it possible?

I need to do some action on jpeg images - Heroku PHP GD does not allow this. I read that this is possible with Imagick, so I rewrote the code, clicked on the hero and ...

PHP Fatal error: class "Imagick" not found in [...]

So what am I doing something wrong (the code works locally)?

$tlo = new Imagick(); $tlo->newImage(640, 480, new ImagickPixel('white')); $tlo->setImageFormat('jpg'); 

Is there any way to work with jpg on heroku?

+6
source share
2 answers

ImageMagick, a command line utility and programming library, must be installed on the system for Imagick to work.

If this does not work for you, then presumably with Heroku PHP web speakers this is not installed by default. You have two options: you can find a complex way to batch ImageMagick with the application itself, for example by adding compiled binaries to the git source tree. Or you can modify the Heroku PHP buildpack , which is a set of rules that configure web dino before deploying your application, to install ImageMagick along with Apache and PHP. The latter approach is more likely to work.

After you have changed the buildpack, change the application to point to your buildpack fork with Heroku tools from the command line (option --buildpack) and redistribute it.

+2
source

A simpler approach is to install ImageMagick with composer.json as described here: https://devcenter.heroku.com/articles/php-support#php-5-5-and-5-6

You just need to include imagick in the require section and update the composer:

 { ... "require": { "ext-imagick": "*", ... } } 
+6
source

Source: https://habr.com/ru/post/919633/


All Articles