From 7f7bedb85829147d2e7f65136040bdfd526b6a11 Mon Sep 17 00:00:00 2001 From: Todd Date: Sun, 8 Jul 2018 17:26:24 -0500 Subject: [PATCH] document: fix non-PNG image support Fixes #188 --- document/document.go | 3 ++- presentation/presentation.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/document/document.go b/document/document.go index ac113167..8fde6dbb 100644 --- a/document/document.go +++ b/document/document.go @@ -16,6 +16,7 @@ import ( "io" "io/ioutil" "os" + "strings" "baliance.com/gooxml" "baliance.com/gooxml/common" @@ -233,7 +234,7 @@ func (d *Document) Save(w io.Writer) error { } for i, img := range d.Images { - fn := fmt.Sprintf("word/media/image%d.png", i+1) + fn := fmt.Sprintf("word/media/image%d.%s", i+1, strings.ToLower(img.Format())) if img.Path() != "" { if err := zippkg.AddFileFromDisk(z, fn, img.Path()); err != nil { return err diff --git a/presentation/presentation.go b/presentation/presentation.go index 50f463fa..95b9b59b 100644 --- a/presentation/presentation.go +++ b/presentation/presentation.go @@ -19,6 +19,7 @@ import ( "log" "os" "path" + "strings" "baliance.com/gooxml" "baliance.com/gooxml/common" @@ -440,6 +441,7 @@ func (p *Presentation) Save(w io.Writer) error { for i, img := range p.Images { fn := gooxml.AbsoluteFilename(gooxml.DocTypePresentation, gooxml.ImageType, i+1) + fn = fn[0:len(fn)-3] + strings.ToLower(img.Format()) if img.Path() != "" { if err := zippkg.AddFileFromDisk(z, fn, img.Path()); err != nil { return err