12-09-2005, 06:49 AM
saw a page recently that had an image converted to text and thought id rip off the idea. heres what i came up with.
www.streetcds.co.uk/test1.html
www.streetcds.co.uk/test2.html
www.streetcds.co.uk/test1.html
www.streetcds.co.uk/test2.html
Code:
#include "crt.bi"
#include "windows.bi"
Option Explicit
Dim Shared message As String
message = "TestStringIsStandardInThisSituationIfYouAreReallyLuckyIMayEvenSayHelloWorld"
Sub Write_Header(hFile As Integer)
Print #hFile, "<html>"
Print #hFile, "<body style=""background-color: #000000;text-align: center;font-size: 7pt;"">"
Print #hFile, "<pre>"
End Sub
Sub Write_Footer(hFile As Integer)
Print #hFile, "</pre>"
Print #hFile, "</body>"
Print #hFile, "</html>"
End Sub
Function HTML_Hex(col As uInteger) As String
Dim str_ret As String
Dim i As Integer
Dim tmp_ptr As uByte ptr
tmp_ptr = cptr(uByte ptr, @col)
For i = 0 To 2
str_ret = hex(tmp_ptr[i]) & str_ret
If Len(str_ret) = (i * 2) + 1 Then str_ret = "0" & str_ret
Next i
HTML_Hex = "#" & str_ret
End Function
Function GetHTMLColor(x As Integer, y As Integer, img_array As uByte ptr, img_width As Integer) As String
Dim p As uInteger
Dim q As uInteger
p = (((y * img_width) + x) * 4) + 4
memcpy(@q, @img_array[p], 4)
GetHTMLColor = HTML_Hex(q)
End Function
Function EatMessage() As String
Static message_pos As uInteger
EatMessage = Mid(message, message_pos + 1, 1)
message_pos = message_pos + 1
If message_pos = len(message) Then message_pos = 0
End Function
Sub Write_ImgData(hFile As Integer, img_array As uByte ptr, img_width As Integer, img_height As Integer)
Dim As Integer x, y
Dim bobo As String
For y = 0 To img_height - 1
For x = 0 To img_width - 1
bobo = ""
bobo = bobo & EatMessage
bobo = bobo & EatMessage
Print #hFile, "<font color=""" & GetHTMLColor(x, y, img_array, img_width) & """>" & bobo & "</font>";
Next x
Print #hFile, ""
Next y
End Sub
Sub Main()
Dim hFile As Integer
Dim bHead As BITMAPFILEHEADER
Dim bInfo As BITMAPINFOHEADER
Dim img_array AS uByte ptr
Dim output_file As String
Dim input_file As String
Dim img_width As Integer
Dim img_height As Integer
Screen 18, 24
input_file = Command$
output_file = input_file & ".html"
If input_file = "" Then
Print "No File Specified"
Sleep
End
End If
hFile = FreeFile
Open input_file For Binary As #hFile
Get #hFile, , bHead
Get #hFile, , bInfo
Close #hFile
If bInfo.biBitCount <> 24 Then
Print "Bitmaps Depth Was Not 24bit"
Sleep
End
End If
img_width = bInfo.biWidth
img_height = bInfo.biHeight
Print " " & img_width & "x" & img_height
img_array = malloc(4 * (img_width * img_height) + 4)
BLoad input_file, img_array
Put (7, 15), img_array
hFile = FreeFile
Open output_file For Output As #hFile
Write_Header(hFile)
Write_ImgData(hFile, img_array, img_width, img_height)
Write_Footer(hFile)
Close #hFile
free(img_array)
End Sub
'Entry
Main
Sleep