Heading image or string? - image

I just created a page which the user can choose the mode to show, such as icon (image) or just temperature (text). Those are my code:
<?lc
#tell the browser that we will send binary data (png)
put header("Content-type:image/png")
#get ip address
if $_GET["ip"] = "" then
put $_SERVER["REMOTE_ADDR"] into ipAddress
else
put $_GET["ip"] into ipAddress
end if
#get the mode
put $_GET["mode"] into mode
#get longtitude and latitude data
put url ("http://vo.afteroffice.com/r/v/public/pub/geoloc?ip=" & ipAddress) into geoInfo
split geoInfo by cr and ":"
#input lon and lat data into url
put url ("http://api.yr.no/weatherapi/locationforecast/1.8/?lat=" & geoInfo["latitude"] & ";lon=" & geoInfo["longtitude"]) into weatherDetail
#create tree from XML data
put revCreateXMLTree(weatherDetail, false, true, false) into tLocation
#get data about temperature and clouds
put revXMLAttribute(tLocation,"weatherdata/product/time/location/temperature", "value") into temperature
#create the output
if mode = "temperature" then
put "The temperature is " & temperature
else if mode = "icon" then
put URL("binfile:icon/hot01.png")
else if mode = "" then
put "Oke"
end if
?>
My image & text problems are:
If I don't put put header("Content-type:image/png") in my code and I call mode=icon, the result will be "‰PNG IHDRPPŽò­tEXtSoftwareAdobe ImageReadyqÉe
If I put put header("Content-type:image/png") in my code and I call mode=temperature, the result will be "Te image cannot displayed, cause it contains error"
Could you help me? Thank you.

And how about adding something like
if mode = "temperature" then
# do not put header
else if mode = "icon" then
put header("Content-type:image/png")
end if
at the position where you have your content type header now?
You just have to add the definition of mode at the beginning instead of the middle of your script

Related

How to send color images with ESC/POS?

I have an Epson CW-C6000 that I'm trying to control with ESC commands. I've gotten text to print, so I know I have the IP address, port, etc correct but cannot for the life of me get an image printed.
Here is my code (running from a Ruby on Rails server, with most of the image truncated):
streamSock = TCPSocket.new( "X.X.X.X", 9100 )
str = "~DYR:PRODIMG,B,P,183208,0,89504E470D...4AE426082" + "^XA" + "^FO150,150^IMR:PRODIMG.PNG^FS" + "^XZ"
streamSock.send( str , 0)
streamSock.close
The image is a .png I converted to hexadecimal with this site:
http://tomeko.net/online_tools/file_to_hex.php?lang=en
I'm mostly using page 10 of this PDF for reference:
https://files.support.epson.com/pdf/pos/bulk/esclabel_apg_en_forcw-c6000series_reve.pdf
Does anyone have a hint? Epson support staff was spectacularly unhelpful.
Also I'm sorry if my formatting is bad; I'm new here and will happily edit my post if something is wrong.
Alright I finally got it working. The command for printing a color .PNG is this:
~DYE:[Image Name].PNG,p,p,[Image Size],0,:B64:[Base64 String]:[CRC]
Things that tripped me up:
-You seem to need the .PNG extension on the file name, even though the Epson manual doesn't show that.
-[Image Size] is the number of characters in the Base64 string, even though the Epson manual says it should be the size of the original .PNG image file. If this is wrong the printer will hang and no longer accept input of any kind until restarted.
-There may be other options, but I could only get it working with a CRC of the hex CRC-16/XMODEM type.
Thanks to K J for his/her suggestions and coming along with me!
Perhaps this material can be used as an additional reference.
They seem to have a completely different command/data format than ESC/POS.
ESC/Label Command Reference Guide
Page 12
1.3.4 About Saving the Graphics and Label Formats in the Printer
With ESC/Label command, you can save graphics and label formats in the printer. The printer has a file system. Data saved in the printer is handled as files and is managed in the following way.
The file system does not have a hierarchy.
The printer has a non-volatile saving device, such as Flash ROM, and a volatile saving device, such as RAM, and different drive letters are allocated for each device.
Files are designated as
"<drive letter> colon <:> <file name> dot <.> <extension>".
Page 40-41
2.8 Printing Graphics
...Details have been omitted. Please refer to the actual document...
2.8.1 Registering a Graphic in a Printer and Printing It
...Pick up some from the content. Please refer to the actual document...
Delete the files that remain in the printer (^ID command).
Register the graphic in the printer (~DY command).
When registering a color graphic, you can use the PNG format. When registering a monochrome graphic, you can register the PNG format or the GRF format.
PNG format Monochrome and color graphics
GRF format Monochrome graphics
The reason to execute the step 1.
To ensure capacity of the storage memory necessary for print which application will perform.
2.8.2 Embedding a Graphic in the Field and Printing It
...Details have been omitted. Please refer to the actual document...
In Addition:
Page 104-106
~DY
[Name]
Save File
[Format]
~DY d: o ,f ,x ,t ,w ,data
...A table detailing the parameters is due, but omitted...
[Function]
...Further detailed explanations and figures of functions and parameters are due, but omitted...
Graphic data is handled as follows.
If the data format is binary, you can use any binary data as Parameter data. At this time, the size of Parameter data must be matched to the size specified in Parameter t.
If the data format is a hexadecimal character string, one character from 1. to 3. below is used as Parameter data. At this time, the size of Parameter data written in binary must be matched to the size specified in Parameter t.
0 to 9, A to F, and a to f in ASCII can be used as hexadecimal graphic data.
ASCII comma <,>, the parameter separator character, is used to separate lines. If a comma is input, processing is carried out as if ASCII 0 was input for the remainder of the line.
G to Y and g to z in ASCII can be used as repetition characters. For example, if I9 is input, processing is carried out as if 999 were input. The following table indicates the number of repetitions.
...Characters and repeat specified number of times table omitted...
Looking at the contents of this Technical Reference Guide, it seems that you can register images with tools instead of commands.
CW-C6000/C6500 Series Technical Reference Guide
Page 173-174
And page 288 outlines the Epson Inkjet Label Printer SDK and also describes the existence of sample programs.
#Farmbot26. I have been attempting this same using vb.Net and as you noted Epson support is not helpful. I'm not sure if it's the actual image data that is wrong, CRC, or the ZPL code as nothing helps. Here's 2 examples that have not worked.
`Dim binaryData As Byte() = System.IO.File.ReadAllBytes(txtPNGFile.Text)
zplImageData = Convert.ToBase64String(binaryData)
crc = calcrc(binaryData, binaryData.Length).ToString("X4")
Dim zplToSend As String = "~DYE:" & Path.GetFileName(txtPNGFile.Text).ToUpper & ",P,P," & zplImageData.Length & ",0,:B64:" & zplImageData & ":" & crc & "^XZ"`
`Dim binaryData As Byte() = System.IO.File.ReadAllBytes(txtPNGFile.Text)
crc = calcrc(binaryData, binaryData.Length).ToString("X4") 'Calculate CRC
zplImageData = BitConverter.ToString(binaryData).Replace("-", "")
Dim zplToSend As String = "~DYE:" & Path.GetFileName(txtPNGFile.Text).ToUpper & ",A,P," & zplImageData.Length & ",0,:B64:" & zplImageData & ":" & crc & "^XZ"`
This is the CRC example I have.
`Function calcrc(ByVal data() As Byte, ByVal count As Integer) As Integer
Dim crc As Integer = 0
For Each b As Byte In data
Dim d As Integer = CInt(b)
crc = crc Xor (d << 8)
For j = 0 To 7
If ((crc And &H8000) <> 0) Then
crc = (crc << 1) Xor &H1021
Else
crc = (crc << 1)
End If
Next
Next
Return crc And &HFFFF
End Function`
I have figured out another solution. Save the PNG Image using the Binary data. I found this when reading the Saved Backup file of Image data using the Epson Settings Utility.
~DYE:FILENAME.PNG,B,P,BINARYFILESIZE,0, BINARYIMGDATA
` Try
Dim binaryData As Byte() = System.IO.File.ReadAllBytes(txtPNGFile.Text)
Dim client As System.Net.Sockets.TcpClient = New System.Net.Sockets.TcpClient()
client.Connect(IP_TextBox1.Text.Replace(" ", ""), txtPort.Text)
Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter(client.GetStream(), Encoding.UTF8)
Using mStream As New MemoryStream(binaryData)
Dim zplToSend As String = "~DYE:" & Path.GetFileName(txtPNGFile.Text).ToUpper & ",B,P," & mStream.Length & ",0,"
writer.Write(zplToSend)
writer.Flush()
mStream.WriteTo(client.GetStream())
writer.Flush()
End Using
writer.Close()
client.Close()
MsgBox("Send Complete", MsgBoxStyle.OkOnly, "Complete")
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.OkOnly, "ERROR")
End Try`
You can also open the image file in an IMAGE object and resize it as needed. I had to do this for the label size of the printer.

How to create a Roblox game where the player has to guess a randomly generated pin?

So, I've been working on this for the past week. I have tried everything (based on the knowledge I know) and yet nothing... my code didn't work the first time, the second time, the third time... the forth... etc... at the end, I let frustration take control of me and I ended up deleting the whole script. Luckily not the parts and models, otherwise I'm really screwed...
I need to create a game in which I have to create a keypad of sorts, at first I thought GUI would work... no, it needs to be SurfaceGUI, which I don't know how to handle well... Anyway, I needed to create a keypad using SurfaceGUI, and display it on a separate screen, as a typical keypad would...
The Player would first have to enter an "initial" number, meaning in order to enter the randomly generated number he first needed to input the static pin in order to "log in," after that, then he would try to guess the number...
I've literally tried everything I could but nothing... It's mainly because of my lack of experience in LUA, I'm more advanced in Python and barely know a thing in Java... If someone could assist me on how to do this, I would appreciate it greatly
First, download this and put it in a ScreenGui in StarterGui. Then, use the following LocalScript placed inside the PIN frame:
-- Script settings
local len = 4 -- replace this as needed...
local regen = false -- determines whether PIN will regenerate after a failed attempt
local regmes = "Enter PIN..." -- start message of PIN pad
local badmes = "Wrong PIN!" -- message displayed when PIN is wrong
local success = "Correct PIN!" -- message displayed when PIN is right
-- Script workings
local pin = script.Parent
local top = pin.Top
local txt = top.Numbers
local nums = top.NumKeys
local pin
local stpin
local nms
txt.Text = regmes
local see = game:GetStorage("ReplicatedStorage").PINActivate
local function activate()
if pin.Visible then
pin.Visible = false
for _, btn in pairs(nums:GetChildren()) do
btn.Active = false
end
return
else
pin.Visible = true
for _, btn in pairs(nums:GetChildren()) do
btn.Active = true
end
return
end
end
local function rand()
math.randomseed(os.time) -- better random numbers this way
return tostring(math.floor(math.random(0,9.9)))
end
local function gen()
nms = {rand()}
for i=2, len, 1 do
nms[#nms+1]=rand()
end
stpin = nms[1]
for i=2, #nms, 1 do
stpin = stpin..nms[i]
end
pin = tonumber(stpin) -- converts the number string into an actual number
end
gen()
local function activate(str)
if tonumber(str) ~= pin then
txt.Text = badmes
wait(2)
txt.Text = regmes
if regen then
gen()
wait(0.1)
end
return
else
txt.Text = success
wait(2)
activate()
-- insert code here...
end
end
for _, btn in pairs(nums:GetChildren()) do
btn.Activated:Connect(function()
if txt.Text == "Wrong PIN!" then return end
txt.Text = txt.Text..btn.Text
if string.len(txt.Text) >= len then
activate(txt.Text)
end
wait(0.1)
end)
end
see.OnClientEvent:Connect(activate)
And in a Script put this:
local Players = game:GetService("Players")
local see = game:GetService("ReplicatedStorage").PINActivate
local plr
-- replace Event with something like Part.Touched
Event:Connect(function(part)
if part.Parent.Head then
plr = Players:GetPlayerFromCharacter(part.Parent)
see:FireClient(plr)
end
end)
What this will do is bring up a ScreenGui for only that player so they can enter the PIN, and they can close it as well. You can modify as needed; have a great day! :D
There is an easier way, try this
First, Create a GUI in StarterGui, then, Create a textbox and postion it, after that, create a local script inside and type this.
local Password = math.random(1000, 9999)
print(Password)
game.ReplicatedStorage.Password.Value = Password
script.Parent.FocusLost:Connect(function(enter)
if enter then
if script.Parent.Text == tostring(Password) then
print("Correct!")
script.Parent.BorderColor3 = Color3.new(0, 255, 0)
Password = math.random(1000, 9999)
game.ReplicatedStorage.Correct1:FireServer()
print(Password)
game.ReplicatedStorage.Password.Value = Password
else
print("wrong!")
print(script.Parent.Text)
script.Parent.BorderColor3 = Color3.new(255, 0, 0)
end
end
end)
That's all in the textbox.
Or if you want a random username script, create a textlabel, then, create a local script in the textlabel and type in this.
local UserText = script.Parent
local Username = math.random(1,10)
while true do
if Username == 1 then
UserText.Text = "John"
elseif Username == 2 then
UserText.Text = "Thomas"
elseif Username == 3 then
UserText.Text = "Raymond"
elseif Username == 4 then
UserText.Text = "Ray"
elseif Username == 5 then
UserText.Text = "Tom"
elseif Username == 6 then
UserText.Text = "Kai"
elseif Username == 7 then
UserText.Text = "Lloyd"
elseif Username == 8 then
UserText.Text = "Jay"
elseif Username == 9 then
UserText.Text = "User"
else
UserText.Text = "Guest"
end
wait()
end
All of those if statments are checking what username has been chosen. I have made a roblox game like this recently, so I just took all the script from the game.
If you want to check out my game, Click Here

Text outputs as multiple separate lines instead of one paragraph with linebreaks

I have a bot that writes my message to a webpage. I want the message to be sent as one paragraph, but with the lines separated by a linebreak. However, when I actually run the code, the bot inputs and enters each line separately, instead of as one paragraph
I've tried messing with the linebreak formatting and string formatting, but the issue persists
reply_messages = []
reply_messages.push([
"FREE BABY AVOCUDDLE - Thank you for your patience!",
"To redeem your FREE avocuddle, just use the LINK IN OUR BIO and ADD TO CART - just cover shipping, no additional charges!",
"Discount AUTOMATICALLY APPLIES! Super simple, no code!",
"If you order another avocuddle in addition, we cover shipping PLUS the free baby avocuddle! :)",
"Feel free to DM us if you need anything!"
].join("\n")+"\n")
.
.
.
while true
browser.get 'https://twitter.com/messages/requests'
sleep 5
request = wait.until {
el = browser.find_element(:css, "[data-testid='conversation']")
el if el.displayed?
}
break if request.nil?
request.click
not_acceptable_link = true
na_link_index = 1
while not_acceptable_link == true
accept_btn = browser.find_element(:xpath, "//*[contains(text(), 'Accept')]")
unless accept_btn.displayed?
request_2 = wait.until {
el = browser.find_elements(:css, "[data-testid='conversation']")[na_link_index]
el if el.displayed?
}
request_2.click
else
not_acceptable_link = false
end
na_link_index += 1
end
accept_btn = browser.find_element(:xpath, "//*[contains(text(), 'Accept')]")
accept_btn.click
sleep 1
reply_input = wait.until {
el = browser.find_element(:css, "[data-testid='dmComposerTextInput']")
el if el.displayed?
}
reply_input.click
reply_input.send_keys(reply_messages)
.
.
.
I would like for the code to output the entire text as one block of text. However, instead, it outputs as separate lines.
Output currently looks like:
FREE BABY AVOCUDDLE - Thank you for your patience!
(enters this into text box)
To redeem your FREE avocuddle, just use the LINK IN OUR BIO and ADD TO CART - just cover shipping, no additional charges!
(enters this into text box)
etc.
Instead I would like for it to send as one message.

How to query from URL "Line" Format to VBA variable

I'm trying to make an application that will display user data through api on command... I have assembled the URL generator and everything. it's just beyond me to find a simple way to assign THIS: "http://api.bf4stats.com/api/playerInfo?plat=xbox&name=charlie%20is%20tftc&output=lines" data to specific variables with my parameters. (Lines / Text format)
This is my code so far, I just want to be able to assign data like 'player.id' to playerid and display it. (Player.id is the first value in the data linked above)
//the code below will be changed to user input, I don't need help with that this was just for theory
Public Class Form1
Public Sub URL_Player_Info(ByVal Address As String)
'Assign all data figures for constructing the "URL"...
Dim url, plat, player, webprefix, domain, paramsym, ext, preplat, preplayer, andsym, lineparam, format As String
'Variables for "Plat"
plat = "xbox"
'Input for "Player"
player = "Charlie Is TFTC"
'Structure for "URL"
webprefix = "http://"
domain = "api.bf4stats"
ext = ".com/api/playerInfo"
paramsym = "?"
preplat = "plat="
andsym = "&"
preplayer = "name="
format = "output="
lineparam = "lines"
'Generate Final "URL"
url = webprefix + domain + ext + paramsym + preplat + plat + andsym + preplayer + player + andsym + format + lineparam
'Getting Data / Assigning Data for "Plat. Player: Params"
End Sub
Thanks in advanced!

how to replace #VARIABLE in text file with value of Emails in xml file

How i can read this xml file
<Subs>
<Sub Report="BusinessSummarySubs" EMails="lalla#yahoo.com; haha#yahoo.com">
<Sub Report="PlayerSubs" EMails="hehe#hotmail.com">
</Subs>
and replace #VARIABLE in BusinesSummarySubs.txt with EMails value in
Here is the content(part of the content) from BusinessSumarySubs.txt
CType(extensionParams(0),ParameterValue).Name = "TO"
CType(extensionParams(0),ParameterValue).Label = ""
CType(extensionParams(0),ParameterValue).Value = "#VARIABLE"
If you look here, you'll see how to search for and to access attributes. Follow the link chain to 'the same for text' and do a mental diff, if you want to get a skeleton for a minimal XML processing script to use for your next task.
Single placeholder substitution in VBScript is easy: just use Replace:
>> attr = "lalla#yahoo.com; haha#yahoo.com"
>> content = "... .Value = ""#VARIABLE"" ..."
>> ph = "#VARIABLE"
>> WScript.Echo Replace(content, ph, attr)
>>
... .Value = "lalla#yahoo.com; haha#yahoo.com" ...
>>
Something like this i suposed
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
for each Emails in xmlDoc.documentElement.childNodes
document.write(Emails .nodename)
document.write(": ")
document.write(Emails .text)
next

Resources