Closed briankung closed 5 years ago
This is not a wand-py issue, but more of a case-study for devops. Wand is a C-API binding for ImageMagick's MagickWand library, and it can only assume that the underlining environment + dependencies are installed correctly. For Heroku, a customized buildpack is the correct method for deploying your solution, and GitHub is full of examples that may work for your business requirements. It might also be time to evaluate if a configuration management solution is needed in you development cycle. Something like Ansible, Chef, or Puppet to name a few.
Wand/ImageMagick not working in Heroku
I have a
Stamp
class that uses Wand 0.4.0 to draw some text onto images. The relevant portions are below:This works locally with no complaints. On Heroku, I am using the Heroku Cedar-14 imagemagick buildpack. When I try to to execute the ImageMagick related code directly from the heroku instance's shell (
heroku run python manage.py shell
orbash
), I get various errors. If I supply a file path, it complains that it is missing a decode delegate:...and if I provide it a file (and/or a format), it gives me a
UnicodeDecodeError
:Via
shell
orpython manage.py shell
, ImageMagick reports that it has all the necessary delegates to handlePNG
:convert
in shellHere's a standard filetype
convert
working just fine without annotation:However,
convert
with the example annotation from the ImageMagick docs throws two errors about missing adelegates.xml
, which looks familiar, and atype.xml
.The files,
delegates.xml
andtype.xml
, both exist on my Heroku instance. If I copy them from/etc/ImageMagick/
or/app/.apt/etc/ImageMagick-6/
to a directory thatconvert
is expecting, like/app/.magick/
, then all but the Font errors disappear. And I can make the font errors go away by specifying a font (ex.convert ... -font 'Nimbus Mono L
) fromconvert -list font
.However, this is not a long-term solution, as Heroku uses an ephemeral writeable filesystem and changes are lost. It's also a configuration step that would ideally be handled by the buildpack. Unfortunately, I wasn't able to figure out if there was something in the buildpack that I could tweak.
Other attempts
I halfheartedly customized the buildpack to use the same version of ImageMagick that I was using locally (6.9.1-3), which failed to install properly. I also tried specifying a
runtime.txt
to make the Heroku Python environment match my local environment (3.4.3), which worked just fine, but it wasn't the problem.Help!
If anyone has gotten Wand working on Heroku and I'm missing something obvious, please do tell! I'm new to Python. For what it's worth, this is within a Django app, though the
Stamp
model itself is just vanilla Python model.Thanks!