Information graphical visualization for web-page: Is there any better way instead of small PNG files?

后端 未结 3 819
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 05:20

Let\'s describe the task first:

I\'d like to create a web-page with several rows of a text and a small (let\'s say 100 by 20 pixels) graphic for each one. Each graphic g

3条回答
  •  暖寄归人
    2021-01-25 06:05

    You can serve an image from PHP rather than from a file - I mean you can have PHP dynamically create an image and serve it rather than having to have a file in your webserver's filesystem and having to refer to it by name in the src field of an tag in your HTML.

    So, instead of

    ...
    

    you can use

    
    

    which causes the PHP script at /php/thumb.php to be called when the page is rendered. In that script, you can dynamically create the image (using extra parameters if you wish) like this:

    
    

    I have omitted some code after the first 3 lines so you just see the technique rather than all the gory details of my code. The actual lines you are interested in are:

    header(...image/png);
    

    which tells the browser what type of stuff is coming - i.e. an image, and

    imagepng();
    

    which actually sends the stream of PNG data to the browser.

    The code above produces this in the browser:

    enter image description here

提交回复
热议问题