Skip to content
Browse files

Switched to ImageMagick...

  • Loading branch information...
1 parent bd58575 commit 31b14a4a8df54f9afde1e9d10cc119f6f28056cd @tobi committed May 3, 2012
Showing with 23 additions and 37 deletions.
  1. BIN example/image.png
  2. +16 −22 example/test.go
  3. +7 −11 image.go
  4. +0 −4 image_test.go
View
BIN example/image.png
Deleted file not rendered
View
38 example/test.go
@@ -1,36 +1,30 @@
package main
import (
- "io/ioutil"
+ "fmt"
"github.com/tobi/mogrify-go"
)
-// func Server(w http.ResponseWriter, r *http.Request) {
-// }
-
-func init() {
- mogrify.Init()
-}
-
func main() {
-
- img := mogrify.NewImage()
- defer img.Destroy()
- bytes, _ := ioutil.ReadFile("image.png")
-
- defer print("\n")
-
- err := img.OpenBlob(bytes)
+ img := mogrify.NewImage()
+ defer img.Destroy()
+
+ if err := img.OpenFile("../assets/example.com.png"); err != nil {
+ panic(err.Error())
+ }
+ fmt.Printf("Image dimensions: %s\n", img.Dimensions())
+
+ resized, err := img.NewTransformation("", "100x75>")
+
if err != nil {
- print("error ")
- print(err.Error())
- return
+ panic(err.Error())
}
+ defer resized.Destroy()
- print(img.Dimensions())
+ fmt.Printf("Resized image dimensions: %s\n", resized.Dimensions())
+
+ resized.SaveFile("/tmp/image.png")
-
-
}
View
18 image.go
@@ -1,7 +1,7 @@
package mogrify
-// #cgo CFLAGS: -I/usr/local/include/GraphicsMagick
-// #cgo LDFLAGS: -fopenmp -lGraphicsMagickWand -lGraphicsMagick
+// #cgo CFLAGS: -fopenmp -I/usr/local/include/ImageMagick -I/usr/include/ImageMagick
+// #cgo LDFLAGS: -lMagickWand -lMagickCore
// #include <wand/magick_wand.h>
import "C"
@@ -28,10 +28,6 @@ type ImageError struct {
severity int
}
-func Init() {
- C.InitializeMagick(nil)
-}
-
func (e *ImageError) Error() string {
return fmt.Sprintf("GraphicsMagick: %s severity: %d", e.message, e.severity)
}
@@ -93,17 +89,17 @@ func (img *Image) OpenBlob(bytes []byte) error {
return BlobEmpty
}
- status := C.MagickReadImageBlob(img.wand, (*C.uchar)(unsafe.Pointer(&bytes[0])), C.size_t(len(bytes)))
+ status := C.MagickReadImageBlob(img.wand, unsafe.Pointer(&bytes[0]), C.size_t(len(bytes)))
if status == C.MagickFalse {
return img.error()
}
return nil
}
-func (img *Image) SaveBlob() ([]byte, error) {
+func (img *Image) Blob() ([]byte, error) {
var len C.size_t
- char_ptr := C.MagickWriteImageBlob(img.wand, &len)
+ char_ptr := C.MagickGetImageBlob(img.wand, &len)
if char_ptr == nil {
return nil, img.error()
@@ -115,7 +111,7 @@ func (img *Image) SaveBlob() ([]byte, error) {
}
func (img *Image) Write(writer io.Writer) (int, error) {
- bytes, err := img.SaveBlob()
+ bytes, err := img.Blob()
if err != nil {
return 0, img.error()
@@ -125,7 +121,7 @@ func (img *Image) Write(writer io.Writer) (int, error) {
}
func (img *Image) Resize(width, height uint) error {
- res := C.MagickResizeImage(img.wand, C.ulong(width), C.ulong(height), C.GaussianFilter, 1)
+ res := C.MagickResizeImage(img.wand, C.size_t(width), C.size_t(height), C.GaussianFilter, 1)
if res == C.MagickFalse {
return img.error()
View
4 image_test.go
@@ -7,10 +7,6 @@ import (
"testing"
)
-func init() {
- Init()
-}
-
func assertDimension(t *testing.T, img *Image, expected string) {
if actual := img.Dimensions(); actual != expected {

0 comments on commit 31b14a4

Please sign in to comment.
Something went wrong with that request. Please try again.