#image #ascii #ascii-art #graphics #ascii-text

asciifyer

Rust库,轻松将图像转换为ASCII艺术

1 个不稳定版本

0.1.1 2020年12月16日

#730 in 图像

Apache-2.0

61KB
62

ASCIIfyer

此crate提供了一种简单的方法将普通图像转换为ASCII图片。支持的图像格式是image crate支持的格式;有关列表,请参阅此处

默认情况下,在将图像转换为ASCII之前,图像会被调整大小到250x250像素。您可以通过传递一个包含宽度和高度的Dimension结构来覆盖此设置。如果图像小于这些维度,则不会调整大小。

功能

  • 打开图像文件并将内容转换为ASCII字符串

可选功能

  • fetch - 启用此功能允许使用函数从URL下载图像。

示例

以下是将图像转换为ASCII的简单示例。要尝试提供的示例,请使用cargo run --example asciify /path/to/picture.png

use asciifyer::{convert_to_ascii, Dimension};
use std::env;

fn main() {
    let path = env::args().nth(1).expect("Please enter a path to an image");

    let dimensions = Dimension::new(50, 50);
    let ascii = convert_to_ascii(&path, Some(dimensions));

    println!("{}", ascii);
}

使用提供的海豚图像的示例输出

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#@@@@0;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;/########@@;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;@############;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;0/#00#########/;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;///O0000#######0;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;////;0000000000##;;;;;;;;;
 ;;;;;;;;;;;;;;;/#;;;://///;000000000000/;;;;;;;;
 ;;;;;;;;;;;;;;;//0;;/////;;0000000000000;;;;;;;;
 ;;;;;;;;;;;;;;;/;0##////;;;;0000000000000@;;;;;;
 ;;;;;;;;;;;;;;;;;;;0////;;;;0000000/00####0;;;;;
 ;;;;;;;;;;;;;;:;;0/;///;;;;;00000///O///###;;;;;
 ;;;;;;;;;;;;;;;;#/////;;;;;;00000O/:;;;/0##;;;;;
 ;;;;;;;;;;;;;;;:////O/;;;;;;:000O/;;;;;;00#/;;;;
 ;;;;;;;;;;;;;;;///////;;;::;:00///;;;;;;O0.;;;;;
 ;;;;;;;;;;;;;;O/////;:;;@  :;0O///:;;;;/'O;;;;;;
 ;;;;;;;;;;;;;0/////;;;;;@@';;;O/O//::;,,;;;;;;;;
 ;;;;;;;;;;;;0/////;;;;;;O;;;;;OOO/;:,,:;;;;;;;;;
 ;;;;;;;;;;;/////;;;;;;.;;;;;;;0OO/,,';;;;;;;;;;;
 ;;;;;;;;;;;/////;;;;;;;;;;;;;;/',,,..//;;;;;;;;;
 ;;;;;;;;;;;////;;;;;;;/;;;;;;,,,,....:;;;;;;;;;;
 ;;;;;;;;;;///;;;;;;;;//;;;;:,,..,....;;;;;;;;;;;
 ;;;;;;;;;;;//;;;;;;;//,;;;,....:,..;;;;;;;;;;;;;
 ;;;;;;;;;;;//;;;;;;OO,.;......;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;/;;;;;0OO..:......;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;/;;;;000.:;......;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;:;;;00;::;......;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;:;;00.::;.....,;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;:;00 ;;;.....,;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;:00';;;.....;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;0,;;;....;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;::;;;....;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;/:;:;....;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;#///;;::...;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;#0,,:;;:...;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;:.,,,;;...;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;0;..,,;:.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;...,;:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;/:.:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

许可证

版权所有 © 2020 Evan Maddock [email protected]

ASCIIfyer可在Apache 2.0许可证的条款下使用。

依赖关系

~5–17MB
~207K SLoC