~dricottone/image2ascii

ref: 80cd2b553b0a44ef00114d715cec803559bf936a image2ascii/README.md -rw-r--r-- 3.7 KiB
80cd2b55Dominic Ricottone Merging branch 'log-more-helpfully' from mjip/PR #22 2 years ago
                                                                                
89d4360b 秦世成
27569433 秦世成
accafd8d 秦世成
448b1ed9 qeesung
93fe9ac7 qeesung
448b1ed9 qeesung
448b1ed9 qeesung
93fe9ac7 qeesung
6e96550b 秦世成
b1f7b10d qeesung
6e96550b 秦世成
cc4686e7 秦世成
6e96550b 秦世成
9766b846 秦世成
6e96550b 秦世成
cc4686e7 秦世成
6e96550b 秦世成
8637a990 qeesung
6e96550b 秦世成
12b91cad qeesung
6e96550b 秦世成
ef8457e1 秦世成
6e96550b 秦世成
12b91cad qeesung
6e96550b 秦世成
ef8457e1 秦世成
8637a990 qeesung
6e96550b 秦世成
8637a990 qeesung
6e96550b 秦世成
b1f7b10d qeesung
12b91cad qeesung
b1f7b10d qeesung
12b91cad qeesung
b1f7b10d qeesung
6e96550b 秦世成
0048ecc6 秦世成
93fe9ac7 qeesung
448b1ed9 qeesung
448b1ed9 qeesung
2f0a0c7d 秦世成
25fbdcc7 秦世成
2f0a0c7d 秦世成
448b1ed9 qeesung
525a85ee 秦世成
25fbdcc7 秦世成
525a85ee 秦世成
5435fd05 秦世成
22ac3f41 秦世成
5435fd05 秦世成
22ac3f41 秦世成
5435fd05 秦世成
22ac3f41 秦世成
5435fd05 秦世成
22ac3f41 秦世成
5435fd05 秦世成
525a85ee 秦世成
5f684178 秦世成
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
135
# Image2ascii

Image2ASCII is a library that converts images into ASCII images and provides command-line tools for easy use.

I forked this repository to port it from Dep to Go Modules.

See demos hosted [in the upstream repository](https://github.com/qeesung/image2ascii/blob/master/docs/images/).

## Installation

```bash
git clone https://git.dominic-ricottone.com/~dricottone/image2ascii
make build
sudo make install
```

## 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 (default "docs/images/lufei.jpg")
  -g int
        Expected image height, -1 for image default height (default -1)
  -i    Reversed the ascii when output to the terminal
  -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)
  -t    Stretch the picture to overspread the screen
  -w int
        Expected image width, -1 for image default width (default -1)
```

convert the image fit the screen(default is true)
```bash
image2ascii -f docs/images/pikaqiu2.jpg
```

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
```

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
```

convert the image to stretch the screen
```bash
image2ascii -f docs/images/long.jpg -t
```

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
```

convert the image reverse the chars
```bash
image2ascii -f docs/images/lufei.jpg -i
```

## Library usage

```golang
package main

import (
	"fmt"
	"git.dominic-ricottone.com/~dricottone/image2ascii/convert"
	_ "image/jpeg"
	_ "image/png"
)

func main() {
	// Create convert options
	convertOptions := convert.DefaultOptions
	convertOptions.FixedWidth = 100
	convertOptions.FixedHeight = 40

	// Create the image converter
	converter := convert.NewImageConverter()
	fmt.Print(converter.ImageFile2ASCIIString(imageFilename, &convertOptions))
}
```

convert options

```golang
type Options struct {
	Ratio           float64 // convert ratio
	FixedWidth      int  // convert the image width fixed width
	FixedHeight     int  // convert the image width fixed height
	FitScreen       bool // only work on terminal, fit the terminal height or width
	StretchedScreen bool // only work on terminal, stretch the width and heigh to overspread the terminal screen
	Colored         bool // only work on terminal, output ascii with color
	Reversed        bool // if reverse the ascii pixels
}
```

supported convert function
```golang
type Converter interface {
	// convert a image object to ascii matrix
	Image2ASCIIMatrix(image image.Image, imageConvertOptions *Options) []string
	// convert a image object to ascii matrix and then join the matrix to a string
	Image2ASCIIString(image image.Image, options *Options) string
	// convert a image object by input a string to ascii matrix
	ImageFile2ASCIIMatrix(imageFilename string, option *Options) []string
	// convert a image object by input a string to ascii matrix then join the matrix to a string
	ImageFile2ASCIIString(imageFilename string, option *Options) string
}
```

## License

This project is under the MIT License. See the LICENSE file for the full license text.