99f753c2d83958a4e7cf0f13a928139815bc1687
1 package be
.nikiroo
.utils
.main
;
3 import java
.awt
.Dimension
;
4 import java
.awt
.image
.BufferedImage
;
6 import java
.io
.FileInputStream
;
7 import java
.io
.IOException
;
8 import java
.io
.InputStream
;
9 import java
.util
.ArrayList
;
10 import java
.util
.List
;
12 import be
.nikiroo
.utils
.IOUtils
;
13 import be
.nikiroo
.utils
.Image
;
14 import be
.nikiroo
.utils
.ui
.ImageTextAwt
;
15 import be
.nikiroo
.utils
.ui
.ImageTextAwt
.Mode
;
16 import be
.nikiroo
.utils
.ui
.ImageUtilsAwt
;
18 public class StartImageUtils
{
20 * ImageUtils main entry point.
26 public static void main(String
[] args
) {
27 Dimension size
= null;
29 boolean invert
= false;
30 List
<String
> inputs
= new ArrayList
<String
>();
38 for (String arg
: args
) {
41 if (arg
.startsWith("--mode=")) {
42 mode
= Mode
.valueOf(arg
.substring("--mode=".length()));
43 } else if (arg
.startsWith("--width=")) {
45 .parseInt(arg
.substring("--width=".length()));
46 } else if (arg
.startsWith("--height=")) {
47 height
= Integer
.parseInt(arg
.substring("--height="
49 } else if (arg
.startsWith("--size=")) {
50 String content
= arg
.substring("--size=".length())
52 width
= Integer
.parseInt(content
.split("x")[0]);
53 height
= Integer
.parseInt(content
.split("x")[1]);
54 } else if (arg
.startsWith("--ouput=")) {
55 if (!arg
.equals("--output=-")) {
56 output
= new File(arg
.substring("--output=".length()));
58 } else if (arg
.equals("--invert")) {
60 } else if (arg
.equals("--help")) {
62 .println("Syntax: (--mode=MODE) (--width=WIDTH) (--height=HEIGHT) (--size=SIZE) (--output=OUTPUT) (--invert) (--help)");
63 System
.out
.println("\t --help: will show this screen");
65 .println("\t --invert: will invert the 'colours'");
67 .println("\t --mode: will select the rendering mode (default: ASCII):");
69 .println("\t\t ASCII: ASCI output mode, that is, characters \" .-+=o8#\"");
71 .println("\t\t DITHERING: Use 5 different \"colours\" which are actually"
72 + "\n\t\t Unicode characters \" ░▒▓█\"");
74 .println("\t\t DOUBLE_RESOLUTION: Use \"block\" Unicode characters up to quarter"
75 + "\n\t\t blocks, thus in effect doubling the resolution both in vertical"
76 + "\n\t\t and horizontal space."
77 + "\n\t\t Note that since 2 characters next to each other are square,"
78 + "\n\t\t 4 blocks per 2 blocks for w/h resolution.");
80 .println("\t\t DOUBLE_DITHERING: Use characters from both DOUBLE_RESOLUTION"
81 + "\n\t\t and DITHERING");
88 size
= new Dimension(width
, height
);
89 if (inputs
.size() == 0) {
90 inputs
.add("-"); // by default, stdin
92 } catch (Exception e
) {
93 System
.err
.println("Syntax error: \"" + lastArg
+ "\" is invalid");
102 for (String input
: inputs
) {
103 InputStream in
= null;
106 if (input
.equals("-")) {
109 in
= new FileInputStream(input
);
111 BufferedImage image
= ImageUtilsAwt
112 .fromImage(new Image(in
));
113 ImageTextAwt img
= new ImageTextAwt(image
, size
, mode
,
115 if (output
== null) {
116 System
.out
.println(img
.getText());
118 IOUtils
.writeSmallFile(output
, img
.getText());
121 if (!input
.equals("-")) {
126 } catch (IOException e
) {