Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: flatten gif animations #12

Open
technoweenie opened this issue Nov 10, 2014 · 0 comments
Open

feature request: flatten gif animations #12

technoweenie opened this issue Nov 10, 2014 · 0 comments

Comments

@technoweenie
Copy link

Flattening GIF animations is heresy, I know. It was a difficult choice for our avatar system :)

I have a local PR where I tried implementing it in Go, but it blew up when trying to call C.WriteImages() in ToFile():

Assertion failed: (images->signature == MagickSignature), function WriteImages, file magick/constitute.c, line 1340.
diff --git a/magick.go b/magick.go
index 6a5a3b2..8bf45e3 100644
--- a/magick.go
+++ b/magick.go
@@ -458,6 +458,10 @@ func (im *MagickImage) Strip() (err error) {
        return
 }

+func (im *MagickImage) Flatten() {
+       im.ReplaceImage(C.GetFirstImageInList(im.Image))
+}
+
 // ToBlob takes a (transformed) MagickImage and returns a byte slice in the format you specify with extension.
 // Magick uses the extension to transform the image in to the proper encoding (e.g. "jpg", "png")
 func (im *MagickImage) ToBlob(extension string) (blob []byte, err error) {
diff --git a/magick_test.go b/magick_test.go
index ab11620..77ed59f 100644
--- a/magick_test.go
+++ b/magick_test.go
@@ -196,6 +196,19 @@ func TestNegateImage(t *testing.T) {
        assert.T(t, image != nil)
 }

+func TestFlattenImage(t *testing.T) {
+       filename := "test/test_animated.gif"
+       image, error := NewFromFile(filename)
+       assert.T(t, error == nil)
+       assert.T(t, image != nil)
+       assert.T(t, image.Image != nil)
+       assert.T(t, image.ImageInfo != nil)
+       image.Flatten()
+
+       err := image.ToFile("test/test_out2.gif")
+       assert.T(t, err == nil)
+}
+
 func TestToBlob(t *testing.T) {
        image := setupImage(t)
        bytes, err := image.ToBlob("png")

We solve this now by adding [0] to the input file name in the convert args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant