Beispiel #1
0
// GifEncode encodes the Image as GIF using giflib
// rather than ImageMagick or GraphicksMagick. While this
// will result in a lower quality GIF, encoding is 9-10x
// faster and produces files ~20% smaller.
func (im *Image) GifEncode() ([]byte, error) {
	var size C.int
	var single C.int
	if im.parent != nil {
		single = 1
	}
	res := C.gif_encode(unsafe.Pointer(im.image), single, &size)
	if res != nil {
		p := unsafe.Pointer(res)
		b := C.GoBytes(p, size)
		C.free(p)
		return b, nil
	}
	return nil, errCouldNotEncodeGif
}
Beispiel #2
0
// GifEncode encodes the Image as GIF using giflib
// rather than ImageMagick or GraphicksMagick. While this
// will result in a lower quality GIF, encoding is 9-10x
// faster and produces files ~20% smaller.
func (im *Image) GifEncode() ([]byte, error) {
	if !im.coalesced {
		coalesced, err := im.Coalesce()
		if err != nil {
			return nil, err
		}
		coalesced.parent = im.parent
		defer coalesced.Dispose()
		im = coalesced
	}
	var size C.int
	var single C.int
	if im.parent != nil {
		single = 1
	}
	res := C.gif_encode(unsafe.Pointer(im.image), single, &size)
	if res != nil {
		p := unsafe.Pointer(res)
		b := C.GoBytes(p, size)
		C.free(p)
		return b, nil
	}
	return nil, errCouldNotEncodeGif
}