Example #1
0
File: gd.go Project: trajber/go-gd
func ImageToPngBuffer(p *Image) []byte {
	var imgSize int
	pimgSize := (*C.int)(Pointer(&imgSize))

	buf := C.gdImagePngPtr(p.img, pimgSize)
	defer C.gdFree(buf)

	return C.GoBytes(buf, *pimgSize)
}
Example #2
0
File: gd.go Project: trajber/go-gd
func ImageToJpegBuffer(p *Image, quality int) []byte {

	var imgSize int
	pimgSize := (*C.int)(Pointer(&imgSize))

	buf := C.gdImageJpegPtr(p.img, pimgSize, C.int(quality))
	defer C.gdFree(buf)

	return C.GoBytes(buf, *pimgSize)
}
Example #3
0
func (p *gdImage) gdImageGif() ([]byte, error) {
	if p == nil {
		panic(imageError)
	}

	var size C.int

	data := C.gdImageGifPtr(p.img, &size)
	if data == nil || int(size) == 0 {
		return []byte{}, writeError
	}

	defer C.gdFree(unsafe.Pointer(data))

	return C.GoBytes(data, size), nil
}
Example #4
0
func (p *gdImage) gdImageJpeg() ([]byte, error) {
	if p == nil {
		panic(imageError)
	}

	var size C.int

	// use -1 as quality, this will mean to use standard Jpeg quality
	data := C.gdImageJpegPtr(p.img, &size, 92)
	if data == nil || int(size) == 0 {
		return []byte{}, writeError
	}

	defer C.gdFree(unsafe.Pointer(data))

	return C.GoBytes(data, size), nil
}