Announcement

Collapse
No announcement yet.

Do I need to change the encoding to stream an image to a browser?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Do I need to change the encoding to stream an image to a browser?

    When using PBCC:
    This is not working:

    Code:
    FUNCTION PBMAIN () AS LONG
    
    LOCAL bmp_string AS STRING
    LOCAL bmp_len AS LONG
    
    OPEN "x.bmp" FOR BINARY AS #1
    GET$ #1, LOF(1), bmp_string
    bmp_len = LOF(1)
    CLOSE #1 
    
    
    STDOUT "HTTP/1.1 200 OK"
    STDOUT "Content-Type: image/bmp"
    STDOUT "Last-Modified: Sun, 01 May 2022 23:23:24 GMT"
    STDOUT "Accept-Ranges: bytes"
    STDOUT "ETag: W/" + $DQ + "61a32f74b25dd81:0" + $DQ
    STDOUT "Server: Microsoft-IIS/10.0"
    STDOUT "Date: Sun, 01 May 2022 23:23:24 GMT"
    STDOUT "Content-Length: 108954"
    STDOUT
    STDOUT bmp_string
    
    END FUNCTION

  • #2
    I think you need to base64 encode any binary data transferred by TCP/IP. Does your code work as-is for text files?
    Dan

    Comment


    • #3
      It is not the TCP layer that needs Base64. (unless your router is at least as old as you are)
      Dale

      Comment


      • #4
        Years ago I saw a product that would embed barcodes in a web page on the fly. It worked like this:

        Code:
        <img src='bcode.exe?12345'>
        I have been meaning to figure out how that worked. So after trying everything complex and convoluted I tried this:

        Code:
        FUNCTION PBMAIN () AS LONG
        
        LOCAL PNG_IMAGE_STRING AS STRING
        
         OPEN "test.png") FOR BINARY AS #1'
         GET$ #1, LOF(1), [/B][B]PNG_IMAGE_STRING 
         CLOSE #1
        
        
        STDOUT
        STDOUT PNG_IMAGE_STRING
        
        
        END FUNCTION[/B]
        This works! So, the next version would use ENVIRON$("QUERY_STRING") to know what image to construct. Next part of the project is to draw the image in PB. But for now I am using Nirsoft SimpleCodeGenerator.exe to make the qr code.

        Code:
        SHELL "SimpleCodeGenerator.exe /ErrorCorrection 2 /MinVersion 1 /MaxVersion 40 /Save otpauth://totp/Verolock?secret=" + GOOGLE_AUTH_CODE_STRING + " C:\IIS\Authenticator\" + GOOGLE_AUTH_CODE_STRING + ".png"
        
        PNG_IMAGE_FILE_NAME = "C:\IIS\Authenticator\" + GOOGLE_AUTH_CODE_STRING + ".png"
        Same basic idea can be used to make live dynamic charts etc....

        Comment


        • #5
          Originally posted by David Clarke View Post
          Next part of the project is to draw the image in PB.
          .
          The last time you asked about QRCode, got me wondering how hard it would be, to actually do that, well it took me 2 weeks of spare time to figure it out. It was an interesting challenge.
          If you are interested, I can share what I have. Which can be made into a nice SLL.

          It creates working QRCodes, that you can display, print or save in all the formats gdi+ can save.

          Comment


          • #6
            Hi Rod! I would love to see what you came up with! you can email me if you like [email protected]
            thanks!

            Comment


            • #7
              Here I'll share it with the community.
              https://forum.powerbasic.com/forum/u...rcode-using-pb

              Comment

              Working...
              X