Skip to content

Instantly share code, notes, and snippets.

@spvkgn
Forked from SoftCreatR/README.md
Last active August 17, 2020 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spvkgn/fd6a202d67e618c93432554f3d7595e6 to your computer and use it in GitHub Desktop.
Save spvkgn/fd6a202d67e618c93432554f3d7595e6 to your computer and use it in GitHub Desktop.
ImageMagick® 7 for Debian/Ubuntu
#!/bin/sh
##############################################################
# Title : build-imagemagick7.sh #
# Description : ImageMagick® 7 for Debian/Ubuntu, #
# including (nearly) full delegate support. #
##############################################################
# Make sure, that we are on Debian or Ubuntu
if ! lsb_release -d | grep -qE 'Ubuntu|Debian'; then
echo "This script cannot run on any other system than Debian or Ubuntu!"
exit 1
fi
# Create temp and build directories as workspace
WORK_DIR=$(mktemp -d)
BUILD_DIR=$WORK_DIR/build
mkdir -p "$BUILD_DIR"
# check if these directories were created
if [ ! "$WORK_DIR" ] || [ ! -d "$WORK_DIR" ]; then
echo "Could not create temp directory $WORK_DIR"
exit 1
fi
if [ ! "$BUILD_DIR" ] || [ ! -d "$BUILD_DIR" ]; then
echo "Could not create build directory $BUILD_DIR"
exit 1
fi
# deletes the temp directory
cleanup() {
rm -rf "$WORK_DIR"
}
# call cleanup function
trap cleanup INT TERM
trap cleanup EXIT
# Install required packages
PKG_LIST="autoconf automake libtool-bin pkg-config gcc git pkg-config wget \
libltdl-dev libfftw3-dev liblcms2-dev liblqr-1-0-dev \
fonts-dejavu-extra libfreetype6-dev libfontconfig1-dev gsfonts ghostscript \
zlib1g-dev liblzma-dev libbz2-dev \
libx11-dev libxext-dev libxt-dev \
libjemalloc-dev libgoogle-perftools-dev \
libdjvulibre-dev libexif-dev libgd-dev libgraphviz-dev libjpeg-dev libopenjp2-7-dev libopenexr-dev libpng-dev \
libraw-dev libtiff-dev libwmf-dev libwebp-dev libpango1.0-dev librsvg2-bin librsvg2-dev libxml2-dev"
case $(lsb_release -d | cut -f2 | cut -f1 -d" ") in
Debian)
case $(lsb_release -c | cut -f2) in
jessie) PKG_LIST="$PKG_LIST libfribidi-dev" ;;
stretch) PKG_LIST="$PKG_LIST libfribidi-dev libzstd-dev" ;;
buster) PKG_LIST="$PKG_LIST libfribidi-dev libzstd-dev libraqm-dev" ;;
esac ;;
Ubuntu)
case $(lsb_release -c | cut -f2) in
xenial) PKG_LIST="$PKG_LIST libfribidi-dev libzstd-dev" ;;
bionic|focal) PKG_LIST="$PKG_LIST libfribidi-dev libzstd-dev libraqm-dev" ;;
esac ;;
*)
echo "Unsupported OS."
exit 1 ;;
esac
#######################
# Installer functions #
#######################
ORIGIN_DIR=$(pwd)
# libheif
build_libheif() {
cd "$WORK_DIR" && \
VER=$(wget -qO- https://api.github.com/repos/strukturag/libheif/releases/latest | grep -Po '"tag_name": "\K.*?(?=")' | sed 's/v//') && \
[ -n $VER ] && wget -qc --show-progress https://github.com/strukturag/libheif/releases/download/v$VER/libheif-$VER.tar.gz && \
tar -xf libheif-$VER.tar.gz && \
cd libheif-$VER && \
./configure --prefix="$BUILD_DIR" --disable-shared --disable-dependency-tracking --disable-examples && \
make -j$(nproc) install
}
# libfpx
build_libfpx() {
cd "$WORK_DIR" && \
wget -qc --show-progress https://imagemagick.org/download/delegates/libfpx-1.3.1-10.tar.xz && \
tar -xf libfpx-*.tar.* && \
cd "$(tar -tf libfpx-*.tar.* | head -1)" && \
./configure --prefix="$BUILD_DIR" --disable-shared --disable-dependency-tracking && \
make -j$(nproc) install
}
# libraqm
build_libraqm() {
cd "$WORK_DIR" && \
VER=$(wget -qO- https://api.github.com/repos/HOST-Oman/libraqm/releases/latest | grep -Po '"tag_name": "\K.*?(?=")' | sed 's/v//') && \
[ -n $VER ] && wget -qc --show-progress https://github.com/HOST-Oman/libraqm/releases/download/v$VER/raqm-$VER.tar.gz && \
tar -xf raqm-$VER.tar.gz && \
cd raqm-$VER && \
./configure --prefix="$BUILD_DIR" --disable-shared --disable-dependency-tracking && \
make -j$(nproc) install
}
# ImageMagick
build_imagemagick() {
cd "$WORK_DIR" && \
wget -qc --show-progress https://imagemagick.org/download/ImageMagick.tar.gz && \
tar -xf ImageMagick.tar.gz && \
cd "$(tar -tf ImageMagick.tar.gz | head -1)" && \
wget -qO- "https://aur.archlinux.org/cgit/aur.git/plain/imagemagick-inkscape-1.0.patch?h=imagemagick-full" | patch -Np1 -i - && \
CFLAGS="-O3 -march=native" CXXFLAGS="-O3 -march=native" \
CPPFLAGS=-I$BUILD_DIR/include LDFLAGS=-L$BUILD_DIR/lib PKG_CONFIG_PATH=$BUILD_DIR/lib/pkgconfig \
./configure \
--prefix="$BUILD_DIR" \
--disable-shared \
--disable-dependency-tracking \
--disable-docs \
--enable-openmp \
--enable-opencl \
--enable-cipher \
--enable-hdri \
--with-threads \
--with-modules \
--with-jemalloc \
--with-tcmalloc \
--with-umem \
--with-bzlib \
--with-x \
--with-zlib \
--with-zstd \
--with-autotrace \
--without-dps \
--with-fftw \
--with-fpx \
--with-djvu \
--with-fontconfig \
--with-freetype \
--with-raqm \
--without-gslib \
--with-gvc \
--with-heic \
--with-jbig \
--with-jpeg \
--with-lcms \
--with-openjp2 \
--with-lqr \
--with-lzma \
--with-openexr \
--with-pango \
--with-png \
--with-raw \
--with-rsvg \
--with-tiff \
--with-webp \
--with-wmf \
--with-xml \
--with-fontpath=/usr/share/fonts/truetype \
--with-dejavu-font-dir=/usr/share/fonts/truetype/ttf-dejavu \
--with-gs-font-dir=/usr/share/fonts/type1/gsfonts && \
make -j$(nproc) install
}
######################
# Install everything #
######################
case $(lsb_release -c | cut -f2) in
jessie|stretch|xenial) apt-get install -y $PKG_LIST && build_libheif && build_libfpx && build_libraqm ;;
buster|bionic) apt-get install -y $PKG_LIST && build_libheif && build_libfpx ;;
focal) apt-get install -y $PKG_LIST && build_libfpx ;;
esac
# Finally, build ImageMagick
build_imagemagick
##########
# Finish #
##########
# Get magick binary
if [ -x $BUILD_DIR/bin/magick ]; then
cp $BUILD_DIR/bin/magick $ORIGIN_DIR && \
strip $ORIGIN_DIR/magick
echo "\n\nBuild successful:\n"
$ORIGIN_DIR/magick -version
echo "\n"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment