Coder Social home page Coder Social logo

image2ascii's Introduction

🌁 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 install github.com/qeesung/image2ascii@latest

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.

image2ascii's People

Contributors

codacy-badger avatar liujj avatar qeesung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image2ascii's Issues

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

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 pkg@version' 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/image2ascii@latest' to install the latest version

C:\Users\Liu.D.H>go install github.com/qeesung/image2ascii@latest
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\image2ascii@v1.0.1\convert\resize.go:4:2: no matching versions for query "latest"

C:\Users\Liu.D.H>

不支持二维码

二维码需要转换成块字符才能被识别
我有个需求是要将二维码输出到终端

batch conversion

i have too many images, maybe support batch conversion is a good idea?

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

?[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?[

Add reverse color options

If the white color of the picture is very high, the output would be better if reverse the ascii char sequence

Binary release

Any chance of having compiled binary releases in GitHub Releases?

I understand implementing Go Releaser should be relatively straight forward.

[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

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.