mapnik.go
func Encode(img image.Image, format string) ([]byte, error) {
	tmp := toNRGBA(img)
	i := C.mapnik_image_from_raw(
		(*C.uint8_t)(unsafe.Pointer(&tmp.Pix[0])),
		C.int(tmp.Bounds().Dx()),
		C.int(tmp.Bounds().Dy()),
	)
	defer C.mapnik_image_free(i)

	cformat := C.CString(format)
	b := C.mapnik_image_to_blob(i, cformat)
	if b == nil {
		return nil, errors.New("mapnik: " + C.GoString(C.mapnik_image_last_error(i)))
	}
	C.free(unsafe.Pointer(cformat))
	defer C.mapnik_image_blob_free(b)
	return C.GoBytes(unsafe.Pointer(b.ptr), C.int(b.len)), nil
}
func Encode(img image.Image, format string) ([]byte, error) {
	tmp := toNRGBA(img)
	i := C.mapnik_image_from_raw(
		(*C.uint8_t)(unsafe.Pointer(&tmp.Pix[0])),
		C.int(tmp.Bounds().Dx()),
		C.int(tmp.Bounds().Dy()),
	)
	defer C.mapnik_image_free(i)

	cformat := C.CString(format)
	b := C.mapnik_image_to_blob(i, cformat)
	if b == nil {
		return nil, errors.New("mapnik: " + C.GoString(C.mapnik_image_last_error(i)))
	}
	C.free(unsafe.Pointer(cformat))
	defer C.mapnik_image_blob_free(b)
	return C.GoBytes(unsafe.Pointer(b.ptr), C.int(b.len)), nil
}
// Encode image.Image with Mapniks image encoder.
// This is optimized for *image.NRGBA or *image.RGBA.