furball1985
Experienced Member
- Joined
- Jul 14, 2022
- Messages
- 128
----------------------
the evolution of the JPGtoFABGL SCRIPT
# Ver 0.5 12/1/2023
# By John Galt Furball1985
from PIL import Image
import sys, termios, tty, os, time
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
# python JPGTOFABGL % A T 0 0
arg1 = sys.argv[1] # filename
arg2 = sys.argv[2] # Auto, Semi, Manual mode
arg3 = sys.argv[3] # T transparency 'T' or not 'N'ot a 't'
arg4 = sys.argv[4] # X
arg5 = sys.argv[5] # Y
esc=chr(27)
FILENAME=arg1 #image can be in gif jpeg or png format
im=Image.open(FILENAME).convert('RGB')
pix=im.load()
w=im.size[0]
h=im.size[1]
YY=w
XX=h
# Automatic mode one image centered screen
if arg2=="A" or arg2=="a":
PS=512-YY
PS2=384-XX
PS=PS/2
PS2=PS2/2 # The Picture in the Center of the screen X: PS2 Y: PS
offsetx=PS
offsety=PS2
# Semi-Automatic mode user positions possible center,left,right,middle
if arg2=="S" or arg2=="s":
key = getch()
if key=="L" or key=="l": #image left-top
offsetx=128-(YY/2)
offsety=40
elif key=="R" or key=="r": #image right-top
offsetx=384-(YY/2)
offsety=40
elif key=="M" or key=="m": #image middle-top
offsetx=256-(YY/2)
offsety=40
elif key=="C" or key=="c": #image centered on screen
PS=512-YY
PS2=384-XX
PS=PS/2
PS2=PS2/2
offsetx=PS
offsety=PS2
elif key=="Q" or key=="q" or key==chr(27):
exit(0)
else:
exit(0)
# Manual Mode
if arg2=="M" or arg2=="m": # Honor user X,Y from Command prompt
offsetx=int(arg5)
offsety=int(arg4)
# OUTPUT TO FABGL TERMINAL IN COLOR
if w<=500 and h<=350: # Range check to make sure we don't go nuts 500 x 350 resolution
for i in range(w):
for j in range(h):
if arg3=="T" or arg3=="t":
# IMAGE IS TRANSPARENT
if pix[i,j][0]<>0 and pix[i,j][1]<>0 and pix[i,j][2]<>0:
print(esc+"[H")
print(esc+"_GPEN"+str(pix[i,j][0])+";"+str(pix[i,j][1])+";"+str(pix[i,j][2]))
print(esc+"_GPIXEL"+str(i+offsetx)+";"+str(j+offsety))
else:
# IMAGE IS NOT TRANSPARENT
print(esc+"[H")
print(esc+"_GPEN"+str(pix[i,j][0])+";"+str(pix[i,j][1])+";"+str(pix[i,j][2]))
print(esc+"_GPIXEL"+str(i+offsetx)+";"+str(j+offsety))
print (esc+"_F0;15")
print (esc+"_GPEN255;255;255")
----------------------------------------------------
the indents do not display correctly on the forums eventually this will be on my github
explanation:
Because of the way 'elinks' and scripts work you don't have interaction normally with them.
I have setup the script to work 3 ways.
1)Automatic
2)Semi-Automatic
3)Manual
there is also transparency support
you setup how you want the script to run from the elinks handler
set mime.handler.image_viewer.unix.program = "python jpgtofabgl % A N 0 0"
this set the script to automatic with no transparency, transparency is to treat the color black as solid or see through.
set mime.handler.image_viewer.unix.program = "python jpgtofabgl % A T 0 0"
this sets the script to automatic with Transparency
set mime.handler.image_viewer.unix.program = "python jpgtofabgl % M N 100 100"
this sets the script to manual no transparency and start the picture at 100,100
when in Automatic you can only display one picture located in the center of the terminal screen
when in Semi Automatic you can display pictures in 4 position. you will not be prompted but you can press L/l,R/r,M/m,C/c this will place 3 pictures at the top and 1 in the center of the screen depending on your keypress.
any mistake in keypress will exit back to the browser and you can try again.
this way its very customizable or ready to go.
i have to bug test it extensively but you can get an idea of what is going on.
python makes it REALLY hard to Pole the keyboard inside a loop basically they don't want unseen keyboard input since it can be used as a key logger.
in working with GIMP i'm now able to pre dither the photos and don't have to worry about any post processes.
i hope to put up a test page with jpg images and then play around with the new script.
the evolution of the JPGtoFABGL SCRIPT
# Ver 0.5 12/1/2023
# By John Galt Furball1985
from PIL import Image
import sys, termios, tty, os, time
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
# python JPGTOFABGL % A T 0 0
arg1 = sys.argv[1] # filename
arg2 = sys.argv[2] # Auto, Semi, Manual mode
arg3 = sys.argv[3] # T transparency 'T' or not 'N'ot a 't'
arg4 = sys.argv[4] # X
arg5 = sys.argv[5] # Y
esc=chr(27)
FILENAME=arg1 #image can be in gif jpeg or png format
im=Image.open(FILENAME).convert('RGB')
pix=im.load()
w=im.size[0]
h=im.size[1]
YY=w
XX=h
# Automatic mode one image centered screen
if arg2=="A" or arg2=="a":
PS=512-YY
PS2=384-XX
PS=PS/2
PS2=PS2/2 # The Picture in the Center of the screen X: PS2 Y: PS
offsetx=PS
offsety=PS2
# Semi-Automatic mode user positions possible center,left,right,middle
if arg2=="S" or arg2=="s":
key = getch()
if key=="L" or key=="l": #image left-top
offsetx=128-(YY/2)
offsety=40
elif key=="R" or key=="r": #image right-top
offsetx=384-(YY/2)
offsety=40
elif key=="M" or key=="m": #image middle-top
offsetx=256-(YY/2)
offsety=40
elif key=="C" or key=="c": #image centered on screen
PS=512-YY
PS2=384-XX
PS=PS/2
PS2=PS2/2
offsetx=PS
offsety=PS2
elif key=="Q" or key=="q" or key==chr(27):
exit(0)
else:
exit(0)
# Manual Mode
if arg2=="M" or arg2=="m": # Honor user X,Y from Command prompt
offsetx=int(arg5)
offsety=int(arg4)
# OUTPUT TO FABGL TERMINAL IN COLOR
if w<=500 and h<=350: # Range check to make sure we don't go nuts 500 x 350 resolution
for i in range(w):
for j in range(h):
if arg3=="T" or arg3=="t":
# IMAGE IS TRANSPARENT
if pix[i,j][0]<>0 and pix[i,j][1]<>0 and pix[i,j][2]<>0:
print(esc+"[H")
print(esc+"_GPEN"+str(pix[i,j][0])+";"+str(pix[i,j][1])+";"+str(pix[i,j][2]))
print(esc+"_GPIXEL"+str(i+offsetx)+";"+str(j+offsety))
else:
# IMAGE IS NOT TRANSPARENT
print(esc+"[H")
print(esc+"_GPEN"+str(pix[i,j][0])+";"+str(pix[i,j][1])+";"+str(pix[i,j][2]))
print(esc+"_GPIXEL"+str(i+offsetx)+";"+str(j+offsety))
print (esc+"_F0;15")
print (esc+"_GPEN255;255;255")
----------------------------------------------------
the indents do not display correctly on the forums eventually this will be on my github
explanation:
Because of the way 'elinks' and scripts work you don't have interaction normally with them.
I have setup the script to work 3 ways.
1)Automatic
2)Semi-Automatic
3)Manual
there is also transparency support
you setup how you want the script to run from the elinks handler
set mime.handler.image_viewer.unix.program = "python jpgtofabgl % A N 0 0"
this set the script to automatic with no transparency, transparency is to treat the color black as solid or see through.
set mime.handler.image_viewer.unix.program = "python jpgtofabgl % A T 0 0"
this sets the script to automatic with Transparency
set mime.handler.image_viewer.unix.program = "python jpgtofabgl % M N 100 100"
this sets the script to manual no transparency and start the picture at 100,100
when in Automatic you can only display one picture located in the center of the terminal screen
when in Semi Automatic you can display pictures in 4 position. you will not be prompted but you can press L/l,R/r,M/m,C/c this will place 3 pictures at the top and 1 in the center of the screen depending on your keypress.
any mistake in keypress will exit back to the browser and you can try again.
this way its very customizable or ready to go.
i have to bug test it extensively but you can get an idea of what is going on.
python makes it REALLY hard to Pole the keyboard inside a loop basically they don't want unseen keyboard input since it can be used as a key logger.
in working with GIMP i'm now able to pre dither the photos and don't have to worry about any post processes.
i hope to put up a test page with jpg images and then play around with the new script.