Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagick on heroku - is it possible?

I need to do some actions on jpeg images - Heroku's PHP GD does not allow that. I've read that it is possible with Imagick, so i rewritten the code, pushed it to heroku and...

PHP Fatal error: Class 'Imagick' not found in [...]

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

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

Is there any way of working with jpg on heroku?

like image 409
anonim1133 Avatar asked Jul 03 '12 22:07

anonim1133


2 Answers

A simpler approach is to install ImageMagick using composer.json, as explained here: https://devcenter.heroku.com/articles/php-support#using-optional-extensions

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

{
    ...
    "require": {
         "ext-imagick": "*",
         ...
    }
}
like image 162
eillarra Avatar answered Oct 22 '22 05:10

eillarra


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

If it's not working for you, then presumably Heroku's PHP web dynos do not have this installed by default. You have two options: you can find some convoluted way to package ImageMagick with your application itself, for instance by adding compiled binaries to your git source tree. Or, you can modify the Heroku PHP buildpack, which is the set of rules that sets up the web dyno before your application is deployed, to install ImageMagick along with Apache and PHP itself. The latter approach is more likely to work.

Once you've modified the buildpack, change your application to point to your buildpack fork with the command-line Heroku tools (the --buildpack option) and redeploy.

like image 33
Andrew Gorcester Avatar answered Oct 22 '22 03:10

Andrew Gorcester