Author Topic: JPG Graphic To Text Artwork Maker  (Read 5194 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
JPG Graphic To Text Artwork Maker
« on: July 31, 2019, 01:19:18 am »
I've wanted to make something like this for awhile. It loads any JPG picture and converts it to some text symbols and letters. It also uses spaces in certain area where the color is light or a shade of gray, black, or white. This program cannot use camera pictures or anything detailed like that, because it shrinks the picture down in memory (don't worry it doesn't change the original file) so the text file will be small enough to see it good on a computer screen. So, it's for simple graphics like stuff you make with Windows Paint or another paint program. But it does use 32 bit pictures in case you were wondering. I don't know if anybody else has made something like this on this forum before, but it's just something to play with mostly. Unless of course you have some other reason you need a program to convert graphics to text. It doesn't make the usual "ASCII Art" that people design themselves for forums, email, etc. unless you want a pretty large sized text graphic like this makes. Since it does shrink it down in memory, you will find some narrow lines that it won't display, but it works best, I think, with filled in colors.  Tonight I learned all about the _RED32, _GREEN32, and _BLUE32 to get what was needed from the POINT command. :) Check it out. :) Just make sure and make a graphic first before you run this and put it in the same directory as the program. The output file will be the same name as your graphic file was, except with a .txt instead of a .jpg ending.

Lastly: You can laugh at the outcomes of this program, because it's very rough and scattered, it was just made for fun and I don't really know how to make it cleaner looking unless I spend a lot more time on it adding more lines of converting colors to text.


(Note: I have a better one below on this page, without the bottom or side lines it makes on the text file.)

Code: QB64: [Select]
  1. _TITLE "JPG Picture To Text File Artwork Maker"
  2. start:
  3. DIM red&(16000)
  4. DIM green&(16000)
  5. DIM blue&(16000)
  6. DIM l$(16000)
  7. t = 0
  8. PRINT "                    JPG Picture To Text File Artwork Maker"
  9. PRINT "                                 By Ken G."
  10. PRINT "         This program loads 1 JPG picture file that's in the"
  11. PRINT "         same directory as this program and creates a text"
  12. PRINT "         file (.txt) of the same name as your JPG picture and"
  13. PRINT "         as a text file instead that can load in Notepad."
  14. PRINT "         This program only works with non-detailed graphics,"
  15. PRINT "         so a camera picture will not come out."
  16. PRINT "         For example, you can draw something with Microsoft"
  17. PRINT "         Paint and save it as a JPG and load it in this"
  18. PRINT "         to make a text graphic. Because this program has to"
  19. PRINT "         shrink the graphic down (without saving it or"
  20. PRINT "         overwriting any part of the original JPG file),"
  21. PRINT "         the detail of the text file will be very minimal."
  22. PRINT "         Which means it will look funny and non-detailed,"
  23. PRINT "         but I like it and I hope you have some fun with it too."
  24. INPUT "         Press Enter to begin.", st$
  25.  
  26. 'This section loads your picture from your computer.
  27.  
  28. loading:
  29. PRINT "                               Loading"
  30. PRINT "                     Do not add .jpg at the end."
  31. PRINT "                     The jpg picture must be in the same"
  32. PRINT "                     directory as this program is."
  33. PRINT "                     Type the name of your picture file"
  34. PRINT "                     here and press the Enter key."
  35. PRINT "                     Example: MyPic"
  36. PRINT "                     Q and Enter key ends program here."
  37. INPUT "->"; nm2$
  38. IF nm2$ = "Quit" OR nm2$ = "quit" OR nm2$ = "QUIT" OR nm2$ = "Q" OR nm2$ = "q" THEN END
  39. nm$ = nm2$ + ".jpg"
  40. theFileExists = _FILEEXISTS(nm$)
  41. IF theFileExists = 0 THEN
  42.     PRINT "File Does Not Exist."
  43.     PRINT "Would you like to try again (Y/N)"
  44.     PRINT "Esc ends program."
  45.     _LIMIT 10
  46.     llloop2:
  47.     ag$ = INKEY$
  48.     IF ag$ = "" THEN GOTO llloop2:
  49.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  50.     IF ag$ = CHR$(27) THEN END
  51.     GOTO start:
  52.  
  53. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  54.  
  55. SCREEN _NEWIMAGE(128, 120, 32)
  56. i& = _LOADIMAGE(nm$, 32)
  57. _PUTIMAGE (0, 0)-(128, 120), i&
  58.  
  59. FOR y = 0 TO 120
  60.     FOR x = 0 TO 128
  61.         t = t + 1
  62.         c& = POINT(x, y)
  63.         red&(t) = _RED32(c&)
  64.         green&(t) = _GREEN32(c&)
  65.         blue&(t) = _BLUE32(c&)
  66.     NEXT x
  67. SCREEN _NEWIMAGE(640, 480, 32)
  68. nm3$ = nm2$ + ".txt"
  69. OPEN nm3$ FOR OUTPUT AS #1
  70.  
  71. 'This section tries to match your pixel colors to certain text or spaces.
  72.  
  73. FOR tt = 1 TO t
  74.     FOR grays& = 0 TO 255
  75.         IF red&(tt) = grays& AND blue&(tt) = grays& AND green&(tt) = grays& THEN l$(tt) = "O": GOTO nex:
  76.     NEXT grays&
  77.     FOR reds& = 0 TO 255
  78.         IF red&(tt) = reds& AND blue&(tt) < 24 AND green&(tt) < 24 THEN l$(tt) = "#": GOTO nex:
  79.     NEXT reds&
  80.     FOR greens& = 0 TO 255
  81.         IF green&(tt) = greens& AND blue&(tt) < 24 AND red&(tt) < 24 THEN l$(tt) = "@": GOTO nex:
  82.     NEXT greens&
  83.     FOR blues& = 0 TO 255
  84.         IF blue&(tt) = blues& AND red&(tt) < 24 AND green&(tt) < 24 THEN l$(tt) = "*": GOTO nex:
  85.     NEXT blues&
  86.     FOR reds& = 24 TO 255
  87.         IF red&(tt) = reds& AND blue&(tt) > 23 AND green&(tt) < 24 THEN l$(tt) = "$": GOTO nex:
  88.     NEXT reds&
  89.     FOR greens& = 0 TO 255
  90.         IF green&(tt) = greens& AND blue&(tt) > 23 AND red&(tt) < 24 THEN l$(tt) = "%": GOTO nex:
  91.     NEXT greens&
  92.     FOR blues& = 0 TO 255
  93.         IF blue&(tt) = blues& AND red&(tt) > 23 AND green&(tt) < 24 THEN l$(tt) = "^": GOTO nex:
  94.     NEXT blues&
  95.     FOR reds& = 24 TO 255
  96.         IF red&(tt) = reds& AND blue&(tt) < 24 AND green&(tt) > 23 THEN l$(tt) = "&": GOTO nex:
  97.     NEXT reds&
  98.     FOR greens& = 0 TO 255
  99.         IF green&(tt) = greens& AND blue&(tt) < 24 AND red&(tt) > 23 THEN l$(tt) = "(": GOTO nex:
  100.     NEXT greens&
  101.     FOR blues& = 0 TO 255
  102.         IF blue&(tt) = blues& AND red&(tt) < 24 AND green&(tt) > 23 THEN l$(tt) = ")": GOTO nex:
  103.     NEXT blues&
  104.     FOR reds& = 0 TO 255
  105.         IF red&(tt) = reds& AND blue&(tt) < 48 AND green&(tt) < 24 THEN l$(tt) = "A": GOTO nex:
  106.     NEXT reds&
  107.     FOR greens& = 0 TO 255
  108.         IF green&(tt) = greens& AND blue&(tt) < 48 AND red&(tt) < 24 THEN l$(tt) = "B": GOTO nex:
  109.     NEXT greens&
  110.     FOR blues& = 0 TO 255
  111.         IF blue&(tt) = blues& AND red&(tt) < 48 AND green&(tt) < 24 THEN l$(tt) = "C": GOTO nex:
  112.     NEXT blues&
  113.     FOR reds& = 24 TO 255
  114.         IF red&(tt) = reds& AND blue&(tt) > 47 AND green&(tt) < 48 THEN l$(tt) = "D": GOTO nex:
  115.     NEXT reds&
  116.     FOR greens& = 0 TO 255
  117.         IF green&(tt) = greens& AND blue&(tt) > 47 AND red&(tt) < 48 THEN l$(tt) = "E": GOTO nex:
  118.     NEXT greens&
  119.     FOR blues& = 0 TO 255
  120.         IF blue&(tt) = blues& AND red&(tt) > 47 AND green&(tt) < 48 THEN l$(tt) = "F": GOTO nex:
  121.     NEXT blues&
  122.     FOR reds& = 24 TO 255
  123.         IF red&(tt) = reds& AND blue&(tt) < 48 AND green&(tt) > 47 THEN l$(tt) = "G": GOTO nex:
  124.     NEXT reds&
  125.     FOR greens& = 0 TO 255
  126.         IF green&(tt) = greens& AND blue&(tt) < 48 AND red&(tt) > 47 THEN l$(tt) = "H": GOTO nex:
  127.     NEXT greens&
  128.     FOR blues& = 0 TO 255
  129.         IF blue&(tt) = blues& AND red&(tt) < 48 AND green&(tt) > 47 THEN l$(tt) = "I": GOTO nex:
  130.     NEXT blues&
  131.     FOR reds& = 24 TO 255
  132.         IF red&(tt) = reds& AND blue&(tt) < 96 AND green&(tt) > 95 THEN l$(tt) = "J": GOTO nex:
  133.     NEXT reds&
  134.     FOR greens& = 0 TO 255
  135.         IF green&(tt) = greens& AND blue&(tt) < 96 AND red&(tt) > 95 THEN l$(tt) = "K": GOTO nex:
  136.     NEXT greens&
  137.     FOR blues& = 0 TO 255
  138.         IF blue&(tt) = blues& AND red&(tt) < 96 AND green&(tt) > 95 THEN l$(tt) = "L": GOTO nex:
  139.     NEXT blues&
  140.     FOR reds& = 24 TO 255
  141.         IF red&(tt) = reds& AND blue&(tt) > 95 AND green&(tt) < 96 THEN l$(tt) = "M": GOTO nex:
  142.     NEXT reds&
  143.     FOR greens& = 0 TO 255
  144.         IF green&(tt) = greens& AND blue&(tt) > 95 AND red&(tt) < 96 THEN l$(tt) = "N": GOTO nex:
  145.     NEXT greens&
  146.     FOR blues& = 0 TO 255
  147.         IF blue&(tt) = blues& AND red&(tt) > 95 AND green&(tt) < 96 THEN l$(tt) = "T": GOTO nex:
  148.     NEXT blues&
  149.     FOR reds& = 24 TO 255
  150.         IF red&(tt) = reds& AND blue&(tt) > 95 AND green&(tt) > 95 THEN l$(tt) = " ": GOTO nex:
  151.     NEXT reds&
  152.     FOR greens& = 0 TO 255
  153.         IF green&(tt) = greens& AND blue&(tt) > 95 AND red&(tt) > 95 THEN l$(tt) = " ": GOTO nex:
  154.     NEXT greens&
  155.     FOR blues& = 0 TO 255
  156.         IF blue&(tt) = blues& AND red&(tt) > 95 AND green&(tt) > 95 THEN l$(tt) = " ": GOTO nex:
  157.     NEXT blues&
  158.  
  159.     'Now it puts the text or spaces onto your text file and then ends program.
  160.  
  161.     nex:
  162.     PRINT #1, l$(tt);
  163.     IF tt / 129 = INT(tt / 129) THEN PRINT #1, " "
  164.  
  165. NEXT tt
  166. PRINT nm3$; " has been saved to your computer."
  167.  
  168.  
« Last Edit: July 31, 2019, 02:18:48 am by SierraKen »

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #1 on: July 31, 2019, 01:36:29 am »
FYI - Here is discussion on another one, follow the given link to get the code.
https://qb64forum.alephc.xyz/index.php?topic=978.msg101819#msg101819

It handles the picture using _MEM commands instead of POINT.
« Last Edit: January 31, 2022, 06:32:53 pm by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #2 on: July 31, 2019, 02:09:07 am »
Thanks RhoSigma, I'll check it out.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #3 on: July 31, 2019, 02:17:02 am »
I'm not sure what to get on that thread Rho. It's probably kinda buried with all of the things you have there. I think for now at least, I will try to clean mine up a little bit.

In this update I just changed it so it doesn't have the bottom or side lines.

(Note, look down toward the bottom of the page for a much better one.)

Code: QB64: [Select]
  1. _TITLE "JPG Picture To Text File Artwork Maker"
  2. start:
  3. DIM red&(16000)
  4. DIM green&(16000)
  5. DIM blue&(16000)
  6. DIM l$(16000)
  7. t = 0
  8. PRINT "                    JPG Picture To Text File Artwork Maker"
  9. PRINT "                                 By Ken G."
  10. PRINT "         This program loads 1 JPG picture file that's in the"
  11. PRINT "         same directory as this program and creates a text"
  12. PRINT "         file (.txt) of the same name as your JPG picture and"
  13. PRINT "         as a text file instead that can load in Notepad."
  14. PRINT "         This program only works with non-detailed graphics,"
  15. PRINT "         so a camera picture will not come out."
  16. PRINT "         For example, you can draw something with Microsoft"
  17. PRINT "         Paint and save it as a JPG and load it in this"
  18. PRINT "         to make a text graphic. Because this program has to"
  19. PRINT "         shrink the graphic down (without saving it or"
  20. PRINT "         overwriting any part of the original JPG file),"
  21. PRINT "         the detail of the text file will be very minimal."
  22. PRINT "         Which means it will look funny and non-detailed,"
  23. PRINT "         but I like it and I hope you have some fun with it too."
  24. INPUT "         Press Enter to begin.", st$
  25.  
  26. 'This section loads your picture from your computer.
  27.  
  28. loading:
  29. PRINT "                               Loading"
  30. PRINT "                     Do not add .jpg at the end."
  31. PRINT "                     The jpg picture must be in the same"
  32. PRINT "                     directory as this program is."
  33. PRINT "                     Type the name of your picture file"
  34. PRINT "                     here and press the Enter key."
  35. PRINT "                     Example: MyPic"
  36. PRINT "                     Q and Enter key ends program here."
  37. INPUT "->"; nm2$
  38. IF nm2$ = "Quit" OR nm2$ = "quit" OR nm2$ = "QUIT" OR nm2$ = "Q" OR nm2$ = "q" THEN END
  39. nm$ = nm2$ + ".jpg"
  40. theFileExists = _FILEEXISTS(nm$)
  41. IF theFileExists = 0 THEN
  42.     PRINT "File Does Not Exist."
  43.     PRINT "Would you like to try again (Y/N)"
  44.     PRINT "Esc ends program."
  45.     _LIMIT 10
  46.     llloop2:
  47.     ag$ = INKEY$
  48.     IF ag$ = "" THEN GOTO llloop2:
  49.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  50.     IF ag$ = CHR$(27) THEN END
  51.     GOTO start:
  52.  
  53. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  54.  
  55. SCREEN _NEWIMAGE(128, 120, 32)
  56. i& = _LOADIMAGE(nm$, 32)
  57. _PUTIMAGE (0, 0)-(128, 120), i&
  58.  
  59. FOR y = 1 TO 120
  60.     FOR x = 1 TO 128
  61.         t = t + 1
  62.         c& = POINT(x, y)
  63.         red&(t) = _RED32(c&)
  64.         green&(t) = _GREEN32(c&)
  65.         blue&(t) = _BLUE32(c&)
  66.     NEXT x
  67. SCREEN _NEWIMAGE(640, 480, 32)
  68. nm3$ = nm2$ + ".txt"
  69. OPEN nm3$ FOR OUTPUT AS #1
  70.  
  71. 'This section tries to match your pixel colors to certain text or spaces.
  72.  
  73. FOR tt = 1 TO t
  74.     FOR grays& = 0 TO 255
  75.         IF red&(tt) = grays& AND blue&(tt) = grays& AND green&(tt) = grays& THEN l$(tt) = "O": GOTO nex:
  76.     NEXT grays&
  77.     FOR reds& = 0 TO 255
  78.         IF red&(tt) = reds& AND blue&(tt) < 24 AND green&(tt) < 24 THEN l$(tt) = "#": GOTO nex:
  79.     NEXT reds&
  80.     FOR greens& = 0 TO 255
  81.         IF green&(tt) = greens& AND blue&(tt) < 24 AND red&(tt) < 24 THEN l$(tt) = "@": GOTO nex:
  82.     NEXT greens&
  83.     FOR blues& = 0 TO 255
  84.         IF blue&(tt) = blues& AND red&(tt) < 24 AND green&(tt) < 24 THEN l$(tt) = "*": GOTO nex:
  85.     NEXT blues&
  86.     FOR reds& = 24 TO 255
  87.         IF red&(tt) = reds& AND blue&(tt) > 23 AND green&(tt) < 24 THEN l$(tt) = "$": GOTO nex:
  88.     NEXT reds&
  89.     FOR greens& = 0 TO 255
  90.         IF green&(tt) = greens& AND blue&(tt) > 23 AND red&(tt) < 24 THEN l$(tt) = "%": GOTO nex:
  91.     NEXT greens&
  92.     FOR blues& = 0 TO 255
  93.         IF blue&(tt) = blues& AND red&(tt) > 23 AND green&(tt) < 24 THEN l$(tt) = "^": GOTO nex:
  94.     NEXT blues&
  95.     FOR reds& = 24 TO 255
  96.         IF red&(tt) = reds& AND blue&(tt) < 24 AND green&(tt) > 23 THEN l$(tt) = "&": GOTO nex:
  97.     NEXT reds&
  98.     FOR greens& = 0 TO 255
  99.         IF green&(tt) = greens& AND blue&(tt) < 24 AND red&(tt) > 23 THEN l$(tt) = "(": GOTO nex:
  100.     NEXT greens&
  101.     FOR blues& = 0 TO 255
  102.         IF blue&(tt) = blues& AND red&(tt) < 24 AND green&(tt) > 23 THEN l$(tt) = ")": GOTO nex:
  103.     NEXT blues&
  104.     FOR reds& = 0 TO 255
  105.         IF red&(tt) = reds& AND blue&(tt) < 48 AND green&(tt) < 24 THEN l$(tt) = "A": GOTO nex:
  106.     NEXT reds&
  107.     FOR greens& = 0 TO 255
  108.         IF green&(tt) = greens& AND blue&(tt) < 48 AND red&(tt) < 24 THEN l$(tt) = "B": GOTO nex:
  109.     NEXT greens&
  110.     FOR blues& = 0 TO 255
  111.         IF blue&(tt) = blues& AND red&(tt) < 48 AND green&(tt) < 24 THEN l$(tt) = "C": GOTO nex:
  112.     NEXT blues&
  113.     FOR reds& = 24 TO 255
  114.         IF red&(tt) = reds& AND blue&(tt) > 47 AND green&(tt) < 48 THEN l$(tt) = "D": GOTO nex:
  115.     NEXT reds&
  116.     FOR greens& = 0 TO 255
  117.         IF green&(tt) = greens& AND blue&(tt) > 47 AND red&(tt) < 48 THEN l$(tt) = "E": GOTO nex:
  118.     NEXT greens&
  119.     FOR blues& = 0 TO 255
  120.         IF blue&(tt) = blues& AND red&(tt) > 47 AND green&(tt) < 48 THEN l$(tt) = "F": GOTO nex:
  121.     NEXT blues&
  122.     FOR reds& = 24 TO 255
  123.         IF red&(tt) = reds& AND blue&(tt) < 48 AND green&(tt) > 47 THEN l$(tt) = "G": GOTO nex:
  124.     NEXT reds&
  125.     FOR greens& = 0 TO 255
  126.         IF green&(tt) = greens& AND blue&(tt) < 48 AND red&(tt) > 47 THEN l$(tt) = "H": GOTO nex:
  127.     NEXT greens&
  128.     FOR blues& = 0 TO 255
  129.         IF blue&(tt) = blues& AND red&(tt) < 48 AND green&(tt) > 47 THEN l$(tt) = "I": GOTO nex:
  130.     NEXT blues&
  131.     FOR reds& = 24 TO 255
  132.         IF red&(tt) = reds& AND blue&(tt) < 96 AND green&(tt) > 95 THEN l$(tt) = "J": GOTO nex:
  133.     NEXT reds&
  134.     FOR greens& = 0 TO 255
  135.         IF green&(tt) = greens& AND blue&(tt) < 96 AND red&(tt) > 95 THEN l$(tt) = "K": GOTO nex:
  136.     NEXT greens&
  137.     FOR blues& = 0 TO 255
  138.         IF blue&(tt) = blues& AND red&(tt) < 96 AND green&(tt) > 95 THEN l$(tt) = "L": GOTO nex:
  139.     NEXT blues&
  140.     FOR reds& = 24 TO 255
  141.         IF red&(tt) = reds& AND blue&(tt) > 95 AND green&(tt) < 96 THEN l$(tt) = "M": GOTO nex:
  142.     NEXT reds&
  143.     FOR greens& = 0 TO 255
  144.         IF green&(tt) = greens& AND blue&(tt) > 95 AND red&(tt) < 96 THEN l$(tt) = "N": GOTO nex:
  145.     NEXT greens&
  146.     FOR blues& = 0 TO 255
  147.         IF blue&(tt) = blues& AND red&(tt) > 95 AND green&(tt) < 96 THEN l$(tt) = "T": GOTO nex:
  148.     NEXT blues&
  149.     FOR reds& = 24 TO 255
  150.         IF red&(tt) = reds& AND blue&(tt) > 95 AND green&(tt) > 95 THEN l$(tt) = " ": GOTO nex:
  151.     NEXT reds&
  152.     FOR greens& = 0 TO 255
  153.         IF green&(tt) = greens& AND blue&(tt) > 95 AND red&(tt) > 95 THEN l$(tt) = " ": GOTO nex:
  154.     NEXT greens&
  155.     FOR blues& = 0 TO 255
  156.         IF blue&(tt) = blues& AND red&(tt) > 95 AND green&(tt) > 95 THEN l$(tt) = " ": GOTO nex:
  157.     NEXT blues&
  158.  
  159.     'Now it puts the text or spaces onto your text file and then ends program.
  160.  
  161.     nex:
  162.     IF tt / 128 = INT(tt / 128) OR lines > 118 THEN PRINT #1, " ": lines = lines + 1: GOTO nex2:
  163.     PRINT #1, l$(tt);
  164.     nex2:
  165. NEXT tt
  166. nex3:
  167. PRINT nm3$; " has been saved to your computer."
  168.  
« Last Edit: July 31, 2019, 08:27:34 pm by SierraKen »

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #4 on: July 31, 2019, 03:29:32 am »
I'm not sure what to get on that thread Rho. It's probably kinda buried with all of the things you have there.

Easy way :)
Follow the link in my signature, from that post download the QB64Library.7z, extract it into your QB64 folder.
Now look into folder QB64Library\IMG-Support\example, there is a file called AsciiArtDemo.bas...
« Last Edit: August 01, 2019, 01:45:10 pm by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #5 on: July 31, 2019, 04:58:35 am »
Hi SierraKen

 Must we we must open the .txt file with a text editor to see the result ?
Programming isn't difficult, only it's  consuming time and coffee

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #6 on: July 31, 2019, 05:15:27 am »
I think you must use a fixed size police to see the result. (courier, mslinedraw...)

Good program of course, and usefull to see how you do this.

But for this job, I use a little programme named "img2ascii.exe" (needs no installation under Win) who gives good results...



Why not yes ?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #7 on: July 31, 2019, 01:19:04 pm »
Very nice work, SierraKen.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #8 on: July 31, 2019, 03:19:00 pm »
Woah Rho! That's incredible! It's a bit past my experience in programming though, I would have to study each line carefully if I want to make something as good as that. And many of those commands are ones I don't know of, so it would take awhile. And you have already made it, so I really don't have a will to copy it. But Great Job!
I think I will try to make mine a little better if I can.

TempodiBasic, I guess I can make a view screen, or open it with a SHELL command, will see what I can do, thanks!

Euklides, if I understand you right, do you mean the vertical is too much in the output? Yeah I noticed that too, will look into that to see what I can do, if anything.

Thanks Petr! Like the rest of my programs, this is just something to play around with.

« Last Edit: July 31, 2019, 03:23:03 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #9 on: July 31, 2019, 04:56:03 pm »
I decided to change it by using semi-random text characters, just adding the red, blue, and green (dividing each by 3 first to get 255 total) and then making THAT number the CHR$ number. I had to check the chart to remove the first 32 non-characters and 1 more so they would show up. I also changed the size of the output to pretty much the same width now as the original picture. It will show the original picture twice as wide in the tiny picture at first, but that only happens because text is twice as high as width, which I had forgotten, so the output is the normal size on the text file. I also added a SHELL command at the end to view the picture with Notepad (or whatever you use for .txt files) automatically without having to hunt for it. I'm guessing Windows computers are the only ones that can use the SHELL command? I really don't know. Anyway, using CHR$ makes the picture show up a lot when there's a lot of white or filled in areas. But on the other hand, I'm sure it will make a mess out of graphics with many different details. Check it out and tell me what you think. Thanks.

(Note: I made an even better one below on this page, than this one.)

Code: QB64: [Select]
  1. _TITLE "JPG Picture To Text File Artwork Maker"
  2. start:
  3. DIM red&(31000)
  4. DIM green&(31000)
  5. DIM blue&(31000)
  6. DIM l$(31000)
  7. t = 0
  8. PRINT "                    JPG Picture To Text File Artwork Maker"
  9. PRINT "                                 By Ken G."
  10. PRINT "         This program loads 1 JPG picture file that's in the"
  11. PRINT "         same directory as this program and creates a text"
  12. PRINT "         file (.txt) of the same name as your JPG picture and"
  13. PRINT "         as a text file instead that can load in Notepad."
  14. PRINT "         This program only works with non-detailed graphics,"
  15. PRINT "         so a camera picture will not come out."
  16. PRINT "         For example, you can draw something with Microsoft"
  17. PRINT "         Paint and save it as a JPG and load it in this"
  18. PRINT "         to make a text graphic. Because this program has to"
  19. PRINT "         shrink the graphic down (without saving it or"
  20. PRINT "         overwriting any part of the original JPG file),"
  21. PRINT "         the detail of the text file will be very minimal."
  22. PRINT "         Which means it will look funny and non-detailed,"
  23. PRINT "         but I like it and I hope you have some fun with it too."
  24. INPUT "         Press Enter to begin.", st$
  25.  
  26. 'This section loads your picture from your computer.
  27.  
  28. loading:
  29. PRINT "                               Loading"
  30. PRINT "                     Do not add .jpg at the end."
  31. PRINT "                     The jpg picture must be in the same"
  32. PRINT "                     directory as this program is."
  33. PRINT "                     Type the name of your picture file"
  34. PRINT "                     here and press the Enter key."
  35. PRINT "                     Example: MyPic"
  36. PRINT "                     Q and Enter key ends program here."
  37. INPUT "->"; nm2$
  38. IF nm2$ = "Quit" OR nm2$ = "quit" OR nm2$ = "QUIT" OR nm2$ = "Q" OR nm2$ = "q" THEN END
  39. nm$ = nm2$ + ".jpg"
  40. theFileExists = _FILEEXISTS(nm$)
  41. IF theFileExists = 0 THEN
  42.     PRINT "File Does Not Exist."
  43.     PRINT "Would you like to try again (Y/N)"
  44.     PRINT "Esc ends program."
  45.     _LIMIT 10
  46.     llloop2:
  47.     ag$ = INKEY$
  48.     IF ag$ = "" THEN GOTO llloop2:
  49.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  50.     IF ag$ = CHR$(27) THEN END
  51.     GOTO start:
  52.  
  53. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  54.  
  55. SCREEN _NEWIMAGE(256, 120, 32)
  56. i& = _LOADIMAGE(nm$, 32)
  57. _PUTIMAGE (0, 0)-(256, 120), i&
  58.  
  59. FOR y = 1 TO 120
  60.     FOR x = 1 TO 256
  61.         t = t + 1
  62.         c& = POINT(x, y)
  63.         red&(t) = _RED32(c&)
  64.         green&(t) = _GREEN32(c&)
  65.         blue&(t) = _BLUE32(c&)
  66.     NEXT x
  67. SCREEN _NEWIMAGE(640, 480, 32)
  68. nm3$ = nm2$ + ".txt"
  69. OPEN nm3$ FOR OUTPUT AS #1
  70.  
  71. 'This section tries to match your pixel colors to certain text or spaces.
  72.  
  73. FOR tt = 1 TO t
  74.  
  75.     'Now it puts the text or spaces onto your text file and then ends program.
  76.     IF red&(tt) = 255 AND green&(tt) = 255 AND blue&(tt) = 255 THEN l$(tt) = " ": GOTO nex:
  77.     rr = INT(red&(tt) / 3)
  78.     gg = INT(green&(tt) / 3)
  79.     bb = INT(blue&(tt) / 3)
  80.     colors = (rr + gg + bb)
  81.     IF colors < 33 THEN colors = 33
  82.     IF colors = 127 THEN colors = 128
  83.     IF colors = 255 THEN colors = 254
  84.     l$(tt) = CHR$(colors)
  85.     nex:
  86.     IF tt / 256 = INT(tt / 256) THEN PRINT #1, " ": GOTO nex2:
  87.     PRINT #1, l$(tt);
  88.     nex2:
  89. NEXT tt
  90. nex3:
  91. PRINT nm3$; " has been saved to your computer."
  92. INPUT "Press Enter to see your new text on your .txt viewing program.", aa$
  93. SHELL nm3$
  94.  
  95.  
« Last Edit: July 31, 2019, 08:28:16 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #10 on: July 31, 2019, 08:26:43 pm »
And like usual... I MADE IT BETTER!!! LOL I studied RhoSigma's ASCIIART program, and found 2 little things that I could use in my program. First, I changed it so it doesn't use colors, it uses shades, which made it really simple to just add _RED32, _GREEN32, and _BLUE32 together and the highest number is the brightest shade. I still use the POINT command, so that part is the same. But then I found a web page of a list of the lightest to darkest ASCII characters, so I ended up using 68 characters, from lightest to darkest on 1 string. Which made it incredibly simple to just use MID$, like RhoSigma did on his, to pick out which character is needed from the string. And it comes out pretty good with simple graphics. It still doesn't work with camera pictures, so it's not as good as Rho's, but I like mine a lot. What mine does do, which Rho didn't add, is make the .txt file and lets you see it in Notepad, or whatever .txt program you use that the SHELL command can find. You still don't see the outcome in the program itself, that got too hard because my outcome texts are very large. So at least with Notepad, etc. you can use the slide bars to see it all.  Tell me what you think all. I been working on this off and on all day and I think I got it wrapped.

(And below this one, on this forum page, I have one that includes seeing the output on the program itself before you make a text file of it, so scroll down.)

Code: QB64: [Select]
  1. _TITLE "JPG Graphics To Text File Artwork Maker"
  2. start:
  3. DIM red&(31000)
  4. DIM green&(31000)
  5. DIM blue&(31000)
  6. DIM l$(31000)
  7. t = 0
  8. PRINT "                    JPG Graphics To Text File Artwork Maker"
  9. PRINT "                                 By Ken G."
  10. PRINT "         This program loads 1 JPG graphic file that's in the"
  11. PRINT "         same directory as this program and creates a text"
  12. PRINT "         file (.txt) of the same name as your JPG file and"
  13. PRINT "         as a text file instead that can load in Notepad."
  14. PRINT "         This program only works with non-detailed graphics,"
  15. PRINT "         so a camera picture will not come out."
  16. PRINT "         For example, you can draw something with Microsoft"
  17. PRINT "         Paint and save it as a JPG and load it in this"
  18. PRINT "         to make a text graphic. Because this program has to"
  19. PRINT "         shrink the graphic down (without saving it or"
  20. PRINT "         overwriting any part of the original JPG file),"
  21. PRINT "         the detail of the text file will be very minimal."
  22. PRINT "         Which means it will look funny and non-detailed,"
  23. PRINT "         but I like it and I hope you have some fun with it too."
  24. INPUT "         Press Enter to begin.", st$
  25.  
  26. 'This section loads your picture from your computer.
  27.  
  28. loading:
  29. PRINT "                               Loading"
  30. PRINT "                     Do not add .jpg at the end."
  31. PRINT "                     The jpg picture must be in the same"
  32. PRINT "                     directory as this program is."
  33. PRINT "                     Type the name of your picture file"
  34. PRINT "                     here and press the Enter key."
  35. PRINT "                     Example: MyPic"
  36. PRINT "                     Q and Enter key ends program here."
  37. INPUT "->"; nm2$
  38. IF nm2$ = "Q" OR nm2$ = "q" THEN END
  39. nm$ = nm2$ + ".jpg"
  40. theFileExists = _FILEEXISTS(nm$)
  41. IF theFileExists = 0 THEN
  42.     PRINT "File Does Not Exist."
  43.     PRINT "Would you like to try again (Y/N)"
  44.     PRINT "Esc ends program."
  45.     _LIMIT 10
  46.     llloop2:
  47.     ag$ = INKEY$
  48.     IF ag$ = "" THEN GOTO llloop2:
  49.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  50.     IF ag$ = CHR$(27) THEN END
  51.     GOTO start:
  52.  
  53. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  54.  
  55. SCREEN _NEWIMAGE(256, 120, 32)
  56. i& = _LOADIMAGE(nm$, 32)
  57. _PUTIMAGE (0, 0)-(256, 120), i&
  58.  
  59. FOR y = 1 TO 120
  60.     FOR x = 1 TO 256
  61.         t = t + 1
  62.         c& = POINT(x, y)
  63.         red&(t) = _RED32(c&)
  64.         green&(t) = _GREEN32(c&)
  65.         blue&(t) = _BLUE32(c&)
  66.     NEXT x
  67. SCREEN _NEWIMAGE(640, 480, 32)
  68. nm3$ = nm2$ + ".txt"
  69. OPEN nm3$ FOR OUTPUT AS #1
  70.  
  71. 'This section matches your pixel shades to certain text or spaces.
  72.  
  73. text$ = " .'`^,:;Il!i<>~+_-?[]{}1()|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
  74.  
  75. FOR tt = 1 TO t
  76.     shade = red&(tt) + green&(tt) + blue&(tt)
  77.     shade = INT(shade / 11)
  78.     l$(tt) = MID$(text$, shade, 1)
  79.     IF tt / 256 = INT(tt / 256) THEN PRINT #1, " ": GOTO nex2:
  80.     PRINT #1, l$(tt);
  81.     nex2:
  82. NEXT tt
  83. PRINT nm3$; " has been saved to your computer."
  84. INPUT "Press Enter to see your new text on your .txt viewing program such as Notepad.", aa$
  85. SHELL nm3$
  86.  
« Last Edit: July 31, 2019, 09:53:22 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #11 on: July 31, 2019, 09:52:04 pm »
Well, because someone asked, and I thought it was a cool idea, I added the feature to see the output inside the program before it makes the .txt file. So now, after you type in the name of the picture, you see the text version on the screen in the program. Then it asks if you want to make a .txt file of it. If you don't say yes (or anything that starts with y), then it will end.
Also, I figured out that the largest graphic you can use with this is 800 x 600. Any larger and it messes up.

(Another one after this makes it easier to see on Notepad without using the horizontal bar... so keep scrolling please.)

Code: QB64: [Select]
  1. _TITLE "JPG Graphics To Text File Artwork Maker"
  2. start:
  3. DIM red&(31000)
  4. DIM green&(31000)
  5. DIM blue&(31000)
  6. DIM l$(31000)
  7. t = 0
  8. PRINT "                    JPG Graphics To Text File Artwork Maker"
  9. PRINT "                                 By Ken G."
  10. PRINT "         This program loads 1 JPG graphics file that's in the"
  11. PRINT "         same directory as this program and creates a text"
  12. PRINT "         file (.txt) of the same name as your JPG file and"
  13. PRINT "         as a text file instead that can load in Notepad."
  14. PRINT "         This program only works with non-detailed graphics,"
  15. PRINT "         so a camera picture will not come out."
  16. PRINT "         For example, you can draw something with Microsoft"
  17. PRINT "         Paint and save it as a JPG and load it in this"
  18. PRINT "         to make a text graphic. Because this program has to"
  19. PRINT "         shrink the graphic down (without saving it or"
  20. PRINT "         overwriting any part of the original JPG file),"
  21. PRINT "         the detail of the text file will be very minimal."
  22. PRINT "         Which means it will look funny and non-detailed,"
  23. PRINT "         but I like it and I hope you have some fun with it too."
  24. INPUT "         Press Enter to begin.", st$
  25.  
  26. 'This section loads your picture from your computer.
  27.  
  28. loading:
  29. PRINT "                               Loading"
  30. PRINT "                     Do not add .jpg at the end."
  31. PRINT "                     The jpg picture must be in the same"
  32. PRINT "                     directory as this program is."
  33. PRINT "                     Type the name of your picture file"
  34. PRINT "                     here and press the Enter key."
  35. PRINT "                     Only use a graphic no larger than"
  36. PRINT "                     800 x 600 pixels."
  37. PRINT "                     Example: MyPic"
  38. PRINT "                     Q and Enter key ends program here."
  39. INPUT "->"; nm2$
  40. IF nm2$ = "Q" OR nm2$ = "q" THEN END
  41. nm$ = nm2$ + ".jpg"
  42. theFileExists = _FILEEXISTS(nm$)
  43. IF theFileExists = 0 THEN
  44.     PRINT "File Does Not Exist."
  45.     PRINT "Would you like to try again (Y/N)"
  46.     PRINT "Esc ends program."
  47.     _LIMIT 10
  48.     llloop2:
  49.     ag$ = INKEY$
  50.     IF ag$ = "" THEN GOTO llloop2:
  51.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  52.     IF ag$ = CHR$(27) THEN END
  53.     GOTO start:
  54.  
  55. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  56.  
  57. SCREEN _NEWIMAGE(64, 40, 32)
  58. i& = _LOADIMAGE(nm$, 32)
  59. _PUTIMAGE (0, 0)-(64, 40), i&
  60. FOR y = 1 TO 40
  61.     FOR x = 1 TO 64
  62.         a = a + 1
  63.         c& = POINT(x, y)
  64.         red&(a) = _RED32(c&)
  65.         green&(a) = _GREEN32(c&)
  66.         blue&(a) = _BLUE32(c&)
  67.     NEXT x
  68. SCREEN _NEWIMAGE(1000, 800, 32)
  69. text$ = " .'`^,:;Il!i<>~+_-?[]{}1()|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
  70.  
  71. FOR ttt = 1 TO a
  72.     shade = red&(ttt) + green&(ttt) + blue&(ttt)
  73.     shade = INT(shade / 11)
  74.     l$(ttt) = MID$(text$, shade, 1)
  75.     IF ttt / 64 = INT(ttt / 64) THEN PRINT: GOTO nex1:
  76.     PRINT l$(ttt);
  77.     nex1:
  78. NEXT ttt
  79. LOCATE 49, 1: INPUT "Do you want to make a .txt file of this (Y/N)"; cc$
  80. IF LEFT$(cc$, 1) = "y" OR LEFT$(cc$, 1) = "Y" THEN GOTO more:
  81. more:
  82.  
  83. 'This section has to do with making the text file.
  84.  
  85. SCREEN _NEWIMAGE(256, 120, 32)
  86. i& = _LOADIMAGE(nm$, 32)
  87. _PUTIMAGE (0, 0)-(256, 120), i&
  88. FOR y = 1 TO 120
  89.     FOR x = 1 TO 256
  90.         t = t + 1
  91.         c& = POINT(x, y)
  92.         red&(t) = _RED32(c&)
  93.         green&(t) = _GREEN32(c&)
  94.         blue&(t) = _BLUE32(c&)
  95.     NEXT x
  96. SCREEN _NEWIMAGE(640, 480, 32)
  97.  
  98. nm3$ = nm2$ + ".txt"
  99. OPEN nm3$ FOR OUTPUT AS #1
  100.  
  101. FOR tt = 1 TO t
  102.     shade = red&(tt) + green&(tt) + blue&(tt)
  103.     shade = INT(shade / 11)
  104.     l$(tt) = MID$(text$, shade, 1)
  105.     IF tt / 256 = INT(tt / 256) THEN PRINT #1, " ": GOTO nex2:
  106.     PRINT #1, l$(tt);
  107.     nex2:
  108. NEXT tt
  109. PRINT nm3$; " has been saved to your computer."
  110. INPUT "Press Enter to see your new text on your .txt viewing program such as Notepad.", aa$
  111. SHELL nm3$
  112.  
  113.  
« Last Edit: July 31, 2019, 10:12:30 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #12 on: July 31, 2019, 10:10:47 pm »
Sorry for so many postings. This time I made it so it's easier to see on Notepad without scrolling the horizontal bar. I tried to print it like that but it's still too wide of text for that, just so you know. But you might be able to change the Font in Notepad to much smaller to print and it might fit all on 1 page, I haven't tried it yet. This one also uses a lot less memory than the others.

(Note: Yep, yet another better one after this one on this forum page, keep scrolling.)

Code: QB64: [Select]
  1. _TITLE "JPG Graphics To Text File Artwork Maker"
  2. start:
  3. DIM red&(8000)
  4. DIM green&(8000)
  5. DIM blue&(8000)
  6. DIM l$(8000)
  7. t = 0
  8. PRINT "                    JPG Graphics To Text File Artwork Maker"
  9. PRINT "                                 By Ken G."
  10. PRINT "         This program loads 1 JPG graphics file that's in the"
  11. PRINT "         same directory as this program and creates a text"
  12. PRINT "         file (.txt) of the same name as your JPG file and"
  13. PRINT "         as a text file instead that can load in Notepad."
  14. PRINT "         This program only works with non-detailed graphics,"
  15. PRINT "         so a camera picture will not come out."
  16. PRINT "         For example, you can draw something with Microsoft"
  17. PRINT "         Paint and save it as a JPG and load it in this"
  18. PRINT "         to make a text graphic. Because this program has to"
  19. PRINT "         shrink the graphic down (without saving it or"
  20. PRINT "         overwriting any part of the original JPG file),"
  21. PRINT "         the detail of the text file will be very minimal."
  22. PRINT "         Which means it will look funny and non-detailed,"
  23. PRINT "         but I like it and I hope you have some fun with it too."
  24. INPUT "         Press Enter to begin.", st$
  25.  
  26. 'This section loads your picture from your computer.
  27.  
  28. loading:
  29. PRINT "                               Loading"
  30. PRINT "                     Do not add .jpg at the end."
  31. PRINT "                     The jpg picture must be in the same"
  32. PRINT "                     directory as this program is."
  33. PRINT "                     Type the name of your picture file"
  34. PRINT "                     here and press the Enter key."
  35. PRINT "                     Only use a graphic no larger than"
  36. PRINT "                     800 x 600 pixels."
  37. PRINT "                     Example: MyPic"
  38. PRINT "                     Q and Enter key ends program here."
  39. INPUT "->"; nm2$
  40. IF nm2$ = "Q" OR nm2$ = "q" THEN END
  41. nm$ = nm2$ + ".jpg"
  42. theFileExists = _FILEEXISTS(nm$)
  43. IF theFileExists = 0 THEN
  44.     PRINT "File Does Not Exist."
  45.     PRINT "Would you like to try again (Y/N)"
  46.     PRINT "Esc ends program."
  47.     _LIMIT 10
  48.     llloop2:
  49.     ag$ = INKEY$
  50.     IF ag$ = "" THEN GOTO llloop2:
  51.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  52.     IF ag$ = CHR$(27) THEN END
  53.     GOTO start:
  54.  
  55. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  56.  
  57. SCREEN _NEWIMAGE(64, 40, 32)
  58. i& = _LOADIMAGE(nm$, 32)
  59. _PUTIMAGE (0, 0)-(64, 40), i&
  60. FOR y = 1 TO 40
  61.     FOR x = 1 TO 64
  62.         a = a + 1
  63.         c& = POINT(x, y)
  64.         red&(a) = _RED32(c&)
  65.         green&(a) = _GREEN32(c&)
  66.         blue&(a) = _BLUE32(c&)
  67.     NEXT x
  68. SCREEN _NEWIMAGE(1000, 800, 32)
  69. text$ = " .'`^,:;Il!i<>~+_-?[]{}1()|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
  70.  
  71. FOR ttt = 1 TO a
  72.     shade = red&(ttt) + green&(ttt) + blue&(ttt)
  73.     shade = INT(shade / 11)
  74.     l$(ttt) = MID$(text$, shade, 1)
  75.     IF ttt / 64 = INT(ttt / 64) THEN PRINT: GOTO nex1:
  76.     PRINT l$(ttt);
  77.     nex1:
  78. NEXT ttt
  79. LOCATE 49, 1: INPUT "Do you want to make a .txt file of this (Y/N)"; cc$
  80. IF LEFT$(cc$, 1) = "y" OR LEFT$(cc$, 1) = "Y" THEN GOTO more:
  81. more:
  82.  
  83. 'This section has to do with making the text file.
  84.  
  85. SCREEN _NEWIMAGE(128, 60, 32)
  86. i& = _LOADIMAGE(nm$, 32)
  87. _PUTIMAGE (0, 0)-(128, 60), i&
  88. FOR y = 1 TO 60
  89.     FOR x = 1 TO 128
  90.         t = t + 1
  91.         c& = POINT(x, y)
  92.         red&(t) = _RED32(c&)
  93.         green&(t) = _GREEN32(c&)
  94.         blue&(t) = _BLUE32(c&)
  95.     NEXT x
  96. SCREEN _NEWIMAGE(640, 480, 32)
  97.  
  98. nm3$ = nm2$ + ".txt"
  99. OPEN nm3$ FOR OUTPUT AS #1
  100.  
  101. FOR tt = 1 TO t
  102.     shade = red&(tt) + green&(tt) + blue&(tt)
  103.     shade = INT(shade / 11)
  104.     l$(tt) = MID$(text$, shade, 1)
  105.     IF tt / 128 = INT(tt / 128) THEN PRINT #1, " ": GOTO nex2:
  106.     PRINT #1, l$(tt);
  107.     nex2:
  108. NEXT tt
  109. PRINT nm3$; " has been saved to your computer."
  110. INPUT "Press Enter to see your new text on your .txt viewing program such as Notepad.", aa$
  111. SHELL nm3$
  112.  

« Last Edit: August 01, 2019, 01:34:31 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #13 on: August 01, 2019, 01:32:54 am »
OK, I'm not going for a World Record on postings here.. lol.. but tonight I spruced this puppy up as much as possible. I changed the font size to make the text picture look better in the program and reduced the size of the .txt file so that if people want to, they can change Notepad (or whatever they use for .txt files) to font size 8 or so and be able to print it good with their printer. I tried it and it works great. I hope some of you aren't tired of all these postings yet. Most likely this will be the last version. There's nothing more I need with it. So, here you go. :) Enjoy.

Code: QB64: [Select]
  1. _TITLE "JPG Graphics To Text Artwork Maker"
  2. start:
  3. DIM red&(4000)
  4. DIM green&(4000)
  5. DIM blue&(4000)
  6. DIM l$(4000)
  7. t = 0
  8. a = 0
  9. PRINT "                     JPG Graphics To Text Artwork Maker"
  10. PRINT "                                By Ken G."
  11. PRINT "     This program loads JPG graphics files that are the same directory"
  12. PRINT "     as this program and creates a text file (.txt) of the same name"
  13. PRINT "     as your JPG file as a text file instead that can load in Notepad."
  14. PRINT "     This program will not change your original JPG file in any way."
  15. PRINT "     This program only works with non-detailed graphics, a camera"
  16. PRINT "     picture will not come out."
  17. PRINT "     For example, you can draw something with Microsoft Paint and save"
  18. PRINT "     it as a JPG and load it in this to make a text graphic. Because"
  19. PRINT "     this program has to shrink the graphic down (in memory only) the"
  20. PRINT "     detail of the text file will be very minimal."
  21. PRINT "     Which means it will look funny and non-detailed, but I like it"
  22. PRINT "     and I hope you have some fun with it too."
  23. INPUT "                         Press Enter to begin.", st$
  24.  
  25. 'This section loads your picture from your computer.
  26.  
  27. loading:
  28. PRINT "                               Loading"
  29. PRINT "                     Do not add .jpg at the end."
  30. PRINT "                     The jpg picture must be in the same"
  31. PRINT "                     directory as this program is."
  32. PRINT "                     Type the name of your picture file"
  33. PRINT "                     here and press the Enter key."
  34. PRINT "                     Only use a graphic no larger than"
  35. PRINT "                     800 x 600 pixels."
  36. PRINT "                     Example: MyPic"
  37. PRINT "                     Q and Enter key ends program here."
  38. INPUT "->"; nm2$
  39. IF nm2$ = "Q" OR nm2$ = "q" THEN PRINT "Goodbye.": END
  40. nm$ = nm2$ + ".jpg"
  41. theFileExists = _FILEEXISTS(nm$)
  42. IF theFileExists = 0 THEN
  43.     PRINT "File Does Not Exist."
  44.     PRINT "Would you like to try again (Y/N)"
  45.     PRINT "Esc ends program."
  46.     _LIMIT 10
  47.     llloop2:
  48.     ag$ = INKEY$
  49.     IF ag$ = "" THEN GOTO llloop2:
  50.     IF ag$ = "y" OR ag$ = "Y" THEN GOTO loading:
  51.     IF ag$ = CHR$(27) THEN PRINT "Goodbye.": END
  52.     GOTO start:
  53.  
  54. 'This section reads your picture file and puts the red, green, and blue numbers into memory.
  55.  
  56. SCREEN _NEWIMAGE(64, 60, 32)
  57. i& = _LOADIMAGE(nm$, 32)
  58. _PUTIMAGE (0, 0)-(64, 60), i&
  59. FOR y = 1 TO 60
  60.     FOR x = 1 TO 64
  61.         a = a + 1
  62.         c& = POINT(x, y)
  63.         red&(a) = _RED32(c&)
  64.         green&(a) = _GREEN32(c&)
  65.         blue&(a) = _BLUE32(c&)
  66.     NEXT x
  67. SCREEN _NEWIMAGE(1000, 800, 32)
  68. text$ = " .'`^,:;Il!i<>~+_-?[]{}1()|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
  69. WIDTH 63, 80
  70. FOR ttt = 1 TO a
  71.     shade = red&(ttt) + green&(ttt) + blue&(ttt)
  72.     shade = INT(shade / 11)
  73.     l$(ttt) = MID$(text$, shade, 1)
  74.     IF ttt / 64 = INT(ttt / 64) THEN PRINT: GOTO nex1:
  75.     PRINT l$(ttt);
  76.     nex1:
  77. NEXT ttt
  78. LOCATE 39, 1: INPUT "Do you want to make a .txt file of this (Y/N)"; cc$
  79. IF LEFT$(cc$, 1) = "y" OR LEFT$(cc$, 1) = "Y" THEN GOTO more:
  80. PRINT "Goodbye."
  81. more:
  82.  
  83. 'This section has to do with making the text file.
  84.  
  85. SCREEN _NEWIMAGE(85, 40, 32)
  86. i& = _LOADIMAGE(nm$, 32)
  87. _PUTIMAGE (0, 0)-(85, 40), i&
  88. FOR y = 1 TO 40
  89.     FOR x = 1 TO 85
  90.         t = t + 1
  91.         c& = POINT(x, y)
  92.         red&(t) = _RED32(c&)
  93.         green&(t) = _GREEN32(c&)
  94.         blue&(t) = _BLUE32(c&)
  95.     NEXT x
  96. SCREEN _NEWIMAGE(640, 480, 32)
  97.  
  98. nm3$ = nm2$ + ".txt"
  99. OPEN nm3$ FOR OUTPUT AS #1
  100.  
  101. FOR tt = 1 TO t
  102.     shade = red&(tt) + green&(tt) + blue&(tt)
  103.     shade = INT(shade / 11)
  104.     l$(tt) = MID$(text$, shade, 1)
  105.     IF tt / 85 = INT(tt / 85) THEN PRINT #1, " ": GOTO nex2:
  106.     PRINT #1, l$(tt);
  107.     nex2:
  108. NEXT tt
  109. PRINT nm3$; " has been saved to your computer."
  110. PRINT "Feel free to change the font size on your .txt viewer (like Notepad)"
  111. PRINT "to font size 8 or so to be able to print on your printer."
  112. INPUT "Press Enter to see your new text on your .txt viewer (like Notepad).", aa$
  113. PRINT "Goodbye."
  114.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: JPG Graphic To Text Artwork Maker
« Reply #14 on: August 01, 2019, 07:29:22 am »
Cool
It works fine!
Programming isn't difficult, only it's  consuming time and coffee