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) }
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) }
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 }
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 }