aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-09-09 09:42:37 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-09-09 09:42:37 +0200
commit500caaeda74dd9c660279036293f4b2997cf0b03 (patch)
tree1226f60231a408b0aae67867faaa3f2cfbac8c83 /vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go
parent413560591fc2d89a73eb8a33ba28b0cc3407b1db (diff)
Add vendor
Diffstat (limited to 'vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go')
-rw-r--r--vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go b/vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go
new file mode 100644
index 0000000..b6dccb9
--- /dev/null
+++ b/vendor/github.com/llgcode/draw2d/draw2dimg/fileutil.go
@@ -0,0 +1,46 @@
+package draw2dimg
+
+import (
+ "bufio"
+ "image"
+ "image/png"
+ "os"
+)
+
+// SaveToPngFile create and save an image to a file using PNG format
+func SaveToPngFile(filePath string, m image.Image) error {
+ // Create the file
+ f, err := os.Create(filePath)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ // Create Writer from file
+ b := bufio.NewWriter(f)
+ // Write the image into the buffer
+ err = png.Encode(b, m)
+ if err != nil {
+ return err
+ }
+ err = b.Flush()
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+// LoadFromPngFile Open a png file
+func LoadFromPngFile(filePath string) (image.Image, error) {
+ // Open file
+ f, err := os.OpenFile(filePath, 0, 0)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ b := bufio.NewReader(f)
+ img, err := png.Decode(b)
+ if err != nil {
+ return nil, err
+ }
+ return img, nil
+}