Skip to content

Commit

Permalink
Add example/docker (refs #173) (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx authored Sep 25, 2018
1 parent 4114284 commit 1ba2b4a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ gopkg.in/gographics/imagick.v1/imagick

# Install

## Docker

See [examples/docker](examples/docker)

## Mac OS X

### MacPorts
Expand Down
33 changes: 33 additions & 0 deletions examples/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM golang:1.11

# Ignore APT warnings about not having a TTY
ENV DEBIAN_FRONTEND noninteractive

# install build essentials
RUN apt-get update && \
apt-get install -y wget build-essential pkg-config --no-install-recommends

# Install ImageMagick deps
RUN apt-get -q -y install libjpeg-dev libpng-dev libtiff-dev \
libgif-dev libx11-dev --no-install-recommends

ENV IMAGEMAGICK_VERSION=6.9.10-11

RUN cd && \
wget https://github.com/ImageMagick/ImageMagick6/archive/${IMAGEMAGICK_VERSION}.tar.gz && \
tar xvzf ${IMAGEMAGICK_VERSION}.tar.gz && \
cd ImageMagick* && \
./configure \
--without-magick-plus-plus \
--without-perl \
--disable-openmp \
--with-gvc=no \
--disable-docs && \
make -j$(nproc) && make install && \
ldconfig /usr/local/lib

WORKDIR /go/projects/resizer
COPY . .

RUN go install
CMD /go/bin/resizer
4 changes: 4 additions & 0 deletions examples/docker/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module resizer

require gopkg.in/gographics/imagick.v2 v2.5.0

50 changes: 50 additions & 0 deletions examples/docker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Port of http://members.shaw.ca/el.supremo/MagickWand/resize.htm to Go
package main

import (
"fmt"

"gopkg.in/gographics/imagick.v2/imagick"
)

func main() {
imagick.Initialize()
// Schedule cleanup
defer imagick.Terminate()
var err error

mw := imagick.NewMagickWand()

err = mw.ReadImage("logo:")
if err != nil {
panic(err)
}

// Get original logo size
width := mw.GetImageWidth()
height := mw.GetImageHeight()

// Calculate half the size
hWidth := uint(width / 2)
hHeight := uint(height / 2)

// Resize the image using the Lanczos filter
// The blur factor is a float, where > 1 is blurry, < 1 is sharp
err = mw.ResizeImage(hWidth, hHeight, imagick.FILTER_LANCZOS, 1)
if err != nil {
panic(err)
}

// Set the compression quality to 95 (high quality = low compression)
err = mw.SetImageCompressionQuality(95)
if err != nil {
panic(err)
}

out := "/tmp/out.png"
if err = mw.WriteImage(out); err != nil {
panic(err)
}

fmt.Printf("Wrote: %s\n", out)
}

0 comments on commit 1ba2b4a

Please sign in to comment.