how do i generate an img for my hit counter on my website

just thinking about it conceptually, i was thinking of making a count which incremented every time a request was sent to the server for my particular webpage, but i’m not sure how i would turn this result or variable into an img tag that i could display as html…

i’m writing in python but it doesn’t matter i’m just thinking abt how it’d work…

You would first need to make a program than renders the hit count into an image. Then you’d need to map this program to some path on your web server, so that requests to that path yield the output of that program. Then in your HTML, you have an <img> with src set to that path.

The typical way this would be done is to have the image-generating program also be responsible for the hit counting, so each successive image it generates has the next number, but you could separate that out if it made sense to you. Separating it would be a way to keep the numbers more accurate. For instance, a text-only browser may not even attempt to load your image, so you would miss counting that hit. But if your website is otherwise completely static, you may not find it worth it to add a backend just to count those few visitors. If your website already has a backend, then you could use that to count hits and pass that in as a parameter to your image generator program, and you could even include the hit count in the alt text of the <img> so that text-only visitors could still read the count.

you may want to use a css file or javascript to count the hits as bots don’t request css/run js.

ah yes it probably would be a better idea but idk much in the way of javascript as of now unfortunately

also just noticed that you seem to be on neocities which I think is only static. You will need to use a server that you can upload code to. You could join tilde.club, which allows you to run code. I would recommend python if you are a beginner. tilde.club wiki – CGI - Making web applications like it’s 90s

You could use a simple javascript fetch to run the python code.

The python code could read a number from a text file and print it then write the next number to the file. Use chown nginx hits.txt on the file so that the web server can read it.

The javascript could then take the number and split it into digits. It could then create an image tag for each digit. I.e for 100:
<img src=/numbers/1.png><img src=/numbers/0.png><img src=/numbers/0.png>

For accessibility you will need to set ariaHidden to true on each img and wrap it in a div with ariaLabel="100" (or whatever the number is).