Convert UIImage to ASCII art

Overview

BKAsciiImage

Version License Platform

Example gif image

As seen on Cmd.fm iOS App

https://itunes.apple.com/app/cmd.fm-radio-for-geeks-hackers/id935765356

Cmd.fm screenshot 1 Cmd.fm screenshot 2

Installation

BKAsciiImage is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "BKAsciiImage"

Usage

Using BKAsciiConverter class

Import BKAsciiConverter header file

#import <BKAsciiImage/BKAsciiConverter.h>

Create a BKAsciiConverter instance

BKAsciiConverter *converter = [BKAsciiConverter new];

Convert synchronously

UIImage *inputImage = [UIImage imageNamed:@"anImage"];
UIImage *asciiImage = [converter convertImage:inputImage];

Convert in the background providing a completion block. Completion block will be called on the main thread.

[converter convertImage:self.inputImage completionHandler:^(UIImage *asciiImage) {
	// do whatever you want with the resulting asciiImage
}];

Convert to NSString

NSLog(@"%@",[converter convertToString:self.inputImage]);

// asynchronous
[converter convertToString:self.inputImage completionHandler:^(NSString *asciiString) {
    NSLog(@"%@",asciiString);
}];

Converter options

converter.backgroundColor = [UIColor whiteColor]; // default: Clear color. Image background is transparent
converter.grayscale = YES; // default: NO
converter.font = [UIFont fontWithName:@"Monaco" size:13.0]; // default: System font of size 10
converter.reversedLuminance = NO; // Reverses the luminance mapping. Reversing gives better results on a dark bg. default: YES
converter.columns = 50; // By default columns is derived by the font size if not set explicitly

Using UIImage category

Import header file

#import <BKAsciiImage/UIImage+BKAscii.h>

Use the provided category methods

UIImage *inputImage = [UIImage imageNamed:@"anImage"];
[inputImage bk_asciiImageCompletionHandler:^(UIImage *asciiImage) {
        
}];
    
[inputImage bk_asciiStringCompletionHandler:^(NSString *asciiString) {
	
}];

[inputImage bk_asciiImageWithFont: [UIFont fontWithName:@"Monaco" size:13.0]
                          bgColor: [UIColor redColor];
                          columns: 30
                         reversed: YES
                        grayscale: NO
                completionHandler: ^(NSString *asciiString) {
					// do whatever you want with the resulting asciiImage
				}];

Advanced usage

By default luminance values are mapped to strings using

NSDictionary *dictionary = @{  @1.0: @" ",
                               @0.95:@"`",
                               @0.92:@".",
                               @0.9 :@",",
                               @0.8 :@"-",
                               @0.75:@"~",
                               @0.7 :@"+",
                               @0.65:@"<",
                               @0.6 :@">",
                               @0.55:@"o",
                               @0.5 :@"=",
                               @0.35:@"*",
                               @0.3 :@"%",
                               @0.1 :@"X",
                               @0.0 :@"@"
                               };

You can instantiate a converter with your own mapping dictionary

NSDictionary *dictionary = @{  @1.0: @" ",
                               @0.7 :@"a",
                               @0.65:@"b",
                               @0.6 :@"c",
                               @0.55:@"d",
                               @0.5 :@"e",
                               @0.35:@"f",
                               @0.3 :@"g",
                               @0.1 :@" ",
                               @0.0 :@" "
                               };



BKAsciiConverter *converter = [[BKAsciiConverter alloc] initWithDictionary:dictionary];
UIImage *inputImage = [UIImage imageNamed:@"anImage"];
UIImage *asciiImage = [converter convertImage:inputImage];

Mapping example screenshot

Author

Barış Koç, https://github.com/bkoc

License

BKAsciiImage is available under the MIT license. See the LICENSE file for more info.

You might also like...
A Swift package to convert a colour to a name using Wikipedia's colour list

ColorName Usage import ColorName SwiftUI let myColorName = getName(for: Color.red) print(myColorName) UIKit let myColorName = getName(for: UIColor.red

Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

Swift program that creates ASCII art from an image
Swift program that creates ASCII art from an image

Swift ASCII Art Generator Converts an image to text for no good reason. The code is pretty cool, though. It's pure functional Swifty goodness. Take a

Generates an image that looks like LEGO Art.

LegoArtFilter Generates an image that looks like LEGO Art. This library supports both iOS (14≤) and macOS (11≤). Usage // Get CGImage from CIImage let

An original digital art work for macOS, iOS and web
An original digital art work for macOS, iOS and web

WordClock WordClock versions of various vintages, for various platforms. https://www.simonheys.com/wordclock/ Downloads Currently avaiaible to downloa

Cardshark is an iOS card counting App that uses state of the art machine learning (YOLO) to classify and count the cards at real time.

Cardshark The game of Blackjack is one of the most popular casino games in the world. It is also the most winnable using a skill called Card Counting.

The Art World in Your Pocket or Your Trendy Tech Company's Tote, Artsy's mobile app.
The Art World in Your Pocket or Your Trendy Tech Company's Tote, Artsy's mobile app.

Meta State: production Point People: Brian Beckerle, Mounir Dhahri, Pavlos Vinieratos CI : This is an Artsy OSS project. Other mobile projects are Ene

An iOS application enables you explore art works provided by DeviartArt.com with high quality UX.
An iOS application enables you explore art works provided by DeviartArt.com with high quality UX.

Iris.iOS Iris is a model mobile application based on iOS. It provides basic functions allow users to explore on DeviantArt and check Daily Arts, Notif

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.

English | 简体中文 | 繁體中文 | 한국어 State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow 🤗 Transformers provides thousands of pretrained models

A minimal iOS app that displays 3d graphic art in AR.
A minimal iOS app that displays 3d graphic art in AR.

AR Art Attractors A minimal iOS AR(Augumented Reality) app that displays 3D graphic arts in AR. It uses attractor systems. An attractor is a set of st

iTunes 11 Style Color Art Detection for iOS
iTunes 11 Style Color Art Detection for iOS

iTunes 11 Style Color Art Detection for iOS. Original implementation from Fred Leitz Port of ColorArt code from OS X to iOS. Usage #include ColorArt/

 SwiftGif - A small UIImage extension with gif support.
SwiftGif - A small UIImage extension with gif support.

SwiftGif - A small UIImage extension with gif support.

High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

A tool to calculate the color ratio of UIImage in iOS.
A tool to calculate the color ratio of UIImage in iOS.

UIImageColorRatio A tool to calculate the color ratio of UIImage in iOS. How to use UIImageColorRatio Get the color ratio of UIImage. let image = ...

TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage
TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage

TextDrawer TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage. About Annotating Images TextDrawer is the easiest way

A Simple way help you drop or drag your source (like UIImage) between different App.

A Simple way help you drop or drag your source (like UIImage) between different App.

A convenient class usable from UIKit view controller or SwiftUI to scan document & get UIImage or PDFDocument as result - Replacement of IRLDocumentScanner

Super easy SwiftUI & UKKit pakcage to scan: Images or PDF. It is also a replacement for IRLScannerViewController

Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling
Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling

AnimatedGIFImageSerialization This library is no longer maintained. In iOS 13+ and macOS 10.15+, use CGAnimateImageAtURLWithBlock instead. AnimatedGIF

🌠 A small UIImage extension with gif support
🌠 A small UIImage extension with gif support

🌠 A small UIImage extension with gif support

Owner
Barış Koç
Barış Koç
Generates an image that looks like LEGO Art.

LegoArtFilter Generates an image that looks like LEGO Art. This library supports both iOS (14≤) and macOS (11≤). Usage // Get CGImage from CIImage let

Takuto NAKAMURA (Kyome) 10 Jul 7, 2022
SwiftGif - A small UIImage extension with gif support.

SwiftGif - A small UIImage extension with gif support.

SwiftGif 1.3k Dec 20, 2022
TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage

TextDrawer TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage. About Annotating Images TextDrawer is the easiest way

Remi ROBERT 106 Dec 18, 2022
IOS UIImage processing functions using the vDSP/Accellerate framework for speed.

UIImage Image Processing extensions using the vDSP/Accelerate framework.

null 372 Sep 1, 2022
A view controller for iOS that allows users to crop portions of UIImage objects

TOCropViewController TOCropViewController is an open-source UIViewController subclass to crop out sections of UIImage objects, as well as perform basi

Tim Oliver 4.4k Jan 1, 2023
An NSFW image detector for Swift built as an extension on UIImage.

Swift_NSFW_Detector An NSFW image detector for Swift built as an extension on UIImage. If you've ever allowed users to share images you are probably w

Chris Brown 5 Nov 27, 2022
Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle

Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle

Arnold Rozon 2 May 9, 2022
Convert HEIC images to JPEG format on the Mac

heic2jpeg Convert HEIC images to JPEG format on the Mac A basic tool to convert Apple's obnoxious HEIC format images (as the default photo format for

Fazal Majid 2 Mar 1, 2022
Convert the image to hexadecimal to send the image to e-paper

ConvertImageToHex Convert the image to hexadecimal to send the image to e-paper Conversion Order // 0. hex로 변환할 이미지 var image = UIImage(named: "sample

Hankyeol Park 0 Feb 26, 2022
A tool support convert image gif to gif3d

Trick convert gif to gif3d using Swift Features Simple way to convert gif to gif3d Change background Change size eraser tool How to work Add a layer w

Chuong Tran 16 Jan 4, 2023