|
Forum Index : Microcontroller and PC projects : I need html help
| Author | Message | ||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1054 |
I cannot get a background jpg file or color to appear on a simple web page set up on the a: drive of the pico webmite (MM.VER=6.0201). I can LOAD JPG to the LCD screen so I am sure the filename and data are correct. Here is some code: <html> <head> <title>WEBMITE TEST PAGE</title> <style> body{ background_color: #F4F4F4; background-image: url('A:/VanRear.jpg'); } </style> </head> <body> <h1>HEADER 1<h1> </body> </html> Hopefully some one can see the errors of my ways. OA47 |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11974 |
Manual page 97 |
||||
| maxwelloau Newbie Joined: 31/10/2025 Location: AustraliaPosts: 7 |
The CSS is close, but background_color isn’t a valid CSS property—it should be background-color. Also, A:/VanRear.jpg is a local drive path, so it likely won’t load for anyone else viewing the site. Put the image in your project and use a relative path: body { background-color: #f4f4f4; background-image: url("images/VanRear.jpg"); } Adjust images/VanRear.jpg to match the image’s location in your project. ----------------------------------------------------------- I don't claim to know this, I just asked the automatic helper. 20 years ago I did some Html, all forgotten! |
||||
| Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5199 |
The "A:/VanRear.jpg" is not a valid url from the browsers perspective. OK, I haven't played with the web mite to really know, but on a web server, to send a file thats not in the web folder folder ( htdocs, wwwroot, etc ), you set up a virtual folder in the web server config, so in your case 'A:\' would be aliased as \htdocs\A. Then background-image: url('/A/VanRear.jpg'); would work. The other option is to convert the image into base64 and embed it into the page. eg <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QLcRXhpZgAATU0AKgAAAAgABAE7AAIAAAAGAAABSodp AAQAAAABAAABUJydAAEAAAAMAAACyOocAAcAAAEMAAAAPgAAAAAc6gAAAAEAAAAAAAAAAAAA etc lots of times tPFFFeWz0kOFU9VvJbO1Dw7dxOMkZxRRRD4kKXws5mWaSeTfM5dj3Jph60UV7K0R5T3G0hoo qhBSUUUxCGk7UUUxDaKKKYCUlFFAhDRRRVCG9qKKKYhKSiimIQ9aSiigBKQ0UVQgNJRRQhCG kNFFMQlFFFMD/9k=" width="820" height="100" border="1"> In a style, that would be... background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ...'); Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1054 |
Peter, am I to assume from your reply that what I am trying to do is not possible? I have been able to pass variable and operations to and from the MMBasic program but thought I might be able to enhance the presentation of the data. @maxwellaou, I did try to move the .jpg file to a /images subdirectory but still nogo. @Glenn you went way over my head with the base64 example but thankyou to all for the responses. OA47 |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11974 |
You just need to double the opening curly bracket as per the manual entry |
||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1054 |
Thankyou maxwellaou for noticing my typo using the underscore instead of the minus and Peter for pointing out I need a double opening curly bracket, now the background colour does change but I still cannot get the .jpg file to load as a background. I have spent way too long without success to get the background file to load. The .jpg file is around 100k in size, is there a size limit or is the problem because the file is local? OA47 |
||||
| phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 3407 |
Is any of this relevant? |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6623 |
Your code is almost right. double up on the {{ put the jpg in the same folder as your index.html for now <html> <head> <title>WEBMITE TEST PAGE</title> <style> body{{ background-color: #F4F4F4; background-image: url('test.jpg'); } </style> </head> <body> <h1>HEADER 1<h1> </body> </html> Your code that processes requests needs to handle jpg. This the the usual sub I use to cover most files trpes I am likely to use. Sub gotrequest Local p%, t%, a%, s$, i, nparams, page$, page_ext$, cons$, newfolder$ Local arg$(1,maxargs-1), endtime WatchDog hw 8000 For a%=1 To MM.Info(max connections) If Not MM.Info(TCP request a%) Then Continue For LongString clear Buff%() WEB tcp read a%,Buff%() ' longstring print Buff%() If LLen(Buff%()) Then page$=parsehtmldata$(nparams,Buff%(), arg$()) print page$ ' if page$ = "" then page$ = html_def$ If Instr(page$,".") Then page_ext$ = LCase$(Field$(page$,2,".")) Else page_ext$ = "" EndIf If MM.Info(FILESIZE page$) > 0 Then ' file does exist. Select Case page_ext$ Case "html", "htm" WEB transmit page a%,page$ 'case "htm" ' WEB transmit File a%,page$,"text/html" Case "ico" WEB Transmit FILE a%,page$,"image/vnd.microsoft.icon" Case "jpg" WEB Transmit FILE a%,page$,"image/jpeg" Case "png" WEB Transmit FILE a%,page$,"image/png" Case "gif" WEB Transmit FILE a%,page$,"image/gif" Case "bmp" WEB Transmit FILE a%,page$,"image/bmp" Case "js" WEB transmit file a%,page$,"text/javascript" Case "txt", "csv", "bas" WEB transmit file a%,page$,"text/plain" Case "csv" WEB transmit file a%,page$,"text/csv" case "py" WEB transmit file a%,page$,"text/x-python" Case "css" WEB transmit file a%,page$,"text/css" Case "cgi" WEB transmit file a%,page$,"application/x-httpd-cgi" Case "" WEB transmit file a%,page$,"text/plain" case "pdf" WEB transmit file a%,page$,"application/pdf" Case Else WEB transmit file a%,page$,"text/plain" End Select Else WEB transmit page a%,"notfound.html" syslog "404 "+page$ WEB transmit code a%, 404 EndIf Else syslog "no data" EndIf Next a% End Sub The image might be too big. Try with a small image first to be sure. Edit: Working program with background image. testweb.zip Jim Edited 2026-10-09 17:07 by TassyJim VK7JH MMedit |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |