1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# :foggy: Image2ascii
[![Build Status](https://travis-ci.org/qeesung/image2ascii.svg?branch=master)](https://travis-ci.org/qeesung/image2ascii)
[![Coverage Status](https://coveralls.io/repos/github/qeesung/image2ascii/badge.svg?branch=master)](https://coveralls.io/github/qeesung/image2ascii?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/71a3059b49274dde9d81d58cedd80962)](https://app.codacy.com/app/qeesung/image2ascii?utm_source=github.com&utm_medium=referral&utm_content=qeesung/image2ascii&utm_campaign=Badge_Grade_Dashboard)
[![Go Report Card](https://goreportcard.com/badge/github.com/qeesung/image2ascii)](https://goreportcard.com/report/github.com/qeesung/image2ascii)
[![GoDoc](https://godoc.org/github.com/qeesung/image2ascii?status.svg)](https://godoc.org/github.com/qeesung/image2ascii)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Image2ASCII is a library that converts images into ASCII images and provides command-line tools for easy use.
![demo](https://github.com/qeesung/image2ascii/blob/master/docs/images/lufei.gif?raw=true)
## Installation
```bash
go get github.com/qeesung/image2ascii
```
## CLI usage
```bash
image2ascii version: image2ascii/1.0.0
>> HomePage: https://github.com/qeesung/image2ascii
>> Issue : https://github.com/qeesung/image2ascii/issues
>> Author : qeesung
Usage: image2ascii [-s] -f <filename> -r <ratio> -w <width> -g <height>
Options:
-c Colored the ascii when output to the terminal (default true)
-f string
Image filename to be convert
-g int
Expected image height, -1 for image default height (default -1)
-r float
Ratio to scale the image, ignored when use -w or -g (default 1)
-s Fit the terminal screen, ignored when use -w, -g, -r (default true)
-w int
Expected image width, -1 for image default width (default -1)
```
convert the image to ascii image with fixed width and height
```bash
# width: 100
# height: 30
image2ascii -f docs/images/baozou.jpg -w 100 -g 30
```
![demo](https://github.com/qeesung/image2ascii/blob/master/docs/images/baozou.gif?raw=true)
convert the image to ascii image by ratio
```bash
# ratio: 0.3
# width: imageWidth * 0.3
# height: imageHeight * 0.3
image2ascii -f docs/images/pikaqiu.jpg -r 0.3
```
![demo](https://github.com/qeesung/image2ascii/blob/master/docs/images/pikaqiu.gif?raw=true)
convert the image to ascii fit the screen
```bash
image2ascii -f docs/images/lufei.jpg -s
```
convert the image without the color
```bash
image2ascii -f docs/images/lufei.jpg -s -c=false
```
convert the image disable fit the screen
```bash
image2ascii -f docs/images/lufei.jpg -s=false
```
## Library usage
```golang
package main
import (
"fmt"
"github.com/qeesung/image2ascii/convert"
_ "image/jpeg"
_ "image/png"
)
func main() {
fmt.Print(convert.ImageFile2ASCIIString("docs/images/baozou.jpg", &convert.Options{
Ratio: 0.5,
}))
}
```
convert options
```golang
type Options struct {
Ratio float64 . // Scale Ratio
ExpectedWidth int // Convert the image with fixed width
ExpectedHeight int // Convert the image with fixed height
FitScreen bool // Scale the image to fit the tereminal screen
Colored bool // if convert the image to colored ascii
}
```
supported convert function
```golang
// convert a image object to ascii matrix
func Image2ASCIIMatrix(image image.Image, imageConvertOptions *Options) []string {}
// convert a image object to ascii matrix and then join the matrix to a string
func Image2ASCIIString(image image.Image, options *Options) string {}
// convert a image object by input a string to ascii matrix then join the matrix to a string
func ImageFile2ASCIIString(imageFilename string, option *Options) string {}
```
## Sample outputs
| Raw Image | ASCII Image |
|:-----------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------:|
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/lufei.jpg) | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/lufei_ascii.png) |
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/lufei.jpg) | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/lufei_ascii_colored.png) |
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/pikaqiu.jpeg) | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/pikaqiu_ascii.png) |
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/pikaqiu.jpeg) | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/pikaqiu_ascii_colored.png) |
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/baozou.jpg) | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/baozou_ascii.png) |
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/baozou.jpg) | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/docs/images/baozou_ascii_colored.png) |
## License
This project is under the MIT License. See the [LICENSE](https://github.com/qeesung/image2ascii/blob/master/LICENSE) file for the full license text.