Imagick on heroku - is it possible?

梦想的初衷 提交于 2019-12-28 23:58:53

问题


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?


回答1:


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.




回答2:


A simpler approach is to install ImageMagick using composer.json, as explained 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 composer:

{
    ...
    "require": {
         "ext-imagick": "*",
         ...
    }
}


来源:https://stackoverflow.com/questions/11319961/imagick-on-heroku-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!