0

I can't put any image in electron app, background-image don't work, img scr don't work, canvas.drawImage don't work what may i do? Obvious code:

<img src="file://bg.jpg" width="50px" height="50px"> 
...
body{ background-image: url('file:///bg.jpg') 50px 50px repeat; }

1 Answers1

0

The source of the image is wrong.

You can either user Absolute Path or Relative Path - Absolute V/s Relative Path

Use Relative Path as they are not bound to a base URL

Now coming back to your problem, file://bg.jpg is not a valid path.
As you have given the structure of your project let us consider that you wanted the background image and <img /> in file index.html and image bg.jpg are both in the same directory.

Which mean if your files structure is like this
project_folder
   |   index.html
   |   main.js
   |   bg.jpg


Then instead of file://bg.jpg use bg.jpg.

Thus you code become like

<img src="bg.jpg" width="50px" height="50px"> 
...
body{ background-image: url('bg.jpg') 50px 50px repeat; }

NOTE: Only valid if both HTML file and image are in the same directory

If not then you have to use a relative path to access the image

Not A Bot
  • 2,474
  • 2
  • 16
  • 33