~dricottone/image2ascii

ref: 9eb7ba1c157d1d9f2043791ca9c7165137b1d8b6 image2ascii/README.md -rw-r--r-- 2.7 KiB
9eb7ba1c — qeesung add colored images 6 years ago
                                                                                
9330e7cf 秦世成
aabae983 qeesung
17a11481 qeesung
448b1ed9 qeesung
6e96550b 秦世成
448b1ed9 qeesung
427a0f9e 秦世成
448b1ed9 qeesung
bc120092 qeesung
448b1ed9 qeesung
427a0f9e 秦世成
9eb7ba1c qeesung
4baed2ab 秦世成
9eb7ba1c qeesung
435f20fa 秦世成
9eb7ba1c qeesung
d8483baf 秦世成
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
# :foggy:image2ascii

Convert image to ASCII

## installation

```bash
go get https://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:
  -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 example/images/lufei.jpg -w 100 -g 30
```

convert the image to ascii image by ratio
```bash
# ratio: 0.3
# width: imageWidth * 0.3
# height: imageHeight * 0.3
image2ascii -f example/images/lufei.jpg -r 0.3
```

convert the image to ascii fit the screen
```bash
image2ascii -f example/images/lufei.jpg -s
```


## library usage

```golang
package main

import (
	"fmt"
	"github.com/qeesung/image2ascii/convert"
	_ "image/jpeg"
	_ "image/png"
)

func main() {
	fmt.Print(convert.ImageFile2ASCIIString("example/images/baozou.jpg", &convert.Options{
		Ratio: 0.5,
	}))
}
```

## example outputs

| Raw Image         | ASCII Image           |
| ------------- |:-------------:| 
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/lufei.jpg)      | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/lufei_ascii.png) |
| ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/lufei.jpg)      | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/lufei_ascii_colored.png) |
 ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/pikaqiu.jpeg)      | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/pikaqiu_ascii.png) |
 ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/pikaqiu.jpeg)      | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/pikaqiu_ascii_colored.png) |
  ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/baozou.jpg)      | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/baozou_ascii.png) |
  ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/baozou.jpg)      | ![](https://raw.githubusercontent.com/qeesung/image2ascii/master/example/images/baozou_ascii_colored.png) |