Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Slightly more consistent API

  • Loading branch information...
commit 569046229702e4343900c53ebe3253e229c1a3e2 1 parent a7dc1e2
@tobi authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 gm.go
View
14 gm.go
@@ -82,17 +82,25 @@ func (img *Image) OpenBlob(bytes []byte) error {
return nil
}
-func (img *Image) Write(writer io.Writer) (int, error) {
+func (img *Image) SaveBlob() ([]byte, error) {
var len C.size_t
char_ptr := C.MagickWriteImageBlob(img.wand, &len)
if char_ptr == nil {
- return 0, img.exception()
+ return nil, img.exception()
}
defer C.free(unsafe.Pointer(char_ptr))
- bytes := C.GoBytes(unsafe.Pointer(char_ptr), C.int(len))
+ return C.GoBytes(unsafe.Pointer(char_ptr), C.int(len)), nil
+}
+
+func (img *Image) Write(writer io.Writer) (int, error) {
+ bytes, err := img.SaveBlob()
+
+ if err != nil {
+ return 0, img.exception()
+ }
return writer.Write(bytes)
}
Please sign in to comment.
Something went wrong with that request. Please try again.