Exemplo n.º 1
0
Arquivo: gd.go Projeto: 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)
}
Exemplo n.º 2
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
}