Skip to content

Commit

Permalink
Merge pull request #12 from seujorgenochurras/develop
Browse files Browse the repository at this point in the history
Release 0.0.3
  • Loading branch information
seujorgenochurras authored Feb 19, 2024
2 parents 5a62663 + 11fa309 commit a7f446f
Show file tree
Hide file tree
Showing 43 changed files with 959 additions and 255 deletions.
87 changes: 46 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

# image-to-ascii

image-to-ascii is a java image to ascii art parser, as the name implies, it generates an ASCII art from any image.<br>
It is highly configurable but at the same time easy to use.


## Results

<div>
Expand All @@ -20,12 +18,13 @@ It is highly configurable but at the same time easy to use.
<br>

# Download

Gradle:

```gradle
dependencies {
implementation ("io.github.seujorgenochurras:image-to-ascii:0.0.2")
implementation ("io.github.seujorgenochurras:image-to-ascii:0.0.3")
}
```
Expand All @@ -35,78 +34,84 @@ Maven:
```xml

<dependency>
<groupId>io.github.seujorgenochurras</groupId>
<artifactId>image-to-ascii</artifactId>
<version>0.0.2</version>
<groupId>io.github.seujorgenochurras</groupId>
<artifactId>image-to-ascii</artifactId>
<version>0.0.3</version>
</dependency>

```

[JPM](https://github.com/seujorgenochurras/Jhey-Package-Manager):

``jpm -i=io.github.seujorgenochurras.image-to-ascii``
``jpm -i=io.github.seujorgenochurras.image-to-ascii``

⚠️ NOT RECOMMENDED ⚠️ [JPM](https://github.com/seujorgenochurras/Jhey-Package-Manager) has a whole lots of bugs
and it'll probably give you a massive headache.<br>
This is here because I worked hard (and badly) on it,
if you liked the idea please let me know somehow.

⚠️ NOT RECOMMENDED ⚠️ [JPM](https://github.com/seujorgenochurras/Jhey-Package-Manager) has a whole lots of bugs
and it'll probably give you a massive headache.<br>
This is here because I worked hard (and badly) on it,
if you liked the idea please let me know somehow.

# Usage

Since the parser is highly configurabe it might be really annoying to use.
So if you are in a hurry or you just don't want to read the code you can use the `DefaultParserConfig`.
Since the parser is highly configurable it might be really annoying to use.
So if you are in a hurry, or you just don't want to read the code you can use the `DefaultParserConfig`.

```java
String imagePath = "smth/somewhere/yourImageFilePath";
String imagePath="smth/somewhere/yourImageFilePath";

String imageAsciiArt = DefaultAsciifier.toAscii(imagePath, height, width, withAnsiColor);
String imageAsciiArt=DefaultAsciifier.toAscii(imagePath,height,width,withAnsiColor);

FileWriter fileWriter = new FileWriter("myAsciiArt.txt");
fileWriter.write(imageAsciiArt);
fileWriter.flush();
FileWriter fileWriter=new FileWriter("myAsciiArt.txt");
fileWriter.write(imageAsciiArt);
fileWriter.flush();

```

<br>

## Configurations
## Configurations

If you want to configure more stuff such as the core algorithms, you can do it with the `ParserConfig` : <br>

```java

String[] symbols = {" ", ".", "-", "I", "W", "@"};
String[]symbols={" ",".","-","I","W","@"};

ParserConfig parserConfig = ParserBuilder.startBuild()
.parserAlgorithm(Algorithms.HUMAN_EYE_ALGORITHM)
.scaled()
.height(30)
.width(80)
.getScale()
.symbols(symbols)
.withColor(new AnsiColorAlgorithm())
.build();
ParserConfig parserConfig=ParserBuilder.startBuild()
.parserAlgorithm(Algorithms.HUMAN_EYE_ALGORITHM)
.scaled()
.height(30)
.width(80)
.getScale()
.symbols(symbols)
.withColor(new AnsiColorAlgorithm())
.build();

String asciiArt = AsciiParser.parse(imagePath, parserConfig);
String asciiArt=AsciiParser.parse(imagePath,parserConfig);

```

As you can see, there're lots of different configurations for your ASCII art, I'll list some of the most important stuff here:<br>
- parserAlgorithm
- This is the algorithm that defines how to deal with brightness, basically speaking the HUMAN_EYE_ALGORITHM is the best for humans
- scaled
As you can see, there are lots of different configurations for your ASCII art, I'll list some of the most important
stuff here:<br>

- parserAlgorithm
- This is the algorithm that defines how to deal with brightness, basically speaking the HUMAN_EYE_ALGORITHM is the
best for humans
- scaled
- This is where you define if you want to scale down (or up) your image
- symbols
- Symbols to use in the ASCII art from darkest to brightest, you can use `symbolPatternFinder` to automatically generate symbols in ""perfect"" order
- symbols
- Symbols to use in the ASCII art from darkest to brightest, you can use `symbolPatternFinder` to automatically
generate symbols in ""perfect"" order

```java

String[] unorderedSymbols = StringUtils.getUTFChars(32, 132);
String[] symbols = BestSymbolPatternFinder.findBestPattern(totalSymbols, unorderedSymbols).toArray();

```
- withColor

- withColor
- This is the color algorithm, yes you read it right, we have colors.<br>
More specifically ANSI colors, if you have no idea what ANSI is,
it is basically a standard on most of terminals that allows you to make some pretty awesome stuff, like playing videos with characters on your terminal or even colorize them.<br>
it is basically a standard on most of the terminals that allows you to make some pretty awesome stuff, like
playing videos with characters on your terminal or even colorize them.<br>
for now there are only 2 colored algorithms, the normal ANSI and the ANSI with tones
14 changes: 13 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("java")
id("maven-publish")
id("signing")
jacoco
}
repositories {
mavenCentral()
Expand All @@ -14,7 +15,12 @@ dependencies {
}
tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
}

tasks.withType(Jar::class) {
manifest {
attributes["Manifest-Version"] = "1.0"
Expand All @@ -26,7 +32,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "io.github.seujorgenochurras"
artifactId = "image-to-ascii"
version = "0.0.2"
version = "0.0.3"
from(components["java"])

pom {
Expand Down Expand Up @@ -77,3 +83,9 @@ signing {
tasks.getByName<Test>("test") {
useJUnitPlatform()
}

jacoco{
toolVersion = "0.8.11"
reportsDirectory = layout.buildDirectory.dir("jacoco")
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static String toAscii(String imagePath) {
}


public static String toAscii(String imagePath, int height, int width, boolean withAnsiColor) {
public static String toAscii(String imagePath, int width, int height, boolean withAnsiColor) {
ParserBuilder parserBuilder = ParserBuilder.startBuild()
.symbols(symbols)
.scaled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.seujorgenochurras.color.symbol.Symbol;
import io.github.seujorgenochurras.color.symbol.SymbolList;
import io.github.seujorgenochurras.image.BetterImage;
import io.github.seujorgenochurras.image.ascii.AsciiParser;
import io.github.seujorgenochurras.image.ascii.ParserConfig;
import io.github.seujorgenochurras.image.ascii.algorithm.pixel.bright.Algorithms;

import java.awt.*;
Expand All @@ -12,15 +14,33 @@
public class BestSymbolPatternFinder {


/**
* Overloaded method of {@link BestSymbolPatternFinder#findBestPattern(int, int, String...)}
*/
public static SymbolList findBestPattern(String... chars) {
return findBestPattern(255, chars);
}

/**
* Overloaded method of {@link BestSymbolPatternFinder#findBestPattern(int, int, String...)}
*/
public static SymbolList findBestPattern(int maxSymbols, String... chars) {

return findBestPattern(10, maxSymbols, chars);
}

/**
* Finds the best pattern given any unsorted symbols
*
* @param symbolAccuracy amount of preciseness of symbols representation, for example: <br>
* symbolAcurracy of 2 means that a symbol can either represent its brightness value +1 or -1,
* <b>lower means high precision</b>
*
* @param maxSymbols maximum amount of symbols
* @param chars unsortedSymbols
* @return the best symbol pattern possible in the font Fira Mono
*/
//TODO refactor this non-sense shit
public static SymbolList findBestPattern(int symbolAccuracy, int maxSymbols, String... chars) {
int width = 50;
int height = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ public class SymbolList {


public SymbolList(int listSize) {
this.sortedSymbols = new Symbol[listSize - 1];
this.sortedSymbols = new Symbol[listSize];
}

public SymbolList(int listSize, int acceptableCharAccuracy) {
this.sortedSymbols = new Symbol[listSize - 1];
System.out.println(sortedSymbols.length);
this.sortedSymbols = new Symbol[listSize];
this.acceptableSymbolAccuracy = acceptableCharAccuracy;

}
Expand All @@ -25,7 +24,7 @@ public void addSymbol(Symbol symbol) {
double newSymbolBrightness = symbol.getBrightness();

int symbolShade = (int) Math.round(newSymbolBrightness / ((double) 255 / sortedSymbols.length));
if (sortedSymbols.length - 1 < symbolShade) return;
if (sortedSymbols.length < symbolShade) return;


Symbol currentSymbol = sortedSymbols[symbolShade];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.seujorgenochurras;
package io.github.seujorgenochurras.demo;

import io.github.seujorgenochurras.color.BestSymbolPatternFinder;
import io.github.seujorgenochurras.image.BetterImage;
Expand Down

This file was deleted.

Loading

0 comments on commit a7f446f

Please sign in to comment.