:foggy: Convert image to ASCII

Overview

🌁 Image2ascii

Build Status Coverage Status Codacy Badge Go Report Card GoDoc License: MIT Awesome

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

demo

Installation

go get github.com/qeesung/image2ascii

CLI usage

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)

image2ascii -f docs/images/pikaqiu2.jpg

demo

convert the image to ascii image with fixed width and height

# width: 100
# height: 30
image2ascii -f docs/images/baozou.jpg -w 100 -g 30

demo

convert the image to ascii image by ratio

# ratio: 0.3
# width: imageWidth * 0.3
# height: imageHeight * 0.3
image2ascii -f docs/images/pikaqiu.jpg -r 0.3

demo

convert the image to stretch the screen

image2ascii -f docs/images/long.jpg -t

demo

convert the image without the color

image2ascii -f docs/images/lufei.jpg -s -c=false

convert the image disable fit the screen

image2ascii -f docs/images/lufei.jpg -s=false

convert the image reverse the chars

image2ascii -f docs/images/lufei.jpg -i

Library usage

package main

import (
	"fmt"
	"github.com/qeesung/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

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

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
}

Sample outputs

Raw Image ASCII Image

License

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

Comments
  • Feature: Option to print raw escape codes of colors

    Feature: Option to print raw escape codes of colors

    It will be really great if image2ascii had an option to print the real escape codes of colors so one could copy/paste the output and place it in a script of his own.

    opened by rafi 3
  • 为什么我输入后显示的是乱七八糟的

    为什么我输入后显示的是乱七八糟的

    ?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;1 6m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;0 0m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;231m ?[0;00m?[38;5;231m ?[0;00m?[38;5;231m ?[0;00m?[38;5;231m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[38;5;16m ?[0;00m?[

    opened by guanzenbin 1
  • Fixed a slice allocate issue

    Fixed a slice allocate issue

    1. The second arg of make is length, then the third is cap;
    2. Reserving a position for the new line char("\n"), though slice can reassign its size automatically.
    opened by liujj 1
  • Update install instructions from to `go install`

    Update install instructions from to `go install`

    Looks like go get has been deprecated.

    New method for installation is go install <repo-url>@latest

    In this case:

    go install github.com/qeesung/[email protected]
    
    opened by klei22 0
  • Add an option to save the result

    Add an option to save the result

    Please could you add the feature of saving the result of the image2ascii to a file. Doing this manually doesn't work as you use some kind of terminal color formatting, which makes the result in a file look ugly.

    Thanks

    opened by OyewoleOyedeji 0
  • [Feature Request] Monochrome output with HEX color description

    [Feature Request] Monochrome output with HEX color description

    Would be cool to have a flag for monochrome output in the command line utility, maybe something like:

    image2ascii --monochrome -f image.png
    

    or

    image2ascii -m -f image.png
    

    Even better if one could specify the color with hex (for example green):

    image2ascii -f image.png -h 00FF00
    
    opened by klei22 0
  • Could not install anymore!

    Could not install anymore!

    I tried to install via go get github.com/qeesung/image2ascii, but it failed.

    C:\Users\Liu.D.H>go get github.com/qeesung/image2ascii
    go: downloading github.com/qeesung/image2ascii v1.0.1
    go: downloading github.com/mattn/go-isatty v0.0.14
    go: downloading github.com/wayneashleyberry/terminal-dimensions v1.1.0
    go: downloading github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
    go: downloading github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59
    go: downloading golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
    go get: installing executables with 'go get' in module mode is deprecated.
            Use 'go install [email protected]' instead.
            For more information, see https://golang.org/doc/go-get-install-deprecation
            or run 'go help get' or 'go help install'.
    # runtime/internal/sys
    D:\apps\go\src\runtime\internal\sys\stubs.go:9:7: PtrSize redeclared in this block
            D:\apps\go\src\runtime\internal\sys\arch.go:24:38: previous declaration
    D:\apps\go\src\runtime\internal\sys\stubs.go:10:24: undefined: Uintreg
    D:\apps\go\src\runtime\internal\sys\stubs.go:16:7: StackGuardMultiplier redeclared in this block
            D:\apps\go\src\runtime\internal\sys\arch.go:27:74: previous declaration
    
    C:\Users\Liu.D.H>go install github.com/qeesung/image2ascii
    go install: version is required when current directory is not in a module
            Try 'go install github.com/qeesung/[email protected]' to install the latest version
    
    C:\Users\Liu.D.H>go install github.com/qeesung/[email protected]
    go: finding module for package github.com/wayneashleyberry/terminal-dimensions
    go: finding module for package github.com/aybabtme/rgbterm
    go: finding module for package github.com/nfnt/resize
    go: finding module for package github.com/mattn/go-isatty
    go: found github.com/aybabtme/rgbterm in github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59
    go: found github.com/mattn/go-isatty in github.com/mattn/go-isatty v0.0.14
    go: found github.com/wayneashleyberry/terminal-dimensions in github.com/wayneashleyberry/terminal-dimensions v1.1.0
    go: finding module for package github.com/nfnt/resize
    go\pkg\mod\github.com\qeesung\[email protected]\convert\resize.go:4:2: no matching versions for query "latest"
    
    C:\Users\Liu.D.H>
    
    opened by liudonghua123 3
  • [Feature request] Ability to specify charmap

    [Feature request] Ability to specify charmap

    Would be amazing to be able to use box shapes and/or all known glyphs available for fidelity on sub-pixel level. Kind of like how this works; https://asciiart.club

    opened by 23d1 0
Owner
秦世成
💥🤘✋Give me four! ✋🤘💥
秦世成
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Zoraiz Hassan 1.1k Nov 20, 2022
Image - This repository holds supplementary Go image librariesThis repository holds supplementary Go image libraries

Go Images This repository holds supplementary Go image libraries. Download/Insta

null 0 Jan 5, 2022
API for generate image to ASCII Art

ASCII API Generate ASCII art from image. You can try this API here: ascii.projec

Sh4yn 5 Jul 1, 2022
package for convert DataURLs to image

convert base64 DataURLs to image

Muhammad Al Farizzi 1 Oct 18, 2021
darkroom - An image proxy with changeable storage backends and image processing engines with focus on speed and resiliency.

Darkroom - Yet Another Image Proxy Introduction Darkroom combines the storage backend and the image processor and acts as an Image Proxy on your image

Gojek 202 Nov 27, 2022
Easily customizable Social image (or Open graph image) generator

fancycard Easily customizable Social image (or Open graph image) generator Built with Go, Gin, GoQuery and Chromedp Build & Run Simply, Clone this rep

Youngbin Han 4 Jan 14, 2022
An API which allows you to upload an image and responds with the same image, stripped of EXIF data

strip-metadata This is an API which allows you to upload an image and responds with the same image, stripped of EXIF data. How to run You need to have

Cristina Simionescu 0 Nov 25, 2021
Imgpreview - Tiny image previews for HTML while the original image is loading

imgpreview This is a Go program that generates tiny blurry previews for images t

Dmitry Chestnykh 8 May 22, 2022
Ascii-art-web

ASCII-ART-WEB Author: Alika96 How to run Run the following commands: For building an image: docker image build -t ascii-art-web-docker . For showing i

null 0 Dec 13, 2021
Human-friendly Go module that builds and prints directory trees using ASCII art

Human-friendly Go module that builds and prints directory trees using ASCII art.

Vadym Borodin 5 Oct 11, 2022
A simple javascript website that takes user input, queries a Go based backend which then creates ascii art and sends it back to the frontend

A simple javascript website that takes user input, queries a Go based backend which then creates ascii art and sends it back to the frontend. Finally the site displays the ascii art and offers the option to download as multiple file types.

null 0 Jan 7, 2022
A command to output longified ascii art.

longify A command to output longified ascii art. Inspired by Tweet from @sheepla: https://twitter.com/Sheeeeepla/status/1522199846870196225 Installati

syumai 11 Sep 12, 2022
Convert images to computer generated art using delaunay triangulation.

▲ Triangle is a tool for generating triangulated image using delaunay triangulation. It takes a source image and converts it to an abstract image comp

Endre Simo 2k Nov 18, 2022
Small project to convert images to grayscale

This is a small http server that will read images from a provided path, convert the image to gray, and then serve back the converted image Usage You c

Wolfgang E Sanyer 0 Nov 5, 2021
Image processing algorithms in pure Go

bild A collection of parallel image processing algorithms in pure Go. The aim of this project is simplicity in use and development over absolute high

Anthony N. Simon 3.7k Nov 22, 2022
Go package for fast high-level image processing powered by libvips C library

bimg Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API. bimg was designed to be

Tom 2.1k Nov 23, 2022
Image processing library and rendering toolkit for Go.

blend Image processing library and rendering toolkit for Go. (WIP) Installation: This library is compatible with Go1. go get github.com/phrozen/blend

Guillermo Estrada 61 Nov 11, 2022
Decode embedded EXIF meta data from image files.

goexif Provides decoding of basic exif and tiff encoded data. Still in alpha - no guarantees. Suggestions and pull requests are welcome. Functionality

Robert Carlsen 540 Nov 19, 2022
A lightning fast image processing and resizing library for Go

govips A lightning fast image processing and resizing library for Go This package wraps the core functionality of libvips image processing library by

David Byttow 795 Nov 25, 2022