Coder Social home page Coder Social logo

gographics / imagick Goto Github PK

View Code? Open in Web Editor NEW
1.7K 55.0 181.0 4.49 MB

Go binding to ImageMagick's MagickWand C API

Home Page: https://godoc.org/github.com/gographics/imagick/imagick

License: Other

Shell 0.05% Go 99.59% Dockerfile 0.37%
imagick magickwand imagemagick go imagemagick-magickwand golang

imagick's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imagick's Issues

Memory Leak

In magick_wand_image.go there appears to be a memory leak for GetImageFormat() and a few others. I am not that knowledgable about CGO but it seems like you need to free the pointer in this function and my testing proves that out.

The original function will push the memory usage every time its called.

// Returns the format of a particular image in a sequence.
func (mw *MagickWand) GetImageFormat() string {
    return C.GoString(C.MagickGetImageFormat(mw.mw))
}

When I change the function to this (based on other functions in your code) the memory leak does not occur.

// Returns the format of a particular image in a sequence.
func (mw *MagickWand) GetImageFormat() string {
    p := C.MagickGetImageFormat(mw.mw)
    defer C.free(unsafe.Pointer(p))
    return C.GoString(p)
}

There appears to be multiple examples of this in magick_wand_image.go, pixel_wand.go and magick_wand.go but I don't know enough to know which ones should be that way and which should not.

Free string constant

Not sure if it happens in older versions but in this version ImageMagick 6.8.9-8 have problem free memory. According to document the returned result is a string constant. I think there are more than this method.

imagick.test(99771,0x7fff7d11a300) malloc: *** error for object 0x44eddb5: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
SIGABRT: abort
PC=0x7fff94201282
signal arrived during cgo execution

The code is simply:

import (
"github.com/gographics/imagick/imagick"
"testing"
)
func TestGetVersion(t *testing.T) {
imagick.GetVersion()
}

Determine temporary directory path used by imagick

I searched the code but I couldn't find a function that returns the temporary directory used by imagick for storing temporary resources. Although, I do see temp files in /tmp/ with a magick- prefix. Any suggestions? sometimes these files are not cleaned up properly and I'd like to add a sweep method myself.

Using gographics to convert RGB PNGs to 8 bit colormaps concurrently in goroutines

Hiya. Attempting to generate indexed (that is, palletized to 8 bit colormap) PNGs representing maptiles. I generate numerous goroutines, and the logic in a go routine essentially is as follows:

  1. Invoke MapNik to generate a 4096x4096 RGB PNG "supertile"
  2. Use the Go Image package to carve up the supertile into 256 256x256 pixel PNG maptiles
  3. (Sequentially) For each of the 256 tiles, call MagigickWand.Clear(), then invoke MagickWand's Quantize() function to create an indexed PNG using 256 colors
  4. Write each palletized PNG to a file via MagickWand's WriteImageFile.

Having various issues -- it almost appears that IM / MW is not threadsafe, although the developers state otherwise. Here's a typical SEGFAULT:

tiler: magick/colorspace.c:1528: TransformImageColorspace: Assertion `image->signature == 0xabacadabUL' failed.
SIGABRT: abort
PC=0x7f0608a47cc9 m=10
signal arrived during cgo execution

goroutine 45 [syscall, locked to thread]:
runtime.cgocall(0x4213e0, 0xc820463b08, 0x0)
/usr/local/go/src/runtime/cgocall.go:120 +0x11b fp=0xc820463ac0 sp=0xc820463a90
github.com/gographics/imagick/imagick._Cfunc_MagickSetImageType(0x7f05e40015d0, 0x4, 0x7f0500000000)
??:0 +0x39 fp=0xc820463b08 sp=0xc820463ac0
github.com/gographics/imagick/imagick.(*MagickWand).SetImageType(0xc82014a008, 0x4, 0x0, 0x0)
/root/work/src/github.com/gographics/imagick/imagick/magick_wand_image.go:2609 +0x3b fp=0xc820463b28 sp=0xc820463b08
main.createTile(0xc8205d4990, 0x2f, 0x7f05f1a2f700, 0xc82016f240, 0x7f05f1a2f738, 0xc820448000, 0xc820463d40, 0xc82044a000, 0xc82014a008, 0x0, ...)
/root/work/src/tomtomapac.com/tiler/tiler.go:250 +0x3b1 fp=0xc820463ca8 sp=0xc820463b28
main.tileWorker(0xc8200142a0, 0xc820014300, 0xc8200141e0, 0xc82014a008)
/root/work/src/tomtomapac.com/tiler/tiler.go:340 +0x9dc fp=0xc820463f80 sp=0xc820463ca8
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1 fp=0xc820463f88 sp=0xc820463f80
created by main.main
/root/work/src/tomtomapac.com/tiler/tiler.go:472 +0xaf1

I've tried calling imagick.Initialize() in the mainthread before the goroutines are spun up as well as having each goroutine call imagick.Initialize() locally. I've tried creating a single MagickWand instance in the mainthread and sharing it among all goroutines, and I've tried having each goroutine create its own MagicWand instance. In all cases, the above and similar errors occur under heavy load.

I'm running this under Ubuntu, using version 6.7.7-10 2014-03-06 Q16 of ImageMagick, and libMagickWand.so.5.0.0 is the lib the go binary is linked against.. I realize I've left out a lot of information you may need, but feel free to flame me back and state whatever further detail you require. Essentially, it would really help if you would give me an idea how to structure my interaction with MagicWand in realtion to my goroutines. Any other gotchas I need to be aware of when running MagickWand in concurrent goroutines?

how to import image pixels?

I am trying to import RGBA data into a wand and the image that I am getting on the output is corrupted. I mean the colors are wrong. What is the right way to do it?

package main

import (
    "image"
    "image/color"
    "image/draw"
    "log"

    "github.com/gographics/imagick/imagick"
)

func main() {
    imagick.Initialize()
    defer imagick.Terminate()

    wand := imagick.NewMagickWand()
    defer wand.Destroy()

    pixelwand := imagick.NewPixelWand()
    defer pixelwand.Destroy()

    im := image.NewRGBA(image.Rect(0, 0, 640, 480))
    blue := color.RGBA{0, 0, 255, 255}
    draw.Draw(im, im.Bounds(), &image.Uniform{blue}, image.ZP, draw.Src)

    b := im.Bounds()
    w, h := uint(b.Dx()), uint(b.Dy())

    wand.NewImage(w, h, pixelwand)

    pixels := im.Pix
    data := make([]interface{}, len(pixels))

    for i, v := range pixels {
        data[i] = interface{}(v)
    }
    e := wand.ImportImagePixels(0, 0, w, h, "RGBA", imagick.PIXEL_CHAR, data)
    if e != nil {
        log.Fatal(e)
    }

    e = wand.WriteImage("test.jpg")
    if e != nil {
        log.Fatal(e)
    }
}

Histograms?

Could you make it more clear how to get the histogram of an image? Or is this not supported yet?

Memory issue with the imagick initialization

I have explained the code in the following link. Which uses the

    imagick.Initialize() 
    defer imagick.Terminate() 

to initialize the library. If, I don't include these lines in the code my /tmp folder size keep on increasing. Where as on the other hand if i include them in code my RAM size increases monotonously and in the end my handler crashes. Kindly look into this matter. Why is it happening. Moreover, as such i don't have any memory leak in my code.

func CreateMaster(keyName string, desiredAspectRatio float64, isMaster bool) bool {             

    s3Client := s3.New(session.New(), &aws.Config{Region: aws.String(region)})
        params := &s3.GetObjectInput{
        Bucket: aws.String(bucketName),
        Key: aws.String(keyName),
        }

    fmt.Println(" Master creation request for key : " + keyName)
    out, err := s3Client.GetObject(params)

    if err != nil { 
        return false                                       
    }

    defer out.Body.Close()  
    img, err := ioutil.ReadAll(out.Body)

    if err != nil { 
            return false      
    }                   

    mw := imagick.NewMagickWand()
    defer mw.Destroy()

    err = mw.ReadImageBlob(img)
    if err != nil {  
        return false                   
    }


    if isMaster == false {
        paramsPut := &s3.PutObjectInput{
                    Bucket:         aws.String(masterBucketName),
                    Key:            aws.String(keyName),
                    Body:         bytes.NewReader(mw.GetImageBlob()),
            }

        _, err = s3Client.PutObject(paramsPut)
        if err != nil {
            log.Printf("Couldn't put the image on s3 : " + keyName + "%s\n", err)       
        }

        return true
    }


        originalWidth := float64(mw.GetImageWidth())
        originalHeight := float64(mw.GetImageHeight())

    imageAspectRatio  := originalWidth / originalHeight
        masterWidth := cwMasterWidth
        masterHeight := cwMasterHeight
        masterAspectRatio := math.Trunc((cwMasterWidth / cwMasterHeight) * 100)/100

    if masterAspectRatio != desiredAspectRatio {           
                    masterAspectRatio = desiredAspectRatio
                }


    pwm := imagick.NewPixelWand()
    defer pwm.Destroy()

    tx := imagick.NewMagickWand()
    defer tx.Destroy()  

    if isMaster == true {               

            var w, h uint = 0, 0
            size := fmt.Sprintf("%dx%d^+0+0", w, h) 
                    if imageAspectRatio <= masterAspectRatio {                
                        // trim the height
            w = uint(originalWidth)
            h = (uint(originalWidth / masterAspectRatio))
               size = fmt.Sprintf("%dx%d^+0+0", w, h)
                     } else { 
                        // trim the width
            w = uint(originalHeight * masterAspectRatio)
            h = uint(originalHeight)
            size = fmt.Sprintf("%dx%d^+0+0", w, h)
                     }

            tx = mw.TransformImage("", size)        
            tx.SetImageGravity(imagick.GRAVITY_CENTER)
            offsetX := -(int(w) - int(tx.GetImageWidth())) / 2
            offsetY := -(int(h) - int(tx.GetImageHeight())) / 2
            err := tx.ExtentImage(w, h, offsetX, offsetY)

                    if float64(tx.GetImageWidth()) > masterWidth && float64(tx.GetImageHeight()) > masterHeight  {                                        
                        err = tx.ResizeImage(uint(masterWidth), uint(masterHeight), imagick.FILTER_BOX, 1)
            if err != nil {
                log.Printf("Inside CreateMaster function Couldn't resize the image : " + keyName + "%s\n", err) 
                return false                 
            }                                                           
                    }                                       
                }       

     paramsPut := &s3.PutObjectInput{
                    Bucket:         aws.String(masterBucketName),
                    Key:            aws.String(keyName),
                    Body:         bytes.NewReader(tx.GetImageBlob()),
            }

    _, err = s3Client.PutObject(paramsPut)
    if err != nil {
        log.Printf("Inside CreateMaster function Couldn't put the image on s3 : " + keyName + "%s\n", err)  
        return false        
    }

    return true
}

http://stackoverflow.com/questions/35768266/memory-leak-in-go-lang-http-handler

Can't be installed with 32 bit?

root@dev:/www/resources/golang# go get github.com/gographics/imagick/imagick
# github.com/gographics/imagick/imagick
/root/gopath/src/github.com/gographics/imagick/imagick/draw_info.go:14:6: unexpected: 12-byte float type - long double

Go Imagick installation on windows

Can you describe more precise how to install Go Imagick on windows? (Windows 8.1 x64, ImageMagick-6.9.0-Q16 x86/x64 both installed.)

All i can get is:
PS E:\users\user\dev\golang> go get github.com/gographics/imagick/imagick
# pkg-config --cflags MagickWand MagickCore
pkg-config: exec: "pkg-config": executable file not found in %PATH%

And, after, somehow, i've got pkg-config-lite (for windows): an output became even more hopeless:

PS E:\users\user\dev\golang> go get github.com/gographics/imagick/imagick
# pkg-config --cflags MagickWand MagickCore
pkg-config: exec: "pkg-config": executable file not found in %PATH%
PS E:\users\user\dev\golang> go get github.com/gographics/imagick/imagick
# pkg-config --cflags MagickWand MagickCore
Package MagickWand was not found in the pkg-config search path.
Perhaps you should add the directory containing 'MagickWand.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickWand' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing 'MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found

Where can i get 'MagickWand.pc'? What kind of compiler (msvc/mingw) should i use? (Hope, it is a relevant question).
Can i install Go Imagick without pkg-config?

It may sound like a stupid question, but: "Is it even possible to install Go Imagick on windows?"
(BTW, it installs like a charm on mac/linux =)

ReadImageBlob() crashes if blog is empty slice

func (mw *MagickWand) ReadImageBlob(blob []byte) error {
    C.MagickReadImageBlob(mw.mw, unsafe.Pointer(&blob[0]), C.size_t(len(blob)))
    return mw.GetLastError()
}

if called with empty or null blob, this will crash because of &blob[0].

The simplest fix that leaves generating the error to C code would probably be along the lines of (untested, assuming C code handles NULL and generates proper error message):

func (mw *MagickWand) ReadImageBlob(blob []byte) error {
    data := unsafe.Pointer(0)
    if (len(blob) > 0) {
        data =  unsafe.Pointer(&blob[0])
    }
    C.MagickReadImageBlob(mw.mw, data, C.size_t(len(blob)))
    return mw.GetLastError()
}

Another option would be:

func (mw *MagickWand) ReadImageBlob(blob []byte) error {
    if (len(blob) == 0) {
        return errors.New("empty or null image data")
    } 
    C.MagickReadImageBlob(mw.mw, unsafe.Pointer(&blob[0]), C.size_t(len(blob)))
    return mw.GetLastError()
}

Install imagick error in mac osx

When I installed the imagick in osx,I got these errors.Thanks for you help.

eric:go yutao$ go get github.com/gographics/imagick/imagick
# github.com/gographics/imagick/imagick
gcc did not produce error at completed:1
on input:
#line 7 "/Users/yutao/Documents/go/src/github.com/gographics/imagick/imagick/channel_type.go"

#include <wand/MagickWand.h>


#include <stddef.h> /* for ptrdiff_t and size_t below */

/* Define intgo when compiling with GCC.  */
typedef ptrdiff_t intgo;

typedef struct { char *p; intgo n; } _GoString_;
typedef struct { char *p; intgo n; intgo c; } _GoBytes_;
_GoString_ GoString(char *p);
_GoString_ GoStringN(char *p, int l);
_GoBytes_ GoBytes(void *p, int n);
char *CString(_GoString_);
void *_CMalloc(size_t);
#line 1 "not-declared"
void __cgo_f_1_1(void) { __typeof__(AllChannels) *__cgo_undefined__; }
#line 1 "not-type"
void __cgo_f_1_2(void) { AllChannels *__cgo_undefined__; }
#line 1 "not-const"
void __cgo_f_1_3(void) { enum { __cgo__undefined__ = (AllChannels)*1 }; }
#line 2 "not-declared"
void __cgo_f_2_1(void) { __typeof__(AlphaChannel) *__cgo_undefined__; }
#line 2 "not-type"
void __cgo_f_2_2(void) { AlphaChannel *__cgo_undefined__; }
#line 2 "not-const"
void __cgo_f_2_3(void) { enum { __cgo__undefined__ = (AlphaChannel)*1 }; }
#line 3 "not-declared"
void __cgo_f_3_1(void) { __typeof__(BlackChannel) *__cgo_undefined__; }
#line 3 "not-type"
void __cgo_f_3_2(void) { BlackChannel *__cgo_undefined__; }
#line 3 "not-const"
void __cgo_f_3_3(void) { enum { __cgo__undefined__ = (BlackChannel)*1 }; }
#line 4 "not-declared"
void __cgo_f_4_1(void) { __typeof__(BlueChannel) *__cgo_undefined__; }
#line 4 "not-type"
void __cgo_f_4_2(void) { BlueChannel *__cgo_undefined__; }
#line 4 "not-const"
void __cgo_f_4_3(void) { enum { __cgo__undefined__ = (BlueChannel)*1 }; }
#line 5 "not-declared"
void __cgo_f_5_1(void) { __typeof__(CompositeChannels) *__cgo_undefined__; }
#line 5 "not-type"
void __cgo_f_5_2(void) { CompositeChannels *__cgo_undefined__; }
#line 5 "not-const"
void __cgo_f_5_3(void) { enum { __cgo__undefined__ = (CompositeChannels)*1 }; }
#line 6 "not-declared"
void __cgo_f_6_1(void) { __typeof__(CyanChannel) *__cgo_undefined__; }
#line 6 "not-type"
void __cgo_f_6_2(void) { CyanChannel *__cgo_undefined__; }
#line 6 "not-const"
void __cgo_f_6_3(void) { enum { __cgo__undefined__ = (CyanChannel)*1 }; }
#line 7 "not-declared"
void __cgo_f_7_1(void) { __typeof__(DefaultChannels) *__cgo_undefined__; }
#line 7 "not-type"
void __cgo_f_7_2(void) { DefaultChannels *__cgo_undefined__; }
#line 7 "not-const"
void __cgo_f_7_3(void) { enum { __cgo__undefined__ = (DefaultChannels)*1 }; }
#line 8 "not-declared"
void __cgo_f_8_1(void) { __typeof__(GrayChannel) *__cgo_undefined__; }
#line 8 "not-type"
void __cgo_f_8_2(void) { GrayChannel *__cgo_undefined__; }
#line 8 "not-const"
void __cgo_f_8_3(void) { enum { __cgo__undefined__ = (GrayChannel)*1 }; }
#line 9 "not-declared"
void __cgo_f_9_1(void) { __typeof__(GrayChannels) *__cgo_undefined__; }
#line 9 "not-type"
void __cgo_f_9_2(void) { GrayChannels *__cgo_undefined__; }
#line 9 "not-const"
void __cgo_f_9_3(void) { enum { __cgo__undefined__ = (GrayChannels)*1 }; }
#line 10 "not-declared"
void __cgo_f_10_1(void) { __typeof__(GreenChannel) *__cgo_undefined__; }
#line 10 "not-type"
void __cgo_f_10_2(void) { GreenChannel *__cgo_undefined__; }
#line 10 "not-const"
void __cgo_f_10_3(void) { enum { __cgo__undefined__ = (GreenChannel)*1 }; }
#line 11 "not-declared"
void __cgo_f_11_1(void) { __typeof__(IndexChannel) *__cgo_undefined__; }
#line 11 "not-type"
void __cgo_f_11_2(void) { IndexChannel *__cgo_undefined__; }
#line 11 "not-const"
void __cgo_f_11_3(void) { enum { __cgo__undefined__ = (IndexChannel)*1 }; }
#line 12 "not-declared"
void __cgo_f_12_1(void) { __typeof__(MagentaChannel) *__cgo_undefined__; }
#line 12 "not-type"
void __cgo_f_12_2(void) { MagentaChannel *__cgo_undefined__; }
#line 12 "not-const"
void __cgo_f_12_3(void) { enum { __cgo__undefined__ = (MagentaChannel)*1 }; }
#line 13 "not-declared"
void __cgo_f_13_1(void) { __typeof__(OpacityChannel) *__cgo_undefined__; }
#line 13 "not-type"
void __cgo_f_13_2(void) { OpacityChannel *__cgo_undefined__; }
#line 13 "not-const"
void __cgo_f_13_3(void) { enum { __cgo__undefined__ = (OpacityChannel)*1 }; }
#line 14 "not-declared"
void __cgo_f_14_1(void) { __typeof__(RGBChannels) *__cgo_undefined__; }
#line 14 "not-type"
void __cgo_f_14_2(void) { RGBChannels *__cgo_undefined__; }
#line 14 "not-const"
void __cgo_f_14_3(void) { enum { __cgo__undefined__ = (RGBChannels)*1 }; }
#line 15 "not-declared"
void __cgo_f_15_1(void) { __typeof__(RedChannel) *__cgo_undefined__; }
#line 15 "not-type"
void __cgo_f_15_2(void) { RedChannel *__cgo_undefined__; }
#line 15 "not-const"
void __cgo_f_15_3(void) { enum { __cgo__undefined__ = (RedChannel)*1 }; }
#line 16 "not-declared"
void __cgo_f_16_1(void) { __typeof__(SyncChannels) *__cgo_undefined__; }
#line 16 "not-type"
void __cgo_f_16_2(void) { SyncChannels *__cgo_undefined__; }
#line 16 "not-const"
void __cgo_f_16_3(void) { enum { __cgo__undefined__ = (SyncChannels)*1 }; }
#line 17 "not-declared"
void __cgo_f_17_1(void) { __typeof__(TrueAlphaChannel) *__cgo_undefined__; }
#line 17 "not-type"
void __cgo_f_17_2(void) { TrueAlphaChannel *__cgo_undefined__; }
#line 17 "not-const"
void __cgo_f_17_3(void) { enum { __cgo__undefined__ = (TrueAlphaChannel)*1 }; }
#line 18 "not-declared"
void __cgo_f_18_1(void) { __typeof__(UndefinedChannel) *__cgo_undefined__; }
#line 18 "not-type"
void __cgo_f_18_2(void) { UndefinedChannel *__cgo_undefined__; }
#line 18 "not-const"
void __cgo_f_18_3(void) { enum { __cgo__undefined__ = (UndefinedChannel)*1 }; }
#line 19 "not-declared"
void __cgo_f_19_1(void) { __typeof__(YellowChannel) *__cgo_undefined__; }
#line 19 "not-type"
void __cgo_f_19_2(void) { YellowChannel *__cgo_undefined__; }
#line 19 "not-const"
void __cgo_f_19_3(void) { enum { __cgo__undefined__ = (YellowChannel)*1 }; }
#line 1 "completed"
int __cgo__1 = __cgo__2;

full error output:
not-type:1:39: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_1_2(void) { AllChannels *__cgo_undefined__; }
                                      ^
not-type:2:40: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_2_2(void) { AlphaChannel *__cgo_undefined__; }
                                       ^
not-type:3:40: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_3_2(void) { BlackChannel *__cgo_undefined__; }
                                       ^
not-type:4:39: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_4_2(void) { BlueChannel *__cgo_undefined__; }
                                      ^
not-type:5:45: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_5_2(void) { CompositeChannels *__cgo_undefined__; }
                                            ^
not-type:6:39: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_6_2(void) { CyanChannel *__cgo_undefined__; }
                                      ^
not-type:7:43: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_7_2(void) { DefaultChannels *__cgo_undefined__; }
                                          ^
not-type:8:39: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_8_2(void) { GrayChannel *__cgo_undefined__; }
                                      ^
not-type:9:40: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_9_2(void) { GrayChannels *__cgo_undefined__; }
                                       ^
not-type:10:41: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_10_2(void) { GreenChannel *__cgo_undefined__; }
                                        ^
not-type:11:41: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_11_2(void) { IndexChannel *__cgo_undefined__; }
                                        ^
not-type:12:43: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_12_2(void) { MagentaChannel *__cgo_undefined__; }
                                          ^
not-type:13:43: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_13_2(void) { OpacityChannel *__cgo_undefined__; }
                                          ^
not-type:14:40: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_14_2(void) { RGBChannels *__cgo_undefined__; }
                                       ^
not-type:15:39: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_15_2(void) { RedChannel *__cgo_undefined__; }
                                      ^
not-type:16:41: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_16_2(void) { SyncChannels *__cgo_undefined__; }
                                        ^
not-type:17:45: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_17_2(void) { TrueAlphaChannel *__cgo_undefined__; }
                                            ^
not-type:18:45: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_18_2(void) { UndefinedChannel *__cgo_undefined__; }
                                            ^
not-type:19:42: error: use of undeclared identifier '__cgo_undefined__'
void __cgo_f_19_2(void) { YellowChannel *__cgo_undefined__; }
                                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

How to use SetImageGravity

Hi. First off thanks so much for this library.

This is a question and not really an issue/bug. How is SetImageGravity supposed to be used?

My current code looks like:

// Set gravity first
err = mw.SetImageGravity(imagick.GRAVITY_SOUTH)
if err != nil {
  return
}
// Now do the cropping
err = mw.CropImage(200, 200, 0, 0)
if err != nil {
  return
}

Gravity does not do anything, as I would expect from the command line version:

convert -resize "200x200^^" -gravity South -crop "200x200+0+0"

Am I doing it wrong?

Thank you in advance.

Depreciation Warnings on Build

Not a huge deal for now as everything still works, but, I've found that this - for some reason - exponentially increases the build time:

# github.com/gographics/imagick/imagick
../../gographics/imagick/imagick/magick_core_env.go:54:23: warning: 'IsMagickInstantiated' is deprecated [-Wdeprecated-declarations]
/usr/local/Cellar/imagemagick/6.8.9-8/include/ImageMagick-6/magick/deprecate.h:203:3: note: 'IsMagickInstantiated' has been explicitly marked deprecated here
# github.com/gographics/imagick/imagick
../../gographics/imagick/imagick/magick_wand_image.go:3014:23: warning: 'MagickRadialBlurImage' is deprecated [-Wdeprecated-declarations]
/usr/local/Cellar/imagemagick/6.8.9-8/include/ImageMagick-6/wand/deprecate.h:109:3: note: 'MagickRadialBlurImage' has been explicitly marked deprecated here
../../gographics/imagick/imagick/magick_wand_image.go:3031:23: warning: 'MagickRadialBlurImageChannel' is deprecated [-Wdeprecated-declarations]
/usr/local/Cellar/imagemagick/6.8.9-8/include/ImageMagick-6/wand/deprecate.h:111:3: note: 'MagickRadialBlurImageChannel' has been explicitly marked deprecated here

Thanks!

I can not use this in centos...

console shows

[root@localhost ~]# go get github.com/gographics/imagick/imagick

github.com/gographics/imagick/imagick

error: 'FlattenAlphaChannel' undeclared (first use in this function)
error: 'RemoveAlphaChannel' undeclared (first use in this function)

Magick Wand ReadImageFile fails

Attempting to use ReadImageFile results in the following error which cannot be prevented:

importer: wand/magick-image.c:8785: MagickReadImageFile: Assertion `file != (FILE *) ((void *)0)' failed.
SIGABRT: abort
PC=0x7f3039f405f8 m=3
signal arrived during cgo execution

Any help would be much appreciated!

error while loading shared libraries: libMagickWand-6.Q16.so.1: cannot open shared object file: No such file or directory

After compile and copy binary to sever:

error while loading shared libraries: libMagickWand-6.Q16.so.1: cannot open shared object file: No such file or directory

Centos 6,

convert --version
Version: ImageMagick 6.9.3-0 Q16 x86_64 2016-01-16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib jng jpeg lcms ltdl openexr pangocairo png ps rsvg tiff webp wmf x xml zlib

ldconfig /usr/local/lib not helped.

Using gopkg.in to support multiple version streams?

Currently we have the master branch acting as the compatibility branch for < ImageMagick-6.8.9, and the im-6.8.9 branch for >= 6.8.9. This makes it a bit more complicated since it isn't go-gettable with the 6.8.9 support.

What do we think of possibly using http://labix.org/gopkg.in, with some kind of tagging convention so that people could do:

# < 6.8.9
$ go get gopkg.in/gographics/imagick.v1/imagick
# >= 6.8.9
$ go get gopkg.in/gographics/imagick.v2/imagick

Thoughts? Not sure the best way to map the branch/tag naming to this, since our compatibility issue sits within a minor version (6.8.x). We would probably just have to keep moving 1.x and 2.x tags on the master and im-6.8.9 branches.

Unable to readImage() a TIF file

I'm having troubles reading a TIF file. Please see my code below. The mw.ReadImage() function panics with the following error: "panic: WARNING_CODER: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/887". A quick search learned me that it could be OSX related, but unfortunately I'm also having troubles running on Ubuntu, with latest ImageMagick and libtiff installed (from official ubuntu repo). Any ideas?

Edit

It looks like it's only a warming, however imagick panics. When I use the command line util from ImageMagic, it displays the error, but the image operation succeeds fine. I suggest imagick should not panic, right?

Edit 2

Sorry, I just noticed this issue: #44

Use ImageMagick itself

convert 3348900871984.tif -resize 500 klein.png
convert: Incompatible type for "RichTIFFIPTC"; tag ignored. TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/887. convert: Unknown field with tag 306 (0x132) encountered.TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/887.
convert: Incompatible type for "FileSource"; tag ignored. TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/887. convert: Incompatible type for "SceneType"; tag ignored.TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/887.
convert: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/887.

Example panic code

imagick.Initialize()
defer imagick.Terminate()

inputFile := "/Users/rlommers/Desktop/3348900871984.tif"
outputFile := "../../target/tif-resized.jpg"
fillColor := "white"
targetWidth := uint(300)
targetHeight := uint(90)
align := "right"
log.Printf("open file [%s] and resize to [%dx%d] with color [%s], saving rendition to [%s]", inputFile, targetWidth, targetHeight, fillColor, outputFile)

mw := imagick.NewMagickWand()
// Schedule cleanup
defer mw.Destroy()

pw := imagick.NewPixelWand()
defer pw.Destroy()
pw.SetColor(fillColor)

// read image
err := mw.ReadImage(inputFile)
if err != nil {
    panic(err)
}

Running In Go Routine Causes Stack Trace

I removed the build I did from /usr/local and downloaded the binary release:

Same problem:

package main

import (
"bufio"
"github.com/gographics/imagick/imagick"
"os"
)

func main() {

imagick.Initialize()
defer imagick.Terminate()

go InRoutine()

reader := bufio.NewReader(os.Stdin)
reader.ReadString('\n')

}

func InRoutine() {

mw := imagick.NewMagickWand()
defer mw.Destroy()

mw.ReadImage("/Users/bill/temp/testimage.gif")

}

SIGSEGV: segmentation violation
PC=0x6f47e5
signal arrived during cgo execution

github.com/gographics/imagick/imagick._Cfunc_MagickReadImage(0x12000000, 0x11900340, 0x11900340)
github.com/gographics/imagick/imagick/_obj/_cgo_defun.c:3547 +0x2f
github.com/gographics/imagick/imagick.(*MagickWand).ReadImage(0xc200000018, 0x122af0, 0x1e, 0x0, 0x0, ...)
github.com/gographics/imagick/imagick/_obj/_cgo_gotypes.go:6398 +0x80
main.InRoutine()
/Users/bill/Spaces/Test/src/image/main.go:26 +0x61
created by main.main
/Users/bill/Spaces/Test/src/image/main.go:15 +0x3b

goroutine 1 [syscall]:
syscall.Syscall()
/usr/local/go/src/pkg/syscall/asm_darwin_amd64.s:14 +0x5
syscall.read(0x0, 0xc2000ad000, 0x1000, 0x1000, 0xc759c0, ...)
/usr/local/go/src/pkg/syscall/zsyscall_darwin_amd64.go:900 +0x70
syscall.Read(0x0, 0xc2000ad000, 0x1000, 0x1000, 0xc75a90, ...)
/usr/local/go/src/pkg/syscall/syscall_unix.go:132 +0x5a
os.(_File).read(0xc200000000, 0xc2000ad000, 0x1000, 0x1000, 0x1800000, ...)
/usr/local/go/src/pkg/os/file_unix.go:174 +0x60
os.(_File).Read(0xc200000000, 0xc2000ad000, 0x1000, 0x1000, 0x118096e8, ...)
/usr/local/go/src/pkg/os/file.go:95 +0x96
bufio.(_Reader).fill(0xc2000ac000)
/usr/local/go/src/pkg/bufio/bufio.go:79 +0x10c
bufio.(_Reader).ReadSlice(0xc2000ac000, 0xa, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/pkg/bufio/bufio.go:262 +0x202
bufio.(_Reader).ReadBytes(0xc2000ac000, 0xc2000ac00a, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/pkg/bufio/bufio.go:343 +0xb7
bufio.(_Reader).ReadString(0xc2000ac000, 0xc20000000a, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/pkg/bufio/bufio.go:383 +0x53
main.main()
/Users/bill/Spaces/Test/src/image/main.go:18 +0x76

goroutine 2 [syscall]:
rax 0x0
rbx 0x0
rcx 0x0
rdx 0x2150
rdi 0x102
rsi 0x0
rbp 0xb0179b20
rsp 0xb0179b10
r8 0xc21200
r9 0x0
r10 0xc04000
r11 0x1201ae00
r12 0x1201ac78
r13 0xaa72e0
r14 0x1201ae00
r15 0x12019c68
rip 0x6f47e5
rflags 0x10202
cs 0x2b
fs 0x0
gs 0x0
Error: process exited with code 2.

Works when everything is just in main. When I use it in a go routine I get a stack trace. I have tried putting Initialize in both main and in the routine as follows.

I used this page:
http://www.imagemagick.org/script/install-source.php#unix

Which Downloaded version 6.8.6-8

I followed the instructions and everything built and worked, until I used the go routine.

I am running on MacOSX 10.8.4

package main

import (
"bufio"
"github.com/gographics/imagick/imagick"
"log"
"os"
)

func main() {

go InRoutine()

reader := bufio.NewReader(os.Stdin)
reader.ReadString('\n')

}

func InRoutine() {

imagick.Initialize()
defer imagick.Terminate()

mw := imagick.NewMagickWand()
defer mw.Destroy()

if err := mw.ReadImage("/Users/bill/temp/testimage.gif"); err != nil {
    log.Fatal(err)
}

fuzz := float64(10) // should be 10%

// our special colors we want to filter
filter := []*imagick.PixelWand{
    imagick.NewPixelWand(),
    imagick.NewPixelWand(),
    imagick.NewPixelWand(),
    imagick.NewPixelWand(),
}
filter[0].SetColor("#3030CE")
defer filter[0].Destroy()
filter[1].SetColor("#04e9e7")
defer filter[0].Destroy()
filter[2].SetColor("#019ff4")
defer filter[0].Destroy()
filter[3].SetColor("#0300f4")
defer filter[0].Destroy()

for _, f := range filter {
    mw.TransparentPaintImage(f, 0, fuzz, false)
}

mw.BlurImage(2, 2)

mw.WriteImage("/Users/bill/temp/codetest.gif")

}

SIGSEGV: segmentation violation
PC=0x726635
signal arrived during cgo execution

github.com/gographics/imagick/imagick._Cfunc_MagickWandGenesis(0x20b4)
github.com/gographics/imagick/imagick/_obj/_cgo_defun.c:4681 +0x2f
github.com/gographics/imagick/imagick.Initialize()
github.com/gographics/imagick/imagick/_obj/_cgo_gotypes.go:4639 +0x23
main.InRoutine()
/Users/bill/Spaces/Test/src/image/main.go:20 +0x24
created by main.main
/Users/bill/Spaces/Test/src/image/main.go:12 +0x23

goroutine 1 [syscall]:
syscall.Syscall()
/usr/local/go/src/pkg/syscall/asm_darwin_amd64.s:15 +0x5
syscall.read(0x0, 0xc20009a000, 0x1000, 0x1000, 0xf00a28, ...)
/usr/local/go/src/pkg/syscall/zsyscall_darwin_amd64.go:900 +0x70
syscall.Read(0x0, 0xc20009a000, 0x1000, 0x1000, 0xf00af8, ...)
/usr/local/go/src/pkg/syscall/syscall_unix.go:132 +0x5a
os.(_File).read(0xc200000000, 0xc20009a000, 0x1000, 0x1000, 0x1800000, ...)
/usr/local/go/src/pkg/os/file_unix.go:174 +0x60
os.(_File).Read(0xc200000000, 0xc20009a000, 0x1000, 0x1000, 0x118096e8, ...)
/usr/local/go/src/pkg/os/file.go:95 +0x96
bufio.(_Reader).fill(0xc200099000)
/usr/local/go/src/pkg/bufio/bufio.go:79 +0x10c
bufio.(_Reader).ReadSlice(0xc200099000, 0xa, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/pkg/bufio/bufio.go:262 +0x202
bufio.(_Reader).ReadBytes(0xc200099000, 0xc20009900a, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/pkg/bufio/bufio.go:343 +0xb7
bufio.(_Reader).ReadString(0xc200099000, 0xc20000000a, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/pkg/bufio/bufio.go:383 +0x53
main.main()
/Users/bill/Spaces/Test/src/image/main.go:15 +0x5e

goroutine 2 [syscall]:
rax 0x0
rbx 0xa00
rcx 0x99b428
rdx 0x7fff5fbffab8
rdi 0x102
rsi 0xb0184d84
rbp 0xb0184da0
rsp 0xb0184d90
r8 0x7fff5fbffb78
r9 0xffffffef
r10 0x7fff99d6382e
r11 0x7fff936ee168
r12 0x1603
r13 0x0
r14 0xb0185e20
r15 0xb0184e20
rip 0x726635
rflags 0x10206
cs 0x2b
fs 0x0
gs 0x0
Error: process exited with code 2.

go get install : 'FlattenAlphaChannel' undeclared (first use in this function)

Hello, my ImageMagick version shipped with Ubuntu is 6.6.9-7 and i got this error while trying to download the gographics/imagick library:

'FlattenAlphaChannel' undeclared (first use in this function)

I read in the (now) non-existing issue here that it it caused by the wrong ImageMagick version (my Go version is 1.3.1) so now i'm compiling ImageMagick from source following the instructions here:

http://askubuntu.com/questions/267746/how-can-i-install-the-latest-upstream-version-of-imagemagick-without-compiling

so when it's done, after "checkinstall" the newer version should reside in my /opt/ directory.

Now, from this point i don't know what to do next: how should i tell Go that it should use the newer version during compliation?

Any help will be much appreciated :-) I want to do my first steps in Go doing a project using gographics/imagick.

PS. Also, i read that "this is a CGO" binding, does it mean that i cannot use "go build" and have to use "cgo" compiler instead for the whole of my project ?

Interlace changes don't appear to be making it to output file or blob.

Hi there,

I tried everything I could think of to avoid creating an issue where none exists, but I'm currently at a loss as to whether, or not, this is, indeed, a bug. I apologize in advance for wasting your time in any way.

I'm attempting to change a non-progressive JPEG to a progressive JPEG, but the change does not seem to make it to the output.

Here's the code (image_resizing1.go):

package main

import (
    "github.com/bfitzsimmons/imagick/imagick"
)

func main() {
    const (
        original_filepath = "/Users/bfitzsimmons/Pictures/test/plant.jpg"
        output1           = "/Users/bfitzsimmons/Pictures/test/plant_1.jpg"
    )

    var (
        err       error
        new_width uint
    )

    // Set up imagick.
    imagick.Initialize()
    defer imagick.Terminate()

    mw := imagick.NewMagickWand()
    defer mw.Destroy()

    // Open and load the file.
    if err = mw.ReadImage(original_filepath); err != nil {
        panic(err)
    }

    // Get the width and height.
    width := mw.GetImageWidth()
    height := mw.GetImageHeight()
    ratio := float64(width) / float64(height)

    if width > 1000 {
        new_width = 1000
    } else {
        new_width = width
    }

    final_width := new_width
    final_height := int(float64(new_width) / ratio)

    // Set the quality.
    if err = mw.SetImageCompressionQuality(85); err != nil {
        panic(err)
    }

    if err = mw.SetImageInterlaceScheme(imagick.INTERLACE_LINE); err != nil {
        panic(err)
    }

    // Resize it.
    if err = mw.ResizeImage(uint(final_width), uint(final_height), imagick.FILTER_LANCZOS, 1); err != nil {
        panic(err)
    }

    // Write it out to a file.
    if err = mw.WriteImage(output1); err != nil {
        panic(err)
    }
}

Here's the output:

$ go run image_resizing1.go && identify -verbose /Users/bfitzsimmons/Pictures/test/plant_1.jpg | grep Interlace
  Interlace: None

Now, when I run the command line convert command I see the output I'm expecting:

$ convert /Users/bfitzsimmons/Pictures/test/plant.jpg -interlace Line /Users/bfitzsimmons/Pictures/test/plant_1.jpg && identify -verbose /Users/bfitzsimmons/Pictures/test/plant_1.jpg | grep Interlace
  Interlace: JPEG

Here's the version of ImageMagick installed on Mac OS X 10.9.2:

$ brew info imagemagick
imagemagick: stable 6.8.8-9 (bottled), HEAD
http://www.imagemagick.org
/usr/local/Cellar/imagemagick/6.8.8-9 (1429 files, 21M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/imagemagick.rb
==> Dependencies
Build: pkg-config ✔
Required: libtool ✔
Recommended: jpeg ✔, libpng ✔, freetype ✔
Optional: fontconfig ✘, libtiff ✘, little-cms ✘, little-cms2 ✘, jasper ✘, libwmf ✘, librsvg ✘, liblqr ✘, openexr ✘, ghostscript ✘, webp ✘

Am I looking at a bug in imagick, or am I doing something wrong?

Thanks, in advance, for any help on this (potential?) issue.

LockSemaphoreInfo: Assertion `semaphore_info != (SemaphoreInfo *) ((void *)0)' failed

gimg: magick/semaphore.c:339: LockSemaphoreInfo: Assertion `semaphore_info != (SemaphoreInfo *) ((void *)0)' failed.
SIGABRT: abort
PC=0x7f7fbb8e8425
signal arrived during cgo execution

goroutine 116 [syscall, locked to thread]:
runtime.cgocall_errno(0x418410, 0xc208161558, 0xc200000000)
/usr/local/go/src/runtime/cgocall.go:130 +0xf5 fp=0xc208161538 sp=0xc208161510
github.com/gographics/imagick/imagick._Cfunc_DestroyMagickWand(0x7f7fa0035ca0, 0x0)
/root/go/src/github.com/gographics/imagick/imagick/:680 +0x44 fp=0xc208161558 sp=0xc208161538
github.com/gographics/imagick/imagick.(_MagickWand).Destroy(0xc208038060)
/root/go/src/github.com/gographics/imagick/imagick/magick_wand.go:50 +0x3a fp=0xc208161570 sp=0xc208161558
github.com/Leon2012/gimg.(_ZSSDBStorage).InfoImage(0xc208038040, 0xc2080e3265, 0x20, 0xc2080e2900, 0x0, 0x0)
/root/go/src/github.com/Leon2012/gimg/zstorage_ssdb.go:174 +0x446 fp=0xc208161688 sp=0xc208161570
github.com/Leon2012/gimg.(_ZHttpd).doGet(0xc208054400, 0xc2080e3265, 0x20)
/root/go/src/github.com/Leon2012/gimg/zhttpd.go:175 +0x194 fp=0xc208161c48 sp=0xc208161688
github.com/Leon2012/gimg.(_ZHttpd).ServeHTTP(0xc208054400, 0x7f7fbca0a288, 0xc2080475e0, 0xc2080f8750)
/root/go/src/github.com/Leon2012/gimg/zhttpd.go:71 +0x2fa fp=0xc208161cb0 sp=0xc208161c48
net/http.serverHandler.ServeHTTP(0xc2080453e0, 0x7f7fbca0a288, 0xc2080475e0, 0xc2080f8750)
/usr/local/go/src/net/http/server.go:1703 +0x19a fp=0xc208161d08 sp=0xc208161cb0
net/http.(_conn).serve(0xc208046be0)
/usr/local/go/src/net/http/server.go:1204 +0xb57 fp=0xc208161fd8 sp=0xc208161d08
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc208161fe0 sp=0xc208161fd8
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1751 +0x35e

Compiling with HDRI support

First off, thanks a bunch for providing this Go binding to ImageMagick.
I'm trying to figure out my options for dealing with EXR image sources, and have been following the guides to first installing OpenEXR, and then compiling ImageMagick with hdri support.

When I install imagick, it is producing a compile error, complaining about "_QuantumRange"

Platform: OSX 10.7.5
go version go1.1.rc3 darwin/amd64

Hopefully this is not some OSX specific issue

ImageMagick configured with:

$ ./configure --enable-hdri --with-modules --with-dps --with-gvc --with-jp2 --with-png --with-openexr --with-freetype
$ pkg-config --cflags --libs MagickWand
-fopenmp -I/usr/local/include/ImageMagick -L/usr/local/lib -lMagickWand-Q16HDRI -lMagickCore-Q16HDRI 

$ go get -x -v -u github.com/gographics/imagick/imagick
...
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I-fopenmp -I/usr/local/include/ImageMagick -fopenmp -I/usr/local/include/ImageMagick -I $WORK/github.com/gographics/imagick/imagick/_obj/ -o $WORK/github.com/gographics/imagick/imagick/_obj/virtual_pixel_method.cgo2.o -c $WORK/github.com/gographics/imagick/imagick/_obj/virtual_pixel_method.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/github.com/gographics/imagick/imagick/_obj/_cgo_.o ... -I-L/usr/local/lib -lMagickWand-Q16HDRI -lMagickCore-Q16HDRI -L/usr/local/lib -lMagickCore-Q16HDRI -lMagickWand-Q16HDRI -lMagickCore-Q16HDRI
# github.com/gographics/imagick/imagick
Undefined symbols for architecture x86_64:
  "_QuantumRange", referenced from:
      __cgohack_QuantumRange in _cgo_main.o
     (maybe you meant: __cgohack_QuantumRange)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

If I following the errors properly, I seem to have the proper HDRI libs installed:

$ file /usr/local/lib/libMagickWand-Q16HDRI.7.dylib 
/usr/local/lib/libMagickWand-Q16HDRI.7.dylib: Mach-O 64-bit dynamically linked shared library x86_64

Hopefully you can offer some insight

fatal error: unexpected signal during runtime execution

golang app that resizes images
works fine with alone requests
but if i try to make several resizes quickly - got this:

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x7f276656096e pc=0x7f276656096e]

runtime stack:
runtime.throw(0x9d3f80, 0x2a)
/usr/local/go/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
/usr/local/go/src/runtime/sigpanic_unix.go:12 +0x5a

goroutine 19 [syscall, locked to thread]:
runtime.cgocall(0x7acee0, 0xc820044980, 0x0)
/usr/local/go/src/runtime/cgocall.go:120 +0x11b fp=0xc820044950 sp=0xc820044920
github.com/gographics/imagick/imagick._Cfunc_MagickReadImage(0x7f2760025a40, 0x7f2760027a90, 0x7f2700000000)
??:0 +0x35 fp=0xc820044980 sp=0xc820044950
github.com/gographics/imagick/imagick.(_MagickWand).ReadImage(0xc82014e020, 0xc820136177, 0x59, 0x0, 0x0)
/go/src/github.com/gographics/imagick/imagick/magick_wand_image.go:2165 +0x82 fp=0xc8200449b8 sp=0xc820044980
app/cropper.CropImage(0x7f2766e95bb0, 0xc8201442c0, 0xc82015a0e0)
/go/src/app/cropper/cropper.go:78 +0x7f9 fp=0xc820044b78 sp=0xc8200449b8
net/http.HandlerFunc.ServeHTTP(0xa0f958, 0x7f2766e95bb0, 0xc8201442c0, 0xc82015a0e0)
/usr/local/go/src/net/http/server.go:1422 +0x3a fp=0xc820044b98 sp=0xc820044b78
net/http.(_ServeMux).ServeHTTP(0xc82006f050, 0x7f2766e95bb0, 0xc8201442c0, 0xc82015a0e0)
/usr/local/go/src/net/http/server.go:1699 +0x17d fp=0xc820044bf0 sp=0xc820044b98
net/http.serverHandler.ServeHTTP(0xc820012480, 0x7f2766e95bb0, 0xc8201442c0, 0xc82015a0e0)
/usr/local/go/src/net/http/server.go:1862 +0x19e fp=0xc820044c50 sp=0xc820044bf0
net/http.(_conn).serve(0xc820144210)
/usr/local/go/src/net/http/server.go:1361 +0xbee fp=0xc820044fa8 sp=0xc820044c50
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1721 +0x1 fp=0xc820044fb0 sp=0xc820044fa8
created by net/http.(_Server).Serve
/usr/local/go/src/net/http/server.go:1910 +0x3f6

goroutine 1 [IO wait]:
net.runtime_pollWait(0x7f2766e95910, 0x72, 0xc82000a180)
/usr/local/go/src/runtime/netpoll.go:157 +0x60
net.(_pollDesc).Wait(0xc82006ca70, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:73 +0x3a
net.(_pollDesc).WaitRead(0xc82006ca70, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:78 +0x36
net.(_netFD).accept(0xc82006ca10, 0x0, 0x7f2766e95a08, 0xc820142240)
/usr/local/go/src/net/fd_unix.go:408 +0x27c
net.(_TCPListener).AcceptTCP(0xc820038098, 0x465f30, 0x0, 0x0)
/usr/local/go/src/net/tcpsock_posix.go:254 +0x4d
net/http.tcpKeepAliveListener.Accept(0xc820038098, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:2135 +0x41
net/http.(_Server).Serve(0xc820012480, 0x7f2766e959d0, 0xc820038098, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1887 +0xb3
net/http.(_Server).ListenAndServe(0xc820012480, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1877 +0x136
net/http.ListenAndServe(0xc82000bb00, 0x5, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:1967 +0x8f
main.main()
/go/src/app/main.go:50 +0x62f

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1721 +0x1

GetImagePixelColor method crash

When i call the method GetImagePixelColor, I 'll get a error:Assertion failed: (wand->signature == WandSignature), function PixelSetQuantumColor, file wand/pixel-wand.c, line 2193.
SIGABRT: abort
PC=0x7fff8d014866
signal arrived during cgo execution

it that a bug or something? here is my code :

func main() {

imagick.Initialize()
defer imagick.Terminate()

mw := imagick.NewMagickWand()
defer mw.Destroy()

pw := imagick.NewPixelWand()
defer pw.Destroy()
pw.SetColor("red")

mw.NewImage(50, 50, pw)
pw.SetColor("black")
mw.NewImage(50, 50, pw)
pw.SetColor("blue")
mw.NewImage(50, 50, pw)

mw.ResetIterator()

combine := mw.AppendImages(true)

combine.WriteImage("test.png")

target, _ := combine.GetImagePixelColor(1, 1)

pw.SetColor("blue")
combine.FloodfillPaintImage(imagick.CHANNELS_DEFAULT, pw, 1, target, 1, 1, false)
combine.WriteImage("test2.png")

}

Errors when not installing under /usr/local

Using MacOSX 10.8.4 / Go 1.1.2 Binary Package

I had to make changes to MagickWand.pc and MagickCore.pc files to get the package to build and install in a custom directory. CGO when it used the pkg-config files did not like the $MAGICK_HOME variable being in any of the paths. I had to replace the variable with the actual path string. The build would error saying it could not find the header files. I tripled checked the variable was set in the environment prior to running go build.

resize img , have a error

resize img , occur a error
Memory allocation failed `No such file or directory' @ fatal/tiff.c/UnregisterTIFFImage/2262.

deprecated warning and more than 5 minutes to start ?

$convert --version
Version: ImageMagick 6.9.0-3 Q16 x86_64 2015-01-09 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
Features: DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png xml zlib

go run bin/main.go

after 5 minutes show warning:

github.com/gographics/imagick/imagick

../../../lib/src/github.com/gographics/imagick/imagick/magick_core_env.go:54:23: warning: 'IsMagickInstantiated' is deprecated [-Wdeprecated-declarations]
/usr/local/Cellar/imagemagick/6.9.0-3/include/ImageMagick-6/magick/deprecate.h:205:3: note: 'IsMagickInstantiated' has been explicitly marked deprecated here

github.com/gographics/imagick/imagick

../../../lib/src/github.com/gographics/imagick/imagick/magick_wand_image.go:3014:23: warning: 'MagickRadialBlurImage' is deprecated [-Wdeprecated-declarations]
/usr/local/Cellar/imagemagick/6.9.0-3/include/ImageMagick-6/wand/deprecate.h:109:3: note: 'MagickRadialBlurImage' has been explicitly marked deprecated here
../../../lib/src/github.com/gographics/imagick/imagick/magick_wand_image.go:3031:23: warning: 'MagickRadialBlurImageChannel' is deprecated [-Wdeprecated-declarations]
/usr/local/Cellar/imagemagick/6.9.0-3/include/ImageMagick-6/wand/deprecate.h:111:3: note: 'MagickRadialBlurImageChannel' has been explicitly marked deprecated here

Vulnerability to "Biggest image in the smallest space"

You may have heard about the recent "attack" on image processing libraries and systems using them:
https://www.bamsoftware.com/hacks/deflate.html
https://news.ycombinator.com/item?id=10158529

I'm just wondering, if I'm using gographics/imagick package, how can I defend against this kind of attacks? How can I set resource limits? Looking at the docs, I've found ResourceType type, but I don't know how to use that to set the limits as I'm just learning Go. I'm using this library to resize and recompress user submitted images.

Static linking

I saw a note in the README about static linking imagick to libmagick, can you provide any additional information and/or examples?

Thanks!

Problem deleting exif:* property

I run this

props := img.GetImageProperties("")
fmt.Println(props)
for _, prop := range props {
    fmt.Println(prop, img.GetImageProperty(prop), img.DeleteImageProperty(prop))
}

for _, prop := range props {
    fmt.Println(prop, img.GetImageProperty(prop))
}

Where img is an MagickWand which the image source is an jpg and contains exif meta data (https://raw.githubusercontent.com/vanng822/imgscale/master/data/kth.jpg) , such as GPS

The code could delete other properties, such as comment, date:, jpg: but not exif:*

I use mac (version 10.10.1) and:
Version: ImageMagick 6.8.9-8 Q16 x86_64 2014-10-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg ltdl lzma png zlib

I guess this is an issue in ImageMagick?
StripImage removed everything as it should.

ImageMagick timeouts.

Hello,

I'm the maintainer of the PHP extension for Imagick. This is a slight 'drive by' giving of information, to give you guys a heads up about an issue that I encountered with using ImageMagick in a long-running process.

The original issue is here

The feature request for the ImageMagick guys to make it be not a problem is here:
https://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=29083&p=129885#p129885

Short version - any process that is using the ImageMagick library needs to restart more frequently than the "max image processing time" limit set in ImageMagick's config file.

Also, it would have been better to chose a different name for the binding.....that doesn't clash with another binding for another language.....I guess it's too late for that now though.

cheers
Dan

fail to build on mac !

$ pkg-config --cflags --libs MagickWand
DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/Cellar/imagemagick/6.9.0-3/include/ImageMagick-6 -L/usr/local/Cellar/imagemagick/6.9.0-3/lib -lMagickWand-6.Q16 -lMagickCore-6.Q16

$go get github.com/gographics/imagick/imagick

No output

$ GOOS=linux GOARCH=amd64 go build -o APP bin/main.go
./xx.go:399: undefined: imagick.Initialize
./xx.go:401: undefined: imagick.Terminate
./xx.go:404: undefined: imagick.NewMagickWand
./xx.go:431: undefined: imagick.FILTER_LANCZOS

but, i can run directly!
$ go run bin/main.go

Index slice out of bound while trying to composite image

lw.CompositeImage(mw, imagick.COMPOSITE_OP_OVER, int(offsetX), int(offsetY))

// mw width is 640, height 360
// lw width is 640, height 480
// offsetX is 0
// offsetY is 60
// the error is: panic: runtime error: slice bounds out of range

Am I doing something wrong or what?

Problem Build Go Program on Unbuntu

When I used -a on the build command go build -a everything built. Why do I need to use -a

I am back, sorry

I following all the instructions and build the C code and Go package. Everything worked, no errors.

Then I go to build my test program and I get

undefined: imagick.Initialize

I really hope you can help me because I have looked at everything

MagickWand CoalesceImages memory leak?

Hi, sorry to bother you again. I was doing some testing since one of my applications' memory footprint seemed quite large and discovered that when using MagickWand.CoalesceImages() the memory is never cleared after the wand is destroyed.

I'm running Arch Linux.

ImageMagick version

Version: ImageMagick 6.9.2-0 Q16 x86_64 2015-08-18 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP
Delegates (built-in): bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma pangocairo png ps rsvg tiff webp wmf x xml zlib

Memory Before and After

Memory before
Memory after
Also please bear in mind that this machine has about 16GB memory

Code used to test

package main

import (
  "fmt"
  "github.com/gographics/imagick/imagick"
  "net/http"
  _ "net/http/pprof"
)

func init() {
  imagick.Initialize()
  go func() {
    http.ListenAndServe(":6060", nil)
  }()
}

func main() {
  for i := 0; i < 500; i++ {
    mw := imagick.NewMagickWand()
    if err := mw.ReadImage("test.jpg"); err != nil {
      panic(err)
    }

    mw = mw.CoalesceImages()

    mw.Destroy()
  }
  fmt.Println("Complete")
  select {}
}

Am I doing something wrong or is this an issue?
Again, thanks for all the hard work! Sorry to bother you

Don't return error if action succeeded

I use IM primarily to convert tiffs. Libtiff (which imagemagick uses under the hood) will call its warning handler whenever it encounters a tag it doesn't recognize. Because tiff tags are just a free-for-all key-value store where every piece of software that's ever touched the file has dumped some info, that means it calls its warning handler pretty much every time.

That isn't a problem because it just skips those tags, finishes reading the file, everything is a-ok. But right now that means when using this lib I get an error during ReadFile...

So two issues.

First, we need a way for end users to figure out what the ExceptionType of an error is. We can make the user do type assertion from error to MagickWandException to get it, but it needs to be accessible. That's as easy as changing MagickWandException#kind to be public and documenting.

Second, anything that wraps a c api method that returns MagickBooleanType shouldn't return an error unless the api call returns false.

go get failed

/usr/bin/ld: skipping incompatible /usr/local/lib/libMagickWand-6.Q16.so when searching for -lMagickWand-6.Q16
/usr/bin/ld: skipping incompatible /usr/local/lib/libMagickWand-6.Q16.a when searching for -lMagickWand-6.Q16
/usr/bin/ld: skipping incompatible //usr/local/lib/libMagickWand-6.Q16.so when searching for -lMagickWand-6.Q16
/usr/bin/ld: skipping incompatible //usr/local/lib/libMagickWand-6.Q16.a when searching for -lMagickWand-6.Q16
/usr/bin/ld: cannot find -lMagickWand-6.Q16
/usr/bin/ld: skipping incompatible /usr/local/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible /usr/local/lib/libMagickCore-6.Q16.a when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible //usr/local/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible //usr/local/lib/libMagickCore-6.Q16.a when searching for -lMagickCore-6.Q16
/usr/bin/ld: cannot find -lMagickCore-6.Q16
collect2: error: ld returned 1 exit status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.