Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Powershell Trick: Convert text to ASCII art

As PowerShell has plain command based console if you want to show different font or different bigger font on the same console as output, you will have to use ASCII Text art, I had got a request to write a script to convert any text to ASCII art. Only weirdness in the request I found was, whatever output generated as ascii art, should not be captured to file or by coping it. Someone might argue using Write-Host cmdlet, but Here I have found perfect use case for my need of using Write-Host, I have used it with backgroundcolor parameter to show font, keeping few spaces no color.

Below is the example of one of the letter A. (There are only capital alphabets, small letters are shown as capital alphabets only), You can create your own font and it is easily replaceable, I am planning to create external file in future with different fonts. 

1
Write-Host $(" " * 6) -BackgroundColor 'Yellow' -NoNewline; Write-Host " "; Write-Host "  " -BackgroundColor 'Yellow' -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor 'Yellow'  -NoNewline; Write-Host " "; Write-Host "  " -BackgroundColor 'Yellow' -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor 'Yellow'  -NoNewline; Write-Host " "; Write-Host $(" " * 6) -BackgroundColor 'Yellow' -NoNewline; Write-Host " "; Write-Host "  " -BackgroundColor 'Yellow' -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor 'Yellow'  -NoNewline; Write-Host " "

You can save script in .\Convertto-TextASCIIArt.ps1. There is a parameter -Text where your provide your custom text message. and -FontColor has choice (Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White). If you need spacial character send me comment on the blog so I can add it if required. 

Difficulty running script go thru my earlier blog.
Different ways to bypass Powershell execution policy :.ps1 cannot be loaded because running scripts is disabled
Installing, importing and using any module in powershell

If you need more font choices, you can use -Online parameter, which will use api and fetch selected text from http://artii.herokuapp.com using Invoke-WebRequest using Get method. For complete font list (figlet) browse http://artii.herokuapp.com/fonts_list or user -FontName Parameter. Font name (figlet name) is case sensitive.

This code is available on GitHub.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#
#requires -version 4

.SYNOPSIS
    Convertto-TextASCIIArt converts text string to ASCII Art.
.DESCRIPTION
    The Convertto-TextASCIIArt show normal string or text as big font nicely on console. I have created one font for use (It is not exactly font but background color and cannot be copied), alternatively if you are using online parameter it will fetch more fonts online from 'http://artii.herokuapp.com'.
.PARAMETER Text
    This is common parameter for inbuilt and online and incase not provided default value is '# This is test !', If you are using inbuilt font small letter will convert to capital letter.
.PARAMETER Online
    To use this parameter make sure you have active internet connection, as it will connect to website http://artii.herokuapp.com and and using api it will download the acsii Art
.PARAMETER FontName
    There are wide variaty of font list available on http://artii.herokuapp.com/fonts_list, when using online parameter, Value provided here is case sensetive.
.PARAMETER FontColor
    Below is the list of font color can be used to show ascii art.
    'Black', 'DarkBlue','DarkGreen','DarkCyan', 'DarkRed','DarkMagenta','DarkYellow','Gray','DarkGray','Blue','Green','Cyan','Red','Magenta','Yellow','White'
.PARAMETER FontHight
    This parameter is optional and default value is 5, this is font hight and required for the font I created. Algorithm of this script is depend on the default value.
.INPUTS
    [System.String]
.OUTPUTS
    [console]
.NOTES
    Version:        1.0
    Author:         Kunal Udapi
    Creation Date:  30 September 2017
    Purpose/Change: Personal use to show text to ascii art.
    Useful URLs: http://vcloud-lab.com, http://artii.herokuapp.com/fonts_list
.EXAMPLE
    PS C:\>.\Convertto-TextASCIIArt -Online -Text "http://vcloud-lab.com" -FontColor Gray -Fontname big
  _     _   _              ____         _                 _        _       _                         
 | |   | | | |       _    / / /        | |               | |      | |     | |                        
 | |__ | |_| |_ _ __(_)  / / /_   _____| | ___  _   _  __| |______| | __ _| |__   ___ ___  _ __ ___  
 | '_ \| __| __| '_ \   / / /\ \ / / __| |/ _ \| | | |/ _` |______| |/ _` | '_ \ / __/ _ \| '_ ` _ \ 
 | | | | |_| |_| |_) | / / /  \ V / (__| | (_) | |_| | (_| |      | | (_| | |_) | (__ (_) | | | | | |
 |_| |_|\__|\__| .__(_)_/_/    \_/ \___|_|\___/ \__,_|\__,_|      |_|\__,_|_.__(_)___\___/|_| |_| |_|
               | |                                                                                   
               |_|                                                                                   

    Shows and converts text to cool ascii art from online site http://artii.herokuapp.com using apis.
.EXAMPLE
    PS C:\>.\Convertto-TextASCIIArt -Text '# This !'

      ██  ██     ██████ ██  ██ ██   ████     ██
    ██████████     ██   ██  ██ ██ ██         ██  
      ██  ██       ██   ██████ ██   ██       ██  
    ██████████     ██   ██  ██ ██     ██    
      ██  ██       ██   ██  ██ ██ ████       ██  
    
    Shows local font on the script not internet required
#>

[CmdletBinding(SupportsShouldProcess=$True,
    ConfirmImpact='Medium',
    HelpURI='http://vcloud-lab.com',
    DefaultParameterSetName='Inbuilt')]
Param
(
    [parameter(Position=0, ParameterSetName='Inbuilt', ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, HelpMessage='Provide valid text')]
    [parameter(Position=0, ParameterSetName='Online', ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, HelpMessage='Provide valid text')]
    [string]$Text = '# This is test !',
    [parameter(Position=2, ParameterSetName='Inbuilt', ValueFromPipelineByPropertyName=$true, HelpMessage='Provide existing font hight')]
    [Alias('Hight')]    
    [string]$FontHight = '5',
    
    [parameter(Position=2, ParameterSetName='Online', ValueFromPipelineByPropertyName=$true, HelpMessage='Provide font name list is avaliable on http://artii.herokuapp.com/fonts_list')]
    [ValidateSet('3-d','3x5','5lineoblique','1943____','4x4_offr','64f1____','a_zooloo','advenger','aquaplan','asc_____','ascii___','assalt_m','asslt__m','atc_____','atc_gran','b_m__200','battle_s','battlesh','baz__bil','beer_pub','bubble__','bubble_b','c1______','c2______','c_ascii_','c_consen','caus_in_','char1___','char2___','char3___','char4___','charact1','charact2','charact3','charact4','charact5','charact6','characte','charset_','coil_cop','com_sen_','computer','convoy__','d_dragon','dcs_bfmo','deep_str','demo_1__','demo_2__','demo_m__','devilish','druid___','e__fist_','ebbs_1__','ebbs_2__','eca_____','etcrvs__','f15_____','faces_of','fair_mea','fairligh','fantasy_','fbr12___','fbr1____','fbr2____','fbr_stri','fbr_tilt','finalass','fireing_','flyn_sh','fp1_____','fp2_____','funky_dr','future_1','future_2','future_3','future_4','future_5','future_6','future_7','future_8','gauntlet','ghost_bo','gothic','gothic__','grand_pr','green_be','hades___','heavy_me','heroboti','high_noo','hills___','home_pak','house_of','hypa_bal','hyper___','inc_raw_','italics_','joust___','kgames_i','kik_star','krak_out','lazy_jon','letter_w','letterw3','lexible_','mad_nurs','magic_ma','master_o','mayhem_d','mcg_____','mig_ally','modern__','new_asci','nfi1____','notie_ca','npn_____','odel_lak','ok_beer_','outrun__','p_s_h_m_','p_skateb','pacos_pe','panther_','pawn_ins','phonix__','platoon2','platoon_','pod_____','r2-d2___','rad_____','rad_phan','radical_','rainbow_','rally_s2','rally_sp','rampage_','rastan__','raw_recu','rci_____','ripper!_','road_rai','rockbox_','rok_____','roman','roman___','script__','skate_ro','skateord','skateroc','sketch_s','sm______','space_op','spc_demo','star_war','stealth_','stencil1','stencil2','street_s','subteran','super_te','t__of_ap','tav1____','taxi____','tec1____','tec_7000','tecrvs__','ti_pan__','timesofl','tomahawk','top_duck','trashman','triad_st','ts1_____','tsm_____','tsn_base','twin_cob','type_set','ucf_fan_','ugalympi','unarmed_','usa_____','usa_pq__','vortron_','war_of_w','yie-ar__','yie_ar_k','z-pilot_','zig_zag_','zone7___','acrobatic','alligator','alligator2','alphabet','avatar','banner','banner3-D','banner3','banner4','barbwire','basic','5x7','5x8','6x10','6x9','brite','briteb','britebi','britei','chartr','chartri','clb6x10','clb8x10','clb8x8','cli8x8','clr4x6','clr5x10','clr5x6','clr5x8','clr6x10','clr6x6','clr6x8','clr7x10','clr7x8','clr8x10','clr8x8','cour','courb','courbi','couri','helv','helvb','helvbi','helvi','sans','sansb','sansbi','sansi','sbook','sbookb','sbookbi','sbooki','times','tty','ttyb','utopia','utopiab','utopiabi','utopiai','xbrite','xbriteb','xbritebi','xbritei','xchartr','xchartri','xcour','xcourb','xcourbi','xcouri','xhelv','xhelvb','xhelvbi','xhelvi','xsans','xsansb','xsansbi','xsansi','xsbook','xsbookb','xsbookbi','xsbooki','xtimes','xtty','xttyb','bell','big','bigchief','binary','block','broadway','bubble','bulbhead','calgphy2','caligraphy','catwalk','chunky','coinstak','colossal','contessa','contrast','cosmic','cosmike','crawford','cricket','cursive','cyberlarge','cybermedium','cybersmall','decimal','diamond','digital','doh','doom','dotmatrix','double','drpepper','dwhistled','eftichess','eftifont','eftipiti','eftirobot','eftitalic','eftiwall','eftiwater','epic','fender','fourtops','fraktur','goofy','graceful','gradient','graffiti','hex','hollywood','invita','isometric1','isometric2','isometric3','isometric4','italic','ivrit','jazmine','jerusalem','katakana','kban','l4me','larry3d','lcd','lean','letters','linux','lockergnome','madrid','marquee','maxfour','mike','mini','mirror','mnemonic','morse','moscow','mshebrew210','nancyj-fancy','nancyj-underlined','nancyj','nipples','ntgreek','nvscript','o8','octal','ogre','os2','pawp','peaks','pebbles','pepper','poison','puffy','pyramid','rectangles','relief','relief2','rev','rot13','rounded','rowancap','rozzo','runic','runyc','sblood','script','serifcap','shadow','short','slant','slide','slscript','small','smisome1','smkeyboard','smscript','smshadow','smslant','smtengwar','speed','stacey','stampatello','standard','starwars','stellar','stop','straight','tanja','tengwar','term','thick','thin','threepoint','ticks','ticksslant','tinker-toy','tombstone','trek','tsalagi','twopoint','univers','usaflag','weird','whimsy')]
    [Alias('Font')]
    [string]$FontName = 'big',

    [parameter(ParameterSetName = 'Online', Position=0, Mandatory=$false)]
    [Switch]$Online,

    [parameter(Position=1, ParameterSetName='Inbuilt', ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, HelpMessage='Provide valid console color')]
    [parameter(ParameterSetName = 'Online', Position=1, Mandatory=$false, HelpMessage='Provide valid console color')]  
    [Alias('Color')]
    [ValidateSet('Black', 'DarkBlue','DarkGreen','DarkCyan', 'DarkRed','DarkMagenta','DarkYellow','Gray','DarkGray','Blue','Green','Cyan','Red','Magenta','Yellow','White')]
    [string]$FontColor = 'Yellow'
)
Begin {
    #$NonExistFont = $null
    if ($PsCmdlet.ParameterSetName -eq 'Inbuilt') {
        $a = { Write-Host $(" " * 6) -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor  -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor  -NoNewline; Write-Host " "
         Write-Host $(" " * 6) -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor  -NoNewline; Write-Host " "} 
        $b = { Write-Host $(" " * 4) -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 3) 
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor   -NoNewline; Write-Host " "
         Write-Host $(" " * 6) -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor  -NoNewline; Write-Host " "
         Write-Host $(" " * 4) -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 3) } 
        $c = { Write-Host $(" " * 5) -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4) 
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4)
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4)
         Write-Host $(" " * 5) -BackgroundColor $FontColor -NoNewline; Write-Host " "}
        $d = { Write-Host $(" " * 4) -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 3)
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host "  " -NoNewline; Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host $(" " * 4) -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 3)}  
        $e = { Write-Host $(" " * 5) -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4)
         Write-Host $(" " * 4) -BackgroundColor $FontColor -NoNewline; Write-Host "  " 
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4)
         Write-Host $(" " * 5) -BackgroundColor $FontColor -NoNewline; Write-Host " "}
        $f = { Write-Host $(" " * 5) -BackgroundColor $FontColor -NoNewline; Write-Host " "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4)
         Write-Host $(" " * 4) -BackgroundColor $FontColor -NoNewline; Write-Host "  "
         Write-Host "  " -BackgroundColor $FontColor -NoNewline; Write-Host $(" " * 4)
         Write-Host 


This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here

Share the post

Powershell Trick: Convert text to ASCII art

×

Subscribe to Tales From Real It System Administrators World And Non-production Environment

Get updates delivered right to your inbox!

Thank you for your subscription

×