-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |