Skip to content

Commit 2b3d35b

Browse files
committed
WIP
1 parent 37a5321 commit 2b3d35b

File tree

8 files changed

+103
-123
lines changed

8 files changed

+103
-123
lines changed

README.md

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,79 @@
1-
# heroku-buildpack-imagemagick-heif
21

3-
[![Build Status](https://github.com/yespark/heroku-imagemagick-buildpack/workflows/ci/badge.svg)](https://github.com/yespark/heroku-imagemagick-buildpack/actions?query=workflow%3Aci)
2+
# Heroku Buildpack for ImageMagick with HEIF/HEIC/AVIF/WebP Support
3+
4+
```
5+
_____ _ _
6+
\_ \_ __ ___ __ _ __ _ ___ /\/\ __ _ __ _(_) ___| | __
7+
/ /\/ '_ ` _ \ / _` |/ _` |/ _ \/ \ / _` |/ _` | |/ __| |/ /
8+
/\/ /_ | | | | | | (_| | (_| | __/ /\/\ \ (_| | (_| | | (__| <
9+
\____/ |_| |_| |_|\__,_|\__, |\___\/ \/\__,_|\__, |_|\___|_|\_\
10+
|___/ |___/
11+
```
412

5-
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.
6-
The current default version of imagemagick installed on heroku:24 dynos is a version 6.xx and does not support processing heic image files.
13+
[![Build Status](https://github.com/yespark/heroku-imagemagick-buildpack/workflows/ci/badge.svg)](https://github.com/yespark/heroku-imagemagick-buildpack/actions?query=workflow%3Aci)
714

8-
This [Heroku buildpack](https://devcenter.heroku.com/articles/buildpacks) vendors a version of ImageMagick with **WEBP and HEIF support** binaries into your project.
15+
# Documentation
916

10-
This one works was built for [**Heroku stack 20**](https://devcenter.heroku.com/articles/stack).
17+
With the rise in popularity of HEIF/HEIC (High Efficiency Image Format), your project needs to handle this format efficiently. The default version of ImageMagick installed on Heroku:22/24 dynos (version 7.xx) does not support processing HEIC and AVIF image files.
1118

12-
The tar file in the [/build folder](./build) currently contains:
19+
This [Heroku buildpack](https://devcenter.heroku.com/articles/buildpacks) includes a version of ImageMagick with **HEIF/HEIC/AVIF/WebP support**.
1320

14-
Version: ImageMagick 7.1.1-35
21+
The binaries in this repository were built using Heroku Docker images with the [**build.sh**](./build.sh) script. The resulting tar files are stored in the `/build` directory and utilized by the [compile script](./bin/compile).
1522

16-
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](#how-to-build-a-new-binary)
23+
The `/build` directory currently contains:
1724

18-
# Usage
25+
Versions:
26+
- ImageMagick 7.1.1-35
27+
- libde265 1.0.15
28+
- libwebp 1.4.0
29+
- libheif 1.18.1
1930

20-
## Step 1 : Adding the buildpack
31+
# Using the Heroku Imagemagick buildpack
2132

22-
From your projects "Settings" tab add this buildpack to your app in the 1st position:
33+
It's suggested that you use the latest version of the release buildpack. You can set it using the heroku-cli.
2334

2435
```bash
25-
https://github.com/yespark/heroku-imagemagick-buildpack
36+
heroku buildpacks:set https://github.com/yespark/heroku-imagemagick-buildpack --index 1 -a your-app-name
2637
```
2738

28-
**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"._
29-
30-
## Step 2 : Clear the cache(**Not Sure if this is necessary**)
39+
Your builds will always used the latest published release of the buildpack.
3140

32-
Since the installation is cached you might want to clean it out due to config changes.
41+
**NOTE:**
42+
- 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 (index 1).
43+
- If needed, clear the cache due to configuration changes:
3344

3445
```bash
3546
heroku plugins:install heroku-builds
3647
heroku builds:cache:purge -a HEROKU_APP_NAME
3748
```
3849

39-
# How to Build a New Binary (if you want to make somes changes)
40-
41-
The binary in this repo was built in a heroku:22 docker image running in a local dev environment.
42-
However, there is a script called [**build.sh**](./build.sh) made to build a tar file through docker easily, it will be copied to the `build` directory. Then you should commit this changes to your git, and adjust the buildpack url previously mentioned just above.
43-
44-
## Prerequisites
50+
## Development
4551

46-
- Docker installed and running in local dev environment. [Get Docker](https://docs.docker.com/get-docker/)
52+
This Dockerfile builds ImageMagick with updated libraries (libde265, libwebp, and libheif) on a Heroku stack. Here's a breakdown of the process:
4753

48-
## Credits
54+
- Starts with a Heroku build image and sets up environment variables and arguments.
55+
- Installs necessary dependencies like `pkg-config`, `ninja-build`, and `yasm`.
56+
- Builds and installs the following libraries in order:
57+
- `libde265`
58+
- `libwebp`
59+
- `libheif` (including AOM as a dependency)
60+
- `ImageMagick`
61+
- For each library, it:
62+
- Downloads the source code from GitHub
63+
- Configures the build
64+
- Compiles the library
65+
- Installs it to `/usr/local`
66+
- Cleans up unnecessary files and strips the shared libraries.
67+
- Depending of the stack version, creates a tarball of the built binaries, libraries, and other necessary files.
68+
- Updates the `ldconfig` cache to ensure the new shared libraries are recognized.
69+
- Saves the ImageMagick configuration for reference.
4970

50-
- https://medium.com/@eplt/5-minutes-to-install-imagemagick-with-heic-support-on-ubuntu-18-04-digitalocean-fe2d09dcef1
51-
- https://github.com/brandoncc/heroku-buildpack-vips
52-
- https://github.com/steeple-dev/heroku-buildpack-imagemagick
53-
- https://github.com/retailzipline/heroku-buildpack-imagemagick-heif
71+
The result is a Docker image with updated versions of ImageMagick and its dependencies, with shared libraries (.so files) built and included in a tarball.
5472

55-
## Knowledge Base
73+
## Bugs
5674

57-
https://devcenter.heroku.com/articles/heroku-24-stack#upgrade-notes
75+
Please report all bugs to the issue tracker: https://github.com/yespark/heroku-imagemagick-buildpack/issues
5876

5977
## License
6078

61-
The gem is available as open source under the terms of the [MIT License](https://github.com/yespark/heroku-imagemagick-buildpack/blob/master/LICENSE).
79+
This buildpack is available as open source under the terms of the [MIT License](https://github.com/yespark/heroku-imagemagick-buildpack/blob/master/LICENSE).

bin/compile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
# bin/compile <build-dir> <cache-dir> <env-dir>
44

5-
# fail hard
6-
set -o pipefail
7-
8-
# fail harder
9-
set -eu
10-
11-
# move hidden files too, just in case
12-
shopt -s dotglob
5+
# Fail hard and fast
6+
set -euo pipefail
137

148
BUILD_DIR=$1
159
CACHE_DIR=$2

bin/test

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
# bin/test <build-dir> <env-dir>
44
# env vars are passed in already, so we can ignore the dir
55

6-
# fail hard
7-
set -o pipefail
8-
9-
# fail harder
10-
set -eu
6+
# Fail hard and fast
7+
set -euo pipefail
118

129
# Setup Path variables, for later use in the Buildpack.
1310
BIN_DIR=$(cd "$(dirname "$0")"; pwd)

build.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
#!/usr/bin/env bash
22

3-
# fail hard
4-
set -o pipefail
3+
# Fail hard and fast
4+
set -euo pipefail
55

6-
# fail harder
7-
set -eu
8-
9-
# move hidden files too, just in case
10-
shopt -s dotglob
11-
12-
# Remove existing builds so that unsupported stacks are automatically removed
13-
rm -rf ./build/*.tar.bz2
14-
15-
# Remove configuration logs so that unsupported stacks are automatically removed
6+
# Remove existing builds and configuration logs so that unsupported stacks are automatically removed
7+
rm -rf ./build/*.tar.bz2 ./build/configurations/*.log 2> /dev/null || true
168
mkdir -p ./build/configurations
17-
rm -rf ./build/configurations/*.log
189

1910
# Stacks
2011
STACK_VERSIONS=(24)
@@ -27,6 +18,7 @@ for stack_version in "${STACK_VERSIONS[@]}"; do
2718
--platform linux/amd64 \
2819
--build-arg STACK_VERSION=${stack_version} \
2920
--tag $image_name \
21+
--progress=plain \
3022
--pull \
3123
--file container/Dockerfile \
3224
container

build/configurations/heroku-24.config.log

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ Path: /usr/local/lib/ImageMagick-7.1.1//config-Q16HDRI/configure.xml
55
Name Value
66
-------------------------------------------------------------------------------
77
CC gcc
8-
CFLAGS -I/usr/include/libxml2 -I/usr/local/include -I/usr/local/include/webp -I/usr/local/include -I/usr/local/include/webp -I/usr/local/include -I/usr/local/include/webp -I/usr/include/libpng16 -I/usr/include/OpenEXR -pthread -I/usr/include/Imath -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/openjpeg-2.5 -I/usr/local/include -I/usr/local/include/webp -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -pthread -fopenmp -Wall -g -O2 -mtune=westmere -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32
8+
CFLAGS -I/usr/include/libxml2 -I/usr/local/include -I/usr/local/include/webp -I/usr/local/include -I/usr/local/include/webp -I/usr/include/libpng16 -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/openjpeg-2.5 -I/usr/local/include -I/usr/local/include/webp -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -pthread -fopenmp -Wall -g -O2 -mtune=westmere -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32
99
CHANNEL_MASK_DEPTH 32
1010
CODER_PATH /usr/local/lib/ImageMagick-7.1.1/modules-Q16HDRI/coders
11-
CONFIGURE ./configure '--prefix=/usr/local' '--disable-docs' '--disable-static' '--without-gvc' 'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig'
11+
CONFIGURE ./configure '--prefix=/usr/local' '--enable-shared=yes' '--disable-docs' '--disable-static' '--without-gvc' '--without-openexr' '--without-tiff' 'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig'
1212
CONFIGURE_PATH /usr/local/etc/ImageMagick-7/
1313
COPYRIGHT Copyright (C) 1999 ImageMagick Studio LLC
1414
CPPFLAGS -I/usr/local/include/ImageMagick-7
1515
CXX g++
1616
CXXFLAGS -g -O2 -pthread
1717
DEFS -DHAVE_CONFIG_H
18-
DELEGATES bzlib djvu fontconfig freetype heic jbig jng jp2 jpeg lcms lqr lzma openexr png tiff webp x xml zip zlib zstd
19-
DISTCHECK_CONFIG_FLAGS --disable-deprecated --with-quantum-depth=16 --with-jemalloc=no --with-umem=no --with-autotrace=no --with-dps=no --with-fftw=no --with-flif=no --with-fpx=no --with-gslib=no --with-fontpath= --with-gvc=no --with-rsvg=no --with-uhdr=no --with-wmf=no --with-perl=no
18+
DELEGATES bzlib djvu fontconfig freetype heic jbig jng jp2 jpeg lcms lqr lzma png webp x xml zip zlib zstd
19+
DISTCHECK_CONFIG_FLAGS --disable-deprecated --with-quantum-depth=16 --with-jemalloc=no --with-umem=no --with-autotrace=no --with-dps=no --with-fftw=no --with-flif=no --with-fpx=no --with-gslib=no --with-fontpath= --with-gvc=no --with-openexr=no --with-rsvg=no --with-tiff=no --with-uhdr=no --with-wmf=no --with-perl=no
2020
DOCUMENTATION_PATH /usr/local/share/doc/ImageMagick-7
2121
EXEC-PREFIX /usr/local
2222
EXECUTABLE_PATH /usr/local/bin
@@ -29,7 +29,7 @@ LDFLAGS -L/usr/local/lib
2929
LIB_VERSION 0x711
3030
LIB_VERSION_NUMBER 7,1,1,35
3131
LIBRARY_PATH /usr/local/lib/ImageMagick-7.1.1
32-
LIBS -ljbig -llcms2 -L/usr/local/lib -ltiff -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lpng16 -ldjvulibre -lfontconfig -lfreetype -L/usr/local/lib -lheif -L/usr/local/lib -lwebpmux -lwebpdemux -L/usr/local/lib -lwebp -lXext -lXt -lSM -lICE -lX11 -llzma -lbz2 -lOpenEXR-3_1 -lOpenEXRUtil-3_1 -lOpenEXRCore-3_1 -lIex-3_1 -lIlmThread-3_1 -lImath-3_1 -lopenjp2 -lxml2 -lz -lzip -lm -lpthread -lgomp
32+
LIBS -ljbig -llcms2 -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lpng16 -ldjvulibre -lfontconfig -lfreetype -L/usr/local/lib -lheif -L/usr/local/lib -lwebpmux -lwebpdemux -L/usr/local/lib -lwebp -lXext -lXt -lSM -lICE -lX11 -llzma -lbz2 -lopenjp2 -lxml2 -lz -lzip -lm -lpthread -lgomp
3333
NAME ImageMagick
3434
PCFLAGS -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32
3535
PREFIX /usr/local
@@ -48,7 +48,7 @@ Path: [built-in]
4848

4949
Name Value
5050
-------------------------------------------------------------------------------
51-
DELEGATES bzlib djvu fontconfig freetype heic jbig jng jp2 jpeg lcms lqr lzma openexr png tiff webp x xml zip zlib zstd
51+
DELEGATES bzlib djvu fontconfig freetype heic jbig jng jp2 jpeg lcms lqr lzma png webp x xml zip zlib zstd
5252
FEATURES Cipher DPC HDRI OpenMP(4.5)
5353
MAGICK_TEMPORARY_PATH /tmp
5454
NAME ImageMagick

build/heroku-24.tar.bz2

-497 KB
Binary file not shown.

check.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

4-
COMPILE_VERSION_LIBTIFF=$(cat container/Dockerfile | egrep -o 'COMPILE_VERSION_LIBTIFF=([0-9.-]+)' | cut -f 2 -d =)
54
COMPILE_VERSION_LIBDE265=$(cat container/Dockerfile | egrep -o 'COMPILE_VERSION_LIBDE265=([0-9.-]+)' | cut -f 2 -d =)
65
COMPILE_VERSION_LIBWEBP=$(cat container/Dockerfile | egrep -o 'COMPILE_VERSION_LIBWEBP=([0-9.-]+)' | cut -f 2 -d =)
76
COMPILE_VERSION_LIBHEIF=$(cat container/Dockerfile | egrep -o 'COMPILE_VERSION_LIBHEIF=([0-9.-]+)' | cut -f 2 -d =)
87
COMPILE_VERSION_IMAGEMAGICK=$(cat container/Dockerfile | egrep -o 'COMPILE_VERSION_IMAGEMAGICK=([0-9.-]+)' | cut -f 2 -d =)
98

10-
LATEST_VERSION_LIBTIFF=$(curl --retry-connrefused --retry 3 --silent "https://api.github.com/repos/libsdl-org/libtiff/tags" | jq -r '.[0].name' | sed 's/v//')
11-
LATEST_VERSION_LIBDE265=$(curl --retry-connrefused --retry 3 --silent "https://api.github.com/repos/strukturag/libde265/releases/latest" | jq -r .tag_name | sed 's/v//')
12-
LATEST_VERSION_LIBWEBP=$(curl --retry-connrefused --retry 3 --silent "https://api.github.com/repos/webmproject/libwebp/tags" | jq -r '.[0].name' | sed 's/v//')
13-
LATEST_VERSION_LIBHEIF=$(curl --retry-connrefused --retry 3 --silent "https://api.github.com/repos/strukturag/libheif/releases/latest" | jq -r .tag_name | sed 's/v//')
14-
LATEST_VERSION_IMAGEMAGICK=$(curl --retry-connrefused --retry 3 --silent "https://api.github.com/repos/ImageMagick/ImageMagick/releases/latest" | jq -r .tag_name | sed 's/v//')
15-
16-
if [ "$COMPILE_VERSION_LIBTIFF" != "$LATEST_VERSION_LIBTIFF" ]; then
17-
echo -e "COMPILE_VERSION_LIBTIFF ($COMPILE_VERSION_LIBTIFF)\nNew version available: $LATEST_VERSION_LIBTIFF"
18-
fi
9+
LATEST_VERSION_LIBDE265=$(curl --retry-connrefused --retry 3 -ksSL "https://api.github.com/repos/strukturag/libde265/releases/latest" | jq -r .tag_name | sed 's/v//')
10+
LATEST_VERSION_LIBWEBP=$(curl --retry-connrefused --retry 3 -ksSL "https://api.github.com/repos/webmproject/libwebp/tags" | jq -r '.[0].name' | sed 's/v//')
11+
LATEST_VERSION_LIBHEIF=$(curl --retry-connrefused --retry 3 -ksSL "https://api.github.com/repos/strukturag/libheif/releases/latest" | jq -r .tag_name | sed 's/v//')
12+
LATEST_VERSION_IMAGEMAGICK=$(curl --retry-connrefused --retry 3 -ksSL "https://api.github.com/repos/ImageMagick/ImageMagick/releases/latest" | jq -r .tag_name | sed 's/v//')
1913

2014
if [ "$COMPILE_VERSION_LIBDE265" != "$LATEST_VERSION_LIBDE265" ]; then
2115
echo -e "COMPILE_VERSION_LIBDE265 ($COMPILE_VERSION_LIBDE265)\nNew version available: $LATEST_VERSION_LIBDE265"

0 commit comments

Comments
 (0)