~dricottone/image2ascii

bc12009269bd9cb001140d5fc903d01740b83620 — qeesung 6 years ago 435f20f
add new method to convert a image from filename directly
2 files changed, 23 insertions(+), 20 deletions(-)

M README.md
M convert/convert.go
M README.md => README.md +3 -18
@@ 16,29 16,14 @@ package main
import (
	"fmt"
	"github.com/qeesung/image2ascii/convert"
	"image"
	_ "image/jpeg"
	_ "image/png"
	"log"
	"os"
)

func main() {
	f, err := os.Open("example/images/lufei.jpg")
	if err != nil {
		log.Fatal(err)
	}

	img, _, err := image.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	f.Close()
	asciiImage := convert.Image2ASCIIString(img, &convert.Options{
		Ratio: 0.2,
	})
	fmt.Print(asciiImage)
	fmt.Print(convert.ImageFile2ASCIIString("example/images/baozou.jpg", &convert.Options{
		Ratio: 0.5,
	}))
}
```


M convert/convert.go => convert/convert.go +20 -2
@@ 3,10 3,12 @@ package convert

import (
	"bytes"
	"github.com/qeesung/image2asicc/ascii"
	"github.com/qeesung/image2asicc/resize"
	"github.com/qeesung/image2ascii/ascii"
	"github.com/qeesung/image2ascii/resize"
	"image"
	"image/color"
	"log"
	"os"
)

type Options struct {


@@ 45,3 47,19 @@ func Image2ASCIIString(image image.Image, options *Options) string {
	}
	return buffer.String()
}

// Convert a image file to ascii string
func ImageFile2ASCIIString(imageFilename string, option *Options) string {
	f, err := os.Open(imageFilename)
	if err != nil {
		log.Fatal(err)
	}

	img, _, err := image.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	f.Close()
	return Image2ASCIIString(img, option)
}