未加星标

An image to ASCII converter in JavaScript

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏
imgToAscii

A javascript implementation of a image to ascii converter.

How to use

Include the imgToAscii.js file

<script src="src/imgToAscii.js"></script>

or

<script src="https://raw.githubusercontent.com/victorqribeiro/imgToAscii/v1.3/src/imgToAscii.js"></script>

then just create a new imgToAscii object with the image address and optionaly the alphabet: (0 - simpler shades, 1 - more complex shades) - default is 0

<script> let ele = new imgToAscii('elefante.png'); ele.display(); </script>

You can also resize your image passing a second parameter between 0 and 1 as percentage. e.g.: 0.5 = 50% - Will reduce the size of your image in 50% both vertical and horizontal (width, height).

<script> let eu = new imgToAscii('eu.png',0.5); eu.display(); </script>

To display the ASCII image with color just call the method displayColor(). You can set the background color of your image passing a color parameter to the method. e.g.: gray, white, black, #fff, rgb(10,10,10). Default is transparent.

<script> eu.displayColor('gray'); </script>

Note that on the code above the same 'eu' image was used. Once you load an image, you can display it with or without color, without the need to reload the image data.

Important

The ascii art depends on a monospace font to work properly. You should consider that 1 pixel in your image is going to be translated to 1 char in Ascii. e.g.: if a image is 100 pixels wide, it's going to take 100 chars of space on your page, unless you do something about it.

The imgToAscii should work with remote images:

let img = new imgToAscii('http://site.com/image.png');

but it might not because of cross-origin settings. Keep that in mind.

A similar code is running on my photoEditor to generate a image of the ascii code (what?!)


An image to ASCII converter in JavaScript
An image to ASCII converter in JavaScript
An image to ASCII converter in JavaScript
An image to ASCII converter in JavaScript

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

tags: image,lt,script,imgToAscii,gt,your,eu,color,new
分页:12
转载请注明
本文标题:An image to ASCII converter in JavaScript
本站链接:https://www.codesec.net/view/604929.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(12)