Add Image printing from URL. Type 7, text field URL.
All checks were successful
Create Release & Upload Assets / Upload Assets To Gitea w/ goreleaser (push) Successful in 2m48s
All checks were successful
Create Release & Upload Assets / Upload Assets To Gitea w/ goreleaser (push) Successful in 2m48s
This commit is contained in:
@@ -5,8 +5,13 @@ import (
|
||||
fifo "github.com/foize/go.fifo"
|
||||
"github.com/justinmichaelvieira/escpos"
|
||||
"github.com/liamg/tml"
|
||||
"image"
|
||||
"net"
|
||||
"net/http"
|
||||
"uberbringer/config"
|
||||
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
)
|
||||
|
||||
func newPrintJob(input DataStruct, queue *fifo.Queue) {
|
||||
@@ -47,10 +52,8 @@ func printJobCreate(input DataStruct, queue *fifo.Queue) {
|
||||
p.Initialize()
|
||||
p.DefaultLineSpacing()
|
||||
|
||||
for i, item := range input.Data {
|
||||
var SeqNum = i + 1
|
||||
tml.Printf("<darkgrey>[" + config.Project + "]: Job #" + input.JobID + " - creating command " + string(SeqNum) + "</darkgrey>\n")
|
||||
if item.Type <= 0 || item.Type > 6 {
|
||||
for _, item := range input.Data {
|
||||
if item.Type <= 0 || item.Type > 7 {
|
||||
tml.Printf("<red>[" + config.Project + "]: Job #" + input.JobID + " bad type</red>\n")
|
||||
return
|
||||
} else if item.Size <= 0 || item.Size > 16 {
|
||||
@@ -89,9 +92,30 @@ func printJobCreate(input DataStruct, queue *fifo.Queue) {
|
||||
}
|
||||
|
||||
p.WriteRaw([]byte(hex_decoded))
|
||||
}
|
||||
case 7:
|
||||
// Print Image from URL
|
||||
response, err := http.Get(item.Text)
|
||||
if err != nil {
|
||||
tml.Printf("<red>[" + config.Project + "]: Job #" + input.JobID + " image load failed</red>\n")
|
||||
return
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
tml.Printf("<green>[" + config.Project + "]: Job #" + input.JobID + " good type</green>\n")
|
||||
if response.StatusCode != 200 {
|
||||
tml.Printf("<red>[" + config.Project + "]: Job #" + input.JobID + " image load failed - received non 200 response code</red>\n")
|
||||
return
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(response.Body)
|
||||
if err != nil {
|
||||
tml.Printf("<red>[" + config.Project + "]: Job #" + input.JobID + " image decode failed</red>\n")
|
||||
return
|
||||
}
|
||||
|
||||
p.PrintImage(img)
|
||||
|
||||
response.Body.Close()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -106,4 +130,5 @@ func printJobCreate(input DataStruct, queue *fifo.Queue) {
|
||||
|
||||
tml.Printf("<green>[" + config.Project + "]: Done printing #" + input.JobID + "</green>\n")
|
||||
|
||||
socket.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user