GitHub Readme.md
Use ImageMagick built with libwebp inside a Heroku heroku-16
environment. This buildpack will download both libraries, build them from source and install them along side your app.
The rise in popularity and use of HEIF/HEIC(High Efficency Image Format) means your project's image processing also needs to be able to handle this format. The current default version of imagemagick installed on heroku:16 dynos is 6.8.9.9 and does not support processing heic image files. This Heroku buildpack vendors a version of ImageMagick with HEIF support binaries into your project. It is based on several resources including https://github.com/retailzipline/heroku-buildpack-imagemagick-heif.
The orginal buildpack was created for heroku-18
stacks but this one was modified to work with Heroku stack: heroku-16
.
The tar file in the /build folder currently contains:
Version: ImageMagick 7.0.10-19 https://imagemagick.org
You will need to build a new binary if you want to use a newer or different version. To build a new binary see How to Build a New Binary
NOTE: To ensure the newer version of imagemagick is found in the $PATH and installed first make sure this buildpack is added to the top of the buildpack list or at "index 1".
From your projects "Settings" tab add this buildpack to your app in the 1st position:
https://github.com/HiMamaInc/heroku-buildpack-imagemagick-heif
OR
From the command line:
heroku buildpacks:add https://github.com/HiMamaInc/heroku-buildpack-imagemagick-heif --index 1 --app HEROKU_APP_NAME
The binary in this repo was built in a heroku:16 docker image running in a local dev environment. The tar file was then copied into the /build
directory in this repo and is used by the compile script.
Prerequisites
Steps:
Spin up a docker container with the heroku:16 stack. This will build and behave exactly the same way a heroku:16 dyno except you will have write access. (make sure docker is running on your machine). From command line:
$ docker run --rm -it heroku/heroku:16-build
This will take you to an interactive bash shell as a root user inside the container. The --rm
flag removes the docker process on exiting. The -ti
flag creates the interactive bash shell.
Get the libraries and dependencies you need(some of these already exist on the system):
$ apt-get update && apt-get install build-essential autoconf libtool git-core
$ apt-get build-dep imagemagick libmagickcore-dev libde265 libheif
Download the libwebp, libde265 and libheif libraries:
$ git clone https://github.com/strukturag/libde265.git
$ git clone https://github.com/strukturag/libheif.git
$ curl -L --silent "http://downloads.webmproject.org/releases/webp/libwebp-1.1.0.tar.gz" | tar xz
install the libde265 library:
$ cd libde265/
$ ./autogen.sh && ./configure && make && make install
Install the libheif library:
$ cd ../libheif/
$ ./autogen.sh && ./configure && make && make install
Install the libwebp library:
$ cd ../libwebp-1.1.0/
$ ./configure && make && make install
Get, Configure and Install Newest Imagemagick:
$ cd /usr/src/
$ git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick
$ cd ImageMagick
$ ./configure --prefix=/usr/src/imagemagick --with-heic=yes --with-webp --with-gvc=no --with-quantum-depth=8 --disable-static
$ make && make install
Take a break this will take a few min to install.
Copy the dependencies into imagemagick lib directory:
$ cp /usr/local/lib/libde265.so.0 /usr/src/imagemagick/lib
$ cp /usr/local/lib/libheif.so.1 /usr/src/imagemagick/lib
$ cp /usr/lib/x86_64-linux-gnu/libomp.so.5 /usr/src/imagemagick/lib
$ cp /usr/lib/x86_64-linux-gnu/libiomp5.so /usr/src/imagemagick/lib
The last 2 libraries are not available at run time on heroku only build time see Ubuntu Packages on Heroku Stacks for more info
Clean up the build and get ready for packaging:
$ cd /usr/src/imagemagick
$ strip lib/*.a lib/lib*.so*
Wrap it up with a bow(compress the binary):
$ cd /usr/src/imagemagick
$ rm -rf build
$ mkdir build
$ tar czf /usr/src/imagemagick/build/imagemagick.tar.gz bin include lib
Copy the compressed file/tarball from the docker container into the repo(you need to have cloned this repo locally):
# List current running docker processes to find out the NAME of your container
$ docker ps
# copy the binary from the container to the build directory in the repo on your local machine
$ docker cp <NAME_of_docker_container>:/usr/src/imagemagick/build/imagemagick.tar.gz <path_to_build_folder_in_git_repo>
DO NOT EXIT YOUR CONTAINER or ALL will be lost, open a new tab in your terminal
You may need to delete the old tarball from the bin folder first or to be safe copy the file from the container to your local machine before adding to the repo so you have a copy of the old binary tarball.
Since the installation is cached you might want to clean it out due to config changes.
heroku plugins:install heroku-repo
heroku repo:purge_cache -app HEROKU_APP_NAME
https://medium.com/@eplt/5-minutes-to-install-imagemagick-with-heic-support-on-ubuntu-18-04-digitalocean-fe2d09dcef1 https://github.com/brandoncc/heroku-buildpack-vips https://github.com/steeple-dev/heroku-buildpack-imagemagick https://github.com/retailzipline/heroku-buildpack-imagemagick-heif
Copy the snippet above into CLI.