Giter Site home page Giter Site logo

image-to-ascii's Introduction

AsciiImage

This is a library that allows you to easily convert any image into an image containing only ascii characters from an alphabet you can define.

How to convert

var path = "your path here";
var image = new Bitmap(path); // first we need to create a bitmap
// now we need to create an instance of the AsciiImageConverter class, for converting
// for now we use default ascii alphabet (gradient)
var converter = new AsciiImageConverter(bitmap, Gradient.Default);
// Now we just need to call the GetAsciiImage() method and get the char[][] containing the image
var image = converter.GetAsciiImage();

How to create Gradient

To control the creation of your own gradient there is the simpliest IGradient interface

public interface IGradient
{
    public string Alphabet { get;  }
}

And now let's just create a class that implements this interface

public class MyGradient : IGradient
{
    public string Alphabet => "my characters here";
}

For simplicity of gradient creation there is a class, with follows static methods:

public class Gradient : IGradient
{
    private const string _default = @" .:!/r(l1Z4H9W8$@\";
    private static readonly string _defaultReversed = string.Join("", _default.Reverse());
    
    public static Gradient Default => new(_default);
    
    public static Gradient WhiteTheme => new(_defaultReversed);
    
    public static Gradient BlackTheme => Default;

    public static Gradient Make(string aplhabet) => new Gradient(aplhabet);
}

Also for simplicity of creating pictures in the AsciiImageConverter class there are the following static methods:

public class AsciiImageConverter
{
    ...

    public static char[][] Convert(Bitmap bitmap, IGradient gradient)
    {
        return new AsciiImageConverter(bitmap, gradient).GetAsciiImage();
    }

    public static char[][] Convert(Bitmap bitmap)
    {
        return new AsciiImageConverter(bitmap, AsciiImage.Gradient.Default).GetAsciiImage();
    }
}

image-to-ascii's People

Contributors

delaynore avatar

Watchers

 avatar

image-to-ascii's Issues

Determining your image size

At this point the image is larger than 1000 pixels in height and width, automatically converted
So we need to make it possible to control this process

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.