forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add images from bytes for presentation and workbook (unidoc#295)
- Loading branch information
Showing
5 changed files
with
41 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package common | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/unidoc/unioffice" | ||
"github.com/unidoc/unioffice/zippkg" | ||
) | ||
|
||
// AddImageToZip adds an image (either from bytes or from disk) and adds it to the zip file. | ||
func AddImageToZip(z *zip.Writer, img ImageRef, imageNum int, dt unioffice.DocType) error { | ||
filename := unioffice.AbsoluteImageFilename(dt, imageNum, strings.ToLower(img.Format())) | ||
if img.Data() != nil && len(*img.Data()) > 0 { | ||
if err := zippkg.AddFileFromBytes(z, filename, *img.Data()); err != nil { | ||
return err | ||
} | ||
} else if img.Path() != "" { | ||
if err := zippkg.AddFileFromDisk(z, filename, img.Path()); err != nil { | ||
return err | ||
} | ||
} else { | ||
return fmt.Errorf("unsupported image source: %+v", img) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters