document: fix non-PNG image support

Fixes #188
This commit is contained in:
Todd 2018-07-08 17:26:24 -05:00
parent a78d579d58
commit 7f7bedb858
2 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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