Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gojko committed May 16, 2019
1 parent f0832a8 commit 18127a7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 32 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ImageMagick for AWS Lambda (Amazon Linux 2)

Scripts to compile ImageMagick utilities for AWS Lambda instances powered by Amazon Linux 2.x, such as the `nodejs10.x` runtime.

Amazon Linux 2 instances for Lambda no longer contain system utilities, so `convert`, `mogrify` and `identify` from the [ImageMagick](https://imagemagick.org) package are no longer available.

## Prerequisites

* Docker desktop
* Unix Make environment

## Compiling the code

* `make all`

The `Makefile` in the root directory just starts a Docker container matching the AWS Linux 2 environment for Lambda runtimes, and compiles a static version of ImageMagick tools. They will be in the `result` dir. By default, this compiles a version expecting to run as a Lambda layer from `/opt/imagemagick` (you can change the expected location in the (`Makefile`)[Makefile].

## Bundled libraries

This is not a full-blown ImageMagick setup you can expect on a regular Linux box, it's a slimmed down version to save space that works with the most common formats. You can add more formats by including another library into the build process in [`src/Makefile`](src/Makefile).
* libpng
* libtiff
* libjpeg
* openjpeg2

## Info on scripts

For more information, check out:

* https://imagemagick.org/script/install-source.php
* http://www.linuxfromscratch.org/blfs/view/cvs/general/imagemagick.html

## Author

Gojko Adzic <https://gojko.net>

## License

* These scripts: [MIT](https://opensource.org/licenses/MIT)
* ImageMagick: https://imagemagick.org/script/license.php
* Contained libraries all have separate licenses, check the respective web sites for more information
64 changes: 32 additions & 32 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

PNG_SOURCE=libpng-1.6.37.tar.xz
JPG_SOURCE=jpegsrc.v9c.tar.gz
LIBPNG_SOURCE=libpng-1.6.37.tar.xz
LIBJPG_SOURCE=jpegsrc.v9c.tar.gz
OPENJP2_VERSION=2.3.1
OPENJP2_SOURCE=openjp2-$(OPENJP2_VERSION)
LIBTIFF_SOURCE=tiff-4.0.9.tar.gz
IMAGE_MAGICK_SOURCE=ImageMagick.tar.gz
TARGET_DIR ?= /opt/imagemagick

Expand All @@ -11,62 +12,61 @@ TARGET_DIR ?= /opt/imagemagick
$(IMAGE_MAGICK_SOURCE):
curl -LO https://imagemagick.org/download/$(IMAGE_MAGICK_SOURCE)

$(JPG_SOURCE):
curl -LO http://ijg.org/files/$(JPG_SOURCE)
$(LIBJPG_SOURCE):
curl -LO http://ijg.org/files/$(LIBJPG_SOURCE)

$(PNG_SOURCE):
curl -LO http://prdownloads.sourceforge.net/libpng/$(PNG_SOURCE)
$(LIBPNG_SOURCE):
curl -LO http://prdownloads.sourceforge.net/libpng/$(LIBPNG_SOURCE)

$(OPENJP2_SOURCE):
curl -L https://github.com/uclouvain/openjpeg/archive/v$(OPENJP2_VERSION).tar.gz -o $(OPENJP2_SOURCE)

$(TARGET_DIR)/lib/libpng.a: $(PNG_SOURCE)
tar xf $(PNG_SOURCE) &&
$(LIBTIFF_SOURCE):
curl -LO http://download.osgeo.org/libtiff/$(LIBTIFF_SOURCE)

CONFIGURE = PKG_CONFIG_PATH=$(TARGET_DIR)/lib/pkgconfig ./configure CPPFLAGS=-I$(TARGET_DIR)/include LDFLAGS=-L$(TARGET_DIR)/lib --disable-dependency-tracking --disable-shared --enable-static --prefix=$(TARGET_DIR)

$(TARGET_DIR)/lib/libpng.a: $(LIBPNG_SOURCE)
tar xf $(LIBPNG_SOURCE) &&
cd libpng*
./configure \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=$(TARGET_DIR)
$(CONFIGURE)
make
make install

$(TARGET_DIR)/lib/libjpeg.a: $(JPG_SOURCE)
tar xf $(JPG_SOURCE)
$(TARGET_DIR)/lib/libjpeg.a: $(LIBJPG_SOURCE)
tar xf $(LIBJPG_SOURCE)
cd jpeg*
./configure \
--disable-dependency-tracking \
--disable-shared \
--enable-static \
--prefix=$(TARGET_DIR)
$(CONFIGURE)
make
make install

$(TARGET_DIR)/lib/libtiff.a: $(LIBTIFF_SOURCE) $(TARGET_DIR)/lib/libjpeg.a
tar xf $(LIBTIFF_SOURCE) &&
cd tiff-*
$(CONFIGURE)
make
make install

$(TARGET_DIR)/lib/libopenjp2.a: $(OPENJP2_SOURCE) $(TARGET_DIR)/lib/libpng.a
$(TARGET_DIR)/lib/libopenjp2.a: $(OPENJP2_SOURCE) $(TARGET_DIR)/lib/libpng.a $(TARGET_DIR)/lib/libtiff.a
tar xf $(OPENJP2_SOURCE) &&
cd openjpeg-*
mkdir -p build
cd build
cmake .. \
PKG_CONFIG_PATH=$(TARGET_DIR)/lib/pkgconfig cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$(TARGET_DIR) \
-DBUILD_SHARED_LIBS:bool=off
make
-DBUILD_SHARED_LIBS:bool=off \
-DBUILD_CODEC:bool=off
make clean
make install

LIBS:=$(TARGET_DIR)/lib/libjpeg.a $(TARGET_DIR)/lib/libpng.a $(TARGET_DIR)/lib/libopenjp2.a
LIBS:=$(TARGET_DIR)/lib/libjpeg.a $(TARGET_DIR)/lib/libpng.a $(TARGET_DIR)/lib/libopenjp2.a $(TARGET_DIR)/lib/libtiff.a

$(TARGET_DIR)/bin/identify: $(LIBS) $(IMAGE_MAGICK_SOURCE)
tar xf $(IMAGE_MAGICK_SOURCE)
cd ImageMa*
PKG_CONFIG_PATH=$(TARGET_DIR)/lib/pkgconfig ./configure \
CPPFLAGS=-I$(TARGET_DIR)/include \
LDFLAGS=-L$(TARGET_DIR)/lib \
--prefix=$(TARGET_DIR) \
--disable-dependency-tracking \
$(CONFIGURE) \
--enable-delegate-build \
--disable-shared \
--enable-static \
--without-modules \
--disable-docs \
--without-magick-plus-plus \
Expand Down

0 comments on commit 18127a7

Please sign in to comment.