• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

web server background image

Q&A Forum › web server background image
0 Vote Up Vote Down
Nazmie Razali asked 6 years ago

Hi, can I know how to insert a picture as background image in my web server? I tried using the code as below, but it seem incorrect.
client.println(“<style>body {background-image: url(“almonds.jpg”); text-align: center; font-family: \”Trebuchet MS\”, Arial;}”);

5 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Hello Nazmie, there are two things wrong with your example.

First, you need to escape the character ” in your Arduino code, otherwise it will not work and give you an error. For example:

background-image: url("almonds.jpg")

It needs to be with an \ before the “ :

background-image: url(\"almonds.jpg\")

However, that HTML will never load that figure, because the figure is not stored in your ESP32 (I don’t have any examples on that subject…).

Basically, you need to host your image in an online service or in your own website.

Then, enter the URL in that part. It would look like this:

client.println("<style>body {background-image: url(\"http://example.com/your-image-url.jpg\"); text-align: center; font-family: \"Trebuchet MS\", Arial;}");

I hope that helps!

0 Vote Up Vote Down
Nazmie Razali answered 6 years ago

yup it works! Thank you very much

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

I’m glad it worked! Regards,
Rui

0 Vote Up Vote Down
Steen Spaten answered 3 years ago

Regarding the background picture: How to display it in the html-page? I can upload a image (a png-image just like your favicon into SPIFFS from your WEB-server projects), but I can’t figure out how to insert it in CSS and hmtl. Can you help?

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
 
Check this tutorial: https://randomnerdtutorials.com/display-images-esp32-esp8266-web-server/
It explains how the ESP32 can serve images.
 
You can also take a look at this: https://www.w3schools.com/cssref/pr_background-image.asp
It explains how to set a background image.
 
In CSS, I think you can use:

 background-image: url("image");

Then, make sure you listen for the /image request and serve the image accordingly.

server.on("/image", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send(SPIFFS, "/sun.png", "image/png");
});

 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.