--- /dev/null
+Copyright (c) 2013, Herbert G. Fischer
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the organization nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL HERBERT G. FISCHER BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
--- /dev/null
+# Go Imagick
+
+Go Imagick is a Go bind to ImageMagick's MagickWand C API.
+
+This is a very stripped down version of
+https://github.com/gographics/imagick intended to build easily on RHEL6.
+Ideally this will be removed in the future if imagick is easier to deploy.
+
+# Install
+
+## Mac OS X
+
+### MacPorts
+
+```
+sudo port install ImageMagick
+```
+
+## Ubuntu / Debian
+
+```
+sudo apt-get install libmagickwand-dev
+```
+
+## Common
+
+Check if pkg-config is able to find the right ImageMagick include and libs:
+
+```
+pkg-config --cflags --libs MagickWand
+```
+
+# License
+
+Copyright (c) 2013, Herbert G. Fischer
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the organization nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL HERBERT G. FISCHER BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+type AlphaChannelType int
+
+const (
+ ALPHA_CHANNEL_UNDEFINED AlphaChannelType = C.UndefinedAlphaChannel
+ ALPHA_CHANNEL_ACTIVATE AlphaChannelType = C.ActivateAlphaChannel
+ ALPHA_CHANNEL_BACKGROUND AlphaChannelType = C.BackgroundAlphaChannel
+ ALPHA_CHANNEL_COPY AlphaChannelType = C.CopyAlphaChannel
+ ALPHA_CHANNEL_DEACTIVATE AlphaChannelType = C.DeactivateAlphaChannel
+ ALPHA_CHANNEL_EXTRACT AlphaChannelType = C.ExtractAlphaChannel
+ ALPHA_CHANNEL_OPAQUE AlphaChannelType = C.OpaqueAlphaChannel
+ ALPHA_CHANNEL_RESET AlphaChannelType = C.ResetAlphaChannel
+ ALPHA_CHANNEL_SET AlphaChannelType = C.SetAlphaChannel
+ ALPHA_CHANNEL_SHAPE AlphaChannelType = C.ShapeAlphaChannel
+ ALPHA_CHANNEL_TRANSPARENT AlphaChannelType = C.TransparentAlphaChannel
+)
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+type CompressionType int
+
+const (
+ COMPRESSION_UNDEFINED CompressionType = C.UndefinedCompression
+ COMPRESSION_NO CompressionType = C.NoCompression
+ COMPRESSION_BZIP CompressionType = C.BZipCompression
+ COMPRESSION_DXT1 CompressionType = C.DXT1Compression
+ COMPRESSION_DXT3 CompressionType = C.DXT3Compression
+ COMPRESSION_DXT5 CompressionType = C.DXT5Compression
+ COMPRESSION_FAX CompressionType = C.FaxCompression
+ COMPRESSION_GROUP4 CompressionType = C.Group4Compression
+ COMPRESSION_JPEG CompressionType = C.JPEGCompression
+ COMPRESSION_JPEG2000 CompressionType = C.JPEG2000Compression
+ COMPRESSION_LOSSLESS_JPEG CompressionType = C.LosslessJPEGCompression
+ COMPRESSION_LZW CompressionType = C.LZWCompression
+ COMPRESSION_RLE CompressionType = C.RLECompression
+ COMPRESSION_ZIP CompressionType = C.ZipCompression
+)
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+import "unsafe"
+
+// Convert a boolean to a integer
+func b2i(boolean bool) C.MagickBooleanType {
+ if boolean {
+ return C.MagickBooleanType(1)
+ }
+ return C.MagickBooleanType(0)
+}
+
+func cStringArrayToStringSlice(p **C.char) []string {
+ var strings []string
+ q := uintptr(unsafe.Pointer(p))
+ for {
+ p = (**C.char)(unsafe.Pointer(q))
+ if *p == nil {
+ break
+ }
+ defer C.free(unsafe.Pointer(*p))
+ strings = append(strings, C.GoString(*p))
+ q += unsafe.Sizeof(q)
+ }
+ return strings
+}
+
+func sizedCStringArrayToStringSlice(p **C.char, num C.ulong) []string {
+ var strings []string
+ q := uintptr(unsafe.Pointer(p))
+ for i := 0; i < int(num); i++ {
+ p = (**C.char)(unsafe.Pointer(q))
+ if *p == nil {
+ break
+ }
+ defer C.free(unsafe.Pointer(*p))
+ strings = append(strings, C.GoString(*p))
+ q += unsafe.Sizeof(q)
+ }
+ return strings
+}
+
+func sizedDoubleArrayToFloat64Slice(p *C.double, num C.size_t) []float64 {
+ var nums []float64
+ q := uintptr(unsafe.Pointer(p))
+ for i := 0; i < int(num); i++ {
+ p = (*C.double)(unsafe.Pointer(q))
+ nums = append(nums, float64(*p))
+ q += unsafe.Sizeof(q)
+ }
+ return nums
+}
+
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+import (
+ "fmt"
+)
+
+type ExceptionType int
+
+const (
+ EXCEPTION_UNDEFINED ExceptionType = C.UndefinedException
+ EXCEPTION_WARNING ExceptionType = C.WarningException
+ WARNING_RESOURCE_LIMIT ExceptionType = C.ResourceLimitWarning
+ WARNING_TYPE ExceptionType = C.TypeWarning
+ WARNING_OPTION ExceptionType = C.OptionWarning
+ WARNING_DELEGATE ExceptionType = C.DelegateWarning
+ WARNING_MISSING_DELEGATE ExceptionType = C.MissingDelegateWarning
+ WARNING_CORRUPT_IMAGE ExceptionType = C.CorruptImageWarning
+ WARNING_FILE_OPEN ExceptionType = C.FileOpenWarning
+ WARNING_BLOB ExceptionType = C.BlobWarning
+ WARNING_STREAM ExceptionType = C.StreamWarning
+ WARNING_CACHE ExceptionType = C.CacheWarning
+ WARNING_CODER ExceptionType = C.CoderWarning
+ WARNING_MODULE ExceptionType = C.ModuleWarning
+ WARNING_DRAW ExceptionType = C.DrawWarning
+ WARNING_IMAGE ExceptionType = C.ImageWarning
+ WARNING_WAND ExceptionType = C.WandWarning
+ WARNING_RANDOM ExceptionType = C.RandomWarning
+ WARNING_XSERVER ExceptionType = C.XServerWarning
+ WARNING_MONITOR ExceptionType = C.MonitorWarning
+ WARNING_REGISTRY ExceptionType = C.RegistryWarning
+ WARNING_CONFIGURE ExceptionType = C.ConfigureWarning
+ WARNING_POLICY ExceptionType = C.PolicyWarning
+ EXCEPTION_ERROR ExceptionType = C.ErrorException
+ ERROR_RESOURCE_LIMIT ExceptionType = C.ResourceLimitError
+ ERROR_TYPE ExceptionType = C.TypeError
+ ERROR_OPTION ExceptionType = C.OptionError
+ ERROR_DELEGATE ExceptionType = C.DelegateError
+ ERROR_MISSING_DELEGATE ExceptionType = C.MissingDelegateError
+ ERROR_CORRUPT_IMAGE ExceptionType = C.CorruptImageError
+ ERROR_FILE_OPEN ExceptionType = C.FileOpenError
+ ERROR_BLOB ExceptionType = C.BlobError
+ ERROR_STREAM ExceptionType = C.StreamError
+ ERROR_CACHE ExceptionType = C.CacheError
+ ERROR_CODER ExceptionType = C.CoderError
+ ERROR_MODULE ExceptionType = C.ModuleError
+ ERROR_DRAW ExceptionType = C.DrawError
+ ERROR_IMAGE ExceptionType = C.ImageError
+ ERROR_WAND ExceptionType = C.WandError
+ ERROR_RANDOM ExceptionType = C.RandomError
+ ERROR_XSERVER ExceptionType = C.XServerError
+ ERROR_MONITOR ExceptionType = C.MonitorError
+ ERROR_REGISTRY ExceptionType = C.RegistryError
+ ERROR_CONFIGURE ExceptionType = C.ConfigureError
+ ERROR_POLICY ExceptionType = C.PolicyError
+ EXCEPTION_FATAL_ERROR ExceptionType = C.FatalErrorException
+ FATAL_ERROR_RESOURCE_LIMIT ExceptionType = C.ResourceLimitFatalError
+ FATAL_ERROR_TYPE ExceptionType = C.TypeFatalError
+ FATAL_ERROR_OPTION ExceptionType = C.OptionFatalError
+ FATAL_ERROR_DELEGATE ExceptionType = C.DelegateFatalError
+ FATAL_ERROR_MISSING_DELEGATE ExceptionType = C.MissingDelegateFatalError
+ FATAL_ERROR_CORRUPT_IMAGE ExceptionType = C.CorruptImageFatalError
+ FATAL_ERROR_FILE_OPEN ExceptionType = C.FileOpenFatalError
+ FATAL_ERROR_BLOB ExceptionType = C.BlobFatalError
+ FATAL_ERROR_STREAM ExceptionType = C.StreamFatalError
+ FATAL_ERROR_CACHE ExceptionType = C.CacheFatalError
+ FATAL_ERROR_CODER ExceptionType = C.CoderFatalError
+ FATAL_ERROR_MODULE ExceptionType = C.ModuleFatalError
+ FATAL_ERROR_DRAW ExceptionType = C.DrawFatalError
+ FATAL_ERROR_IMAGE ExceptionType = C.ImageFatalError
+ FATAL_ERROR_WAND ExceptionType = C.WandFatalError
+ FATAL_ERROR_RANDOM ExceptionType = C.RandomFatalError
+ FATAL_ERROR_XSERVER ExceptionType = C.XServerFatalError
+ FATAL_ERROR_MONITOR ExceptionType = C.MonitorFatalError
+ FATAL_ERROR_REGISTRY ExceptionType = C.RegistryFatalError
+ FATAL_ERROR_CONFIGURE ExceptionType = C.ConfigureFatalError
+ FATAL_ERROR_POLICY ExceptionType = C.PolicyFatalError
+)
+
+var exceptionTypeStrings = map[ExceptionType]string{
+ EXCEPTION_UNDEFINED: "EXCEPTION_UNDEFINED",
+ EXCEPTION_WARNING: "EXCEPTION_WARNING",
+ WARNING_TYPE: "WARNING_TYPE",
+ WARNING_OPTION: "WARNING_OPTION",
+ WARNING_DELEGATE: "WARNING_DELEGATE",
+ WARNING_MISSING_DELEGATE: "WARNING_MISSING_DELEGATE",
+ WARNING_CORRUPT_IMAGE: "WARNING_CORRUPT_IMAGE",
+ WARNING_FILE_OPEN: "WARNING_FILE_OPEN",
+ WARNING_BLOB: "WARNING_BLOB",
+ WARNING_STREAM: "WARNING_STREAM",
+ WARNING_CACHE: "WARNING_CACHE",
+ WARNING_CODER: "WARNING_CODER",
+ WARNING_MODULE: "WARNING_MODULE",
+ WARNING_DRAW: "WARNING_DRAW",
+ WARNING_IMAGE: "WARNING_IMAGE",
+ WARNING_WAND: "WARNING_WAND",
+ WARNING_RANDOM: "WARNING_RANDOM",
+ WARNING_XSERVER: "WARNING_XSERVER",
+ WARNING_MONITOR: "WARNING_MONITOR",
+ WARNING_REGISTRY: "WARNING_REGISTRY",
+ WARNING_CONFIGURE: "WARNING_CONFIGURE",
+ WARNING_POLICY: "WARNING_POLICY",
+ EXCEPTION_ERROR: "EXCEPTION_ERROR",
+ ERROR_TYPE: "ERROR_TYPE",
+ ERROR_OPTION: "ERROR_OPTION",
+ ERROR_DELEGATE: "ERROR_DELEGATE",
+ ERROR_MISSING_DELEGATE: "ERROR_MISSING_DELEGATE",
+ ERROR_CORRUPT_IMAGE: "ERROR_CORRUPT_IMAGE",
+ ERROR_FILE_OPEN: "ERROR_FILE_OPEN",
+ ERROR_BLOB: "ERROR_BLOB",
+ ERROR_STREAM: "ERROR_STREAM",
+ ERROR_CACHE: "ERROR_CACHE",
+ ERROR_CODER: "ERROR_CODER",
+ ERROR_MODULE: "ERROR_MODULE",
+ ERROR_DRAW: "ERROR_DRAW",
+ ERROR_IMAGE: "ERROR_IMAGE",
+ ERROR_WAND: "ERROR_WAND",
+ ERROR_RANDOM: "ERROR_RANDOM",
+ ERROR_XSERVER: "ERROR_XSERVER",
+ ERROR_MONITOR: "ERROR_MONITOR",
+ ERROR_REGISTRY: "ERROR_REGISTRY",
+ ERROR_CONFIGURE: "ERROR_CONFIGURE",
+ ERROR_POLICY: "ERROR_POLICY",
+ EXCEPTION_FATAL_ERROR: "EXCEPTION_FATAL_ERROR",
+ FATAL_ERROR_TYPE: "FATAL_ERROR_TYPE",
+ FATAL_ERROR_OPTION: "FATAL_ERROR_OPTION",
+ FATAL_ERROR_DELEGATE: "FATAL_ERROR_DELEGATE",
+ FATAL_ERROR_MISSING_DELEGATE: "FATAL_ERROR_MISSING_DELEGATE",
+ FATAL_ERROR_CORRUPT_IMAGE: "FATAL_ERROR_CORRUPT_IMAGE",
+ FATAL_ERROR_FILE_OPEN: "FATAL_ERROR_FILE_OPEN",
+ FATAL_ERROR_BLOB: "FATAL_ERROR_BLOB",
+ FATAL_ERROR_STREAM: "FATAL_ERROR_STREAM",
+ FATAL_ERROR_CACHE: "FATAL_ERROR_CACHE",
+ FATAL_ERROR_CODER: "FATAL_ERROR_CODER",
+ FATAL_ERROR_MODULE: "FATAL_ERROR_MODULE",
+ FATAL_ERROR_DRAW: "FATAL_ERROR_DRAW",
+ FATAL_ERROR_IMAGE: "FATAL_ERROR_IMAGE",
+ FATAL_ERROR_WAND: "FATAL_ERROR_WAND",
+ FATAL_ERROR_RANDOM: "FATAL_ERROR_RANDOM",
+ FATAL_ERROR_XSERVER: "FATAL_ERROR_XSERVER",
+ FATAL_ERROR_MONITOR: "FATAL_ERROR_MONITOR",
+ FATAL_ERROR_REGISTRY: "FATAL_ERROR_REGISTRY",
+ FATAL_ERROR_CONFIGURE: "FATAL_ERROR_CONFIGURE",
+ FATAL_ERROR_POLICY: "FATAL_ERROR_POLICY",
+ //WARNING_RESOURCE_LIMIT: "WARNING_RESOURCE_LIMIT",
+ //ERROR_RESOURCE_LIMIT: "ERROR_RESOURCE_LIMIT",
+ //FATAL_ERROR_RESOURCE_LIMIT: "FATAL_ERROR_RESOURCE_LIMIT",
+}
+
+func (et *ExceptionType) String() string {
+ if v, ok := exceptionTypeStrings[ExceptionType(*et)]; ok {
+ return v
+ }
+ return fmt.Sprintf("UnknownError[%d]", *et)
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+type FilterType int
+
+const (
+ FILTER_UNDEFINED FilterType = C.UndefinedFilter
+ FILTER_POINT FilterType = C.PointFilter
+ FILTER_BOX FilterType = C.BoxFilter
+ FILTER_TRIANGLE FilterType = C.TriangleFilter
+ FILTER_HERMITE FilterType = C.HermiteFilter
+ FILTER_HANNING FilterType = C.HanningFilter
+ FILTER_HAMMING FilterType = C.HammingFilter
+ FILTER_BLACKMAN FilterType = C.BlackmanFilter
+ FILTER_GAUSSIAN FilterType = C.GaussianFilter
+ FILTER_QUADRATIC FilterType = C.QuadraticFilter
+ FILTER_CUBIC FilterType = C.CubicFilter
+ FILTER_CATROM FilterType = C.CatromFilter
+ FILTER_MITCHELL FilterType = C.MitchellFilter
+ FILTER_SINC FilterType = C.SincFilter
+ FILTER_KAISER FilterType = C.KaiserFilter
+ FILTER_WELSH FilterType = C.WelshFilter
+ FILTER_PARZEN FilterType = C.ParzenFilter
+ FILTER_BOHMAN FilterType = C.BohmanFilter
+ FILTER_BARTLETT FilterType = C.BartlettFilter
+ FILTER_LAGRANGE FilterType = C.LagrangeFilter
+ FILTER_LANCZOS FilterType = C.LanczosFilter
+ FILTER_SENTINEL FilterType = C.SentinelFilter
+ /*
+ Missing in ImageMagick 6.7.7
+ FILTER_LANCZOS_RADIUS FilterType = C.LanczosRadiusFilter
+ */
+)
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <magick/MagickCore.h>
+*/
+import "C"
+
+type Image struct {
+ img *C.Image
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <magick/MagickCore.h>
+*/
+import "C"
+
+type ImageInfo struct {
+ info *C.ImageInfo
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+type InterlaceType int
+
+const (
+ INTERLACE_UNDEFINED InterlaceType = C.UndefinedInterlace
+ INTERLACE_NO InterlaceType = C.NoInterlace
+ INTERLACE_LINE InterlaceType = C.LineInterlace
+ INTERLACE_PLANE InterlaceType = C.PlaneInterlace
+ INTERLACE_PARTITION InterlaceType = C.PartitionInterlace
+ INTERLACE_GIF InterlaceType = C.GIFInterlace
+ INTERLACE_JPEG InterlaceType = C.JPEGInterlace
+ INTERLACE_PNG InterlaceType = C.PNGInterlace
+)
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#cgo pkg-config: MagickWand MagickCore
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+// This struct represents the MagickWand C API of ImageMagick
+type MagickWand struct {
+ mw *C.MagickWand
+}
+
+// Returns a wand required for all other methods in the API. A fatal exception is thrown if there is not enough memory to allocate the wand.
+// Use Destroy() to dispose of the wand then it is no longer needed.
+func NewMagickWand() *MagickWand {
+ return &MagickWand{C.NewMagickWand()}
+}
+
+// Returns a wand with an image/
+func NewMagickWandFromImage(img *Image) *MagickWand {
+ return &MagickWand{C.NewMagickWandFromImage(img.img)}
+}
+
+// Clear resources associated with the wand, leaving the wand blank, and ready to be used for a new set of images.
+func (mw *MagickWand) Clear() {
+ C.ClearMagickWand(mw.mw)
+}
+
+// Makes an exact copy of the MagickWand object
+func (mw *MagickWand) Clone() *MagickWand {
+ clone := C.CloneMagickWand(mw.mw)
+ return &MagickWand{clone}
+}
+
+// Deallocates memory associated with an MagickWand
+func (mw *MagickWand) Destroy() {
+ if mw.mw == nil {
+ return
+ }
+ mw.mw = C.DestroyMagickWand(mw.mw)
+ C.free(unsafe.Pointer(mw.mw))
+ mw.mw = nil
+}
+
+// Returns true if the wand is a verified magick wand
+func (mw *MagickWand) IsVerified() bool {
+ if mw.mw != nil {
+ return 1 == C.int(C.IsMagickWand(mw.mw))
+ }
+ return false
+}
+
+// Relinquishes memory resources returned by such methods as MagickIdentifyImage(), MagickGetException(), etc
+func (mw *MagickWand) relinquishMemory(ptr unsafe.Pointer) {
+ C.MagickRelinquishMemory(ptr)
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#cgo pkg-config: MagickWand
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+var (
+ initialized bool
+)
+
+// Inicializes the MagickWand environment
+func Initialize() {
+ if initialized {
+ return
+ }
+ C.MagickWandGenesis()
+ initialized = true
+}
+
+// Terminates the MagickWand environment
+func Terminate() {
+ if initialized {
+ C.MagickWandTerminus()
+ initialized = false
+ }
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+type MagickWandException struct {
+ kind ExceptionType
+ description string
+}
+
+func (mwe *MagickWandException) Error() string {
+ return fmt.Sprintf("%s: %s", mwe.kind.String(), mwe.description)
+}
+
+// Clears any exceptions associated with the wand
+func (mw *MagickWand) clearException() bool {
+ return 1 == C.int(C.MagickClearException(mw.mw))
+}
+
+// Returns the kind, reason and description of any error that occurs when using other methods in this API
+func (mw *MagickWand) GetLastError() error {
+ var et C.ExceptionType
+ csdescription := C.MagickGetException(mw.mw, &et)
+ defer mw.relinquishMemory(unsafe.Pointer(csdescription))
+ if ExceptionType(et) != EXCEPTION_UNDEFINED {
+ mw.clearException()
+ return &MagickWandException{ExceptionType(C.int(et)), C.GoString(csdescription)}
+ }
+ return nil
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+
+import (
+ "errors"
+ "unsafe"
+)
+
+// Returns the current image from the magick wand
+func (mw *MagickWand) GetImageFromMagickWand() *Image {
+ return &Image{C.GetImageFromMagickWand(mw.mw)}
+}
+
+// Extracts a region of the image
+func (mw *MagickWand) CropImage(width, height uint, x, y int) error {
+ C.MagickCropImage(mw.mw, C.ulong(width), C.ulong(height), C.long(x), C.long(y))
+ return mw.GetLastError()
+}
+
+// Dereferences an image, deallocating memory associated with the image if the
+// reference count becomes zero.
+func (mw *MagickWand) DestroyImage(img *Image) *Image {
+ return &Image{C.MagickDestroyImage(img.img)}
+}
+
+// Implements direct to memory image formats. It returns the image as a blob
+// (a formatted "file" in memory) and its length, starting from the current
+// position in the image sequence. Use SetImageFormat() to set the format to
+// write to the blob (GIF, JPEG, PNG, etc.). Utilize ResetIterator() to ensure
+// the write is from the beginning of the image sequence.
+func (mw *MagickWand) GetImageBlob() []byte {
+ clen := C.size_t(0)
+ csblob := C.MagickGetImageBlob(mw.mw, &clen)
+ defer mw.relinquishMemory(unsafe.Pointer(csblob))
+ return C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
+}
+
+// Returns the format of a particular image in a sequence.
+func (mw *MagickWand) GetImageFormat() string {
+ return C.GoString(C.MagickGetImageFormat(mw.mw))
+}
+
+// Returns the image height.
+func (mw *MagickWand) GetImageHeight() uint {
+ return uint(C.MagickGetImageHeight(mw.mw))
+}
+
+// Returns the image width.
+func (mw *MagickWand) GetImageWidth() uint {
+ return uint(C.MagickGetImageWidth(mw.mw))
+}
+
+// Pings an image or image sequence from a blob.
+func (mw *MagickWand) PingImageBlob(blob []byte) error {
+ C.MagickPingImageBlob(mw.mw, unsafe.Pointer(&blob[0]), C.size_t(len(blob)))
+ return mw.GetLastError()
+}
+
+// Reads an image or image sequence from a blob.
+func (mw *MagickWand) ReadImageBlob(blob []byte) error {
+ if len(blob) == 0 {
+ return errors.New("zero-length blob not permitted")
+ }
+ C.MagickReadImageBlob(mw.mw, unsafe.Pointer(&blob[0]), C.size_t(len(blob)))
+ return mw.GetLastError()
+}
+
+
+// Scales an image to the desired dimensions
+//
+// cols: the number of cols in the scaled image.
+//
+// rows: the number of rows in the scaled image.
+//
+// filter: Image filter to use.
+//
+// blur: the blur factor where > 1 is blurry, < 1 is sharp.
+//
+func (mw *MagickWand) ResizeImage(cols, rows uint, filter FilterType, blur float64) error {
+ C.MagickResizeImage(mw.mw, C.ulong(cols), C.ulong(rows), C.FilterTypes(filter), C.double(blur))
+ return mw.GetLastError()
+}
+
+// Activates, deactivates, resets, or sets the alpha channel.
+func (mw *MagickWand) SetImageAlphaChannel(act AlphaChannelType) error {
+ C.MagickSetImageAlphaChannel(mw.mw, C.AlphaChannelType(act))
+ return mw.GetLastError()
+}
+
+// Sets the image compression.
+func (mw *MagickWand) SetImageCompression(compression CompressionType) error {
+ C.MagickSetImageCompression(mw.mw, C.CompressionType(compression))
+ return mw.GetLastError()
+}
+
+// Sets the image compression quality.
+func (mw *MagickWand) SetImageCompressionQuality(quality uint) error {
+ C.MagickSetImageCompressionQuality(mw.mw, C.ulong(quality))
+ return mw.GetLastError()
+}
+
+// Sets the image depth.
+//
+// depth: the image depth in bits: 8, 16, or 32.
+//
+func (mw *MagickWand) SetImageDepth(depth uint) error {
+ C.MagickSetImageDepth(mw.mw, C.ulong(depth))
+ return mw.GetLastError()
+}
+
+// Sets the format of a particular image in a sequence.
+//
+// format: the image format.
+//
+func (mw *MagickWand) SetImageFormat(format string) error {
+ csformat := C.CString(format)
+ defer C.free(unsafe.Pointer(csformat))
+ C.MagickSetImageFormat(mw.mw, csformat)
+ return mw.GetLastError()
+}
+
+
+// Sets the image interlace scheme.
+func (mw *MagickWand) SetImageInterlaceScheme(interlace InterlaceType) error {
+ C.MagickSetImageInterlaceScheme(mw.mw, C.InterlaceType(interlace))
+ return mw.GetLastError()
+}
+
+// Unsharpens an image. We convolve the image with a Gaussian operator of the
+// given radius and standard deviation (sigma). For reasonable results, radius
+// should be larger than sigma. Use a radius of 0 and UnsharpMaskImage()
+// selects a suitable radius for you.
+//
+// radius: the radius of the Gaussian, in pixels, not counting the center pixel.
+//
+// sigma: the standard deviation of the Gaussian, in pixels.
+//
+// amount: the percentage of the difference between the original and the blur
+// image that is added back into the original.
+//
+// threshold: the threshold in pixels needed to apply the diffence amount.
+//
+func (mw *MagickWand) UnsharpMaskImage(radius, sigma, amount, threshold float64) error {
+ C.MagickUnsharpMaskImage(mw.mw, C.double(radius), C.double(sigma), C.double(amount), C.double(threshold))
+ return mw.GetLastError()
+}
--- /dev/null
+// Copyright 2013 Herbert G. Fischer. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package imagick
+
+/*
+#include <wand/MagickWand.h>
+*/
+import "C"
+import (
+ //"fmt"
+ "unsafe"
+)
+
+// This method deletes a image property
+func (mw *MagickWand) DeleteImageProperty(property string) error {
+ csproperty := C.CString(property)
+ defer C.free(unsafe.Pointer(csproperty))
+ C.MagickDeleteImageProperty(mw.mw, csproperty)
+ return mw.GetLastError()
+}
+
+// This method deletes a wand option
+func (mw *MagickWand) DeleteOption(option string) error {
+ csoption := C.CString(option)
+ defer C.free(unsafe.Pointer(csoption))
+ C.MagickDeleteOption(mw.mw, csoption)
+ return mw.GetLastError()
+}
+
+// Returns all the profile names that match the specified pattern associated
+// with a wand. Use GetImageProfile() to return the value of a particular
+// property.
+func (mw *MagickWand) GetImageProfiles(pattern string) (profiles []string) {
+ cspattern := C.CString(pattern)
+ defer C.free(unsafe.Pointer(cspattern))
+ np := C.ulong(0)
+ ps := C.MagickGetImageProfiles(mw.mw, cspattern, &np)
+ profiles = sizedCStringArrayToStringSlice(ps, np)
+ return
+}
+
+// Gets the wand interlace scheme.
+func (mw *MagickWand) GetInterlaceScheme() InterlaceType {
+ return InterlaceType(C.MagickGetInterlaceScheme(mw.mw))
+}
+
+// Returns a value associated with a wand and the specified key.
+func (mw *MagickWand) GetOption(key string) string {
+ cskey := C.CString(key)
+ defer C.free(unsafe.Pointer(cskey))
+ csval := C.MagickGetOption(mw.mw, cskey)
+ return C.GoString(csval)
+}
+
+// Returns all the option names that match the specified pattern associated
+// with a wand. Use GetOption() to return the value of a particular option.
+func (mw *MagickWand) GetOptions(pattern string) (options []string) {
+ cspattern := C.CString(pattern)
+ defer C.free(unsafe.Pointer(cspattern))
+ np := C.ulong(0)
+ ps := C.MagickGetOptions(mw.mw, cspattern, &np)
+ options = sizedCStringArrayToStringSlice(ps, np)
+ return
+}
+
+// Removes the named image profile and returns it.
+//
+// name: name of profile to return: ICC, IPTC, or generic profile.
+//
+func (mw *MagickWand) RemoveImageProfile(name string) []byte {
+ csname := C.CString(name)
+ defer C.free(unsafe.Pointer(csname))
+ clen := C.size_t(0)
+ profile := C.MagickRemoveImageProfile(mw.mw, csname, &clen)
+ return C.GoBytes(unsafe.Pointer(profile), C.int(clen))
+}
+
+// Sets the image interlacing scheme
+func (mw *MagickWand) SetInterlaceScheme(scheme InterlaceType) error {
+ C.MagickSetInterlaceScheme(mw.mw, C.InterlaceType(scheme))
+ return mw.GetLastError()
+}
+
+// Associates one or options with the wand (.e.g
+// SetOption(wand, "jpeg:perserve", "yes")).
+func (mw *MagickWand) SetOption(key, value string) error {
+ cskey := C.CString(key)
+ defer C.free(unsafe.Pointer(cskey))
+ csvalue := C.CString(value)
+ defer C.free(unsafe.Pointer(csvalue))
+ C.MagickSetOption(mw.mw, cskey, csvalue)
+ return mw.GetLastError()
+}
package imager
import (
- "github.com/gographics/imagick/imagick"
+ "github.com/die-net/fotomat/imager/imagick"
)
func init() {
import (
"fmt"
- "github.com/gographics/imagick/imagick"
+ "github.com/die-net/fotomat/imager/imagick"
)
type Result struct {
package imager
import (
- "github.com/gographics/imagick/imagick"
+ "github.com/die-net/fotomat/imager/imagick"
"net/http"
)