Does html can be use with dynamic generated images in php?

前端 未结 2 812
孤街浪徒
孤街浪徒 2021-01-20 17:56

I am using this code to create an image



        
相关标签:
2条回答
  • 2021-01-20 18:20

    If you want a div around your image you have to do that in the html, you can't do that in the image generation code

    <div>
    <img src="http://localhost/php/test92.php">
    </div>
    

    If you are getting errors regarding the image, try browsing the image url http://localhost/php/test92.php and see what it looks like.

    Does it show an image like you are expecting?

    0 讨论(0)
  • 2021-01-20 18:34

    Basically, to create dynamic image in HTML, you will need 2 PHP files:

    1. one for the image itself
    2. another one for PHP to display it.

    Let's take a look how to do it:

    1. You create image.php that accept parameter, like: image ID or file name. For security reason, you HAVE to filter whatever parameter it get.

      Why you have to do this? because, to generate image, you can't mix it with another HTML output. Let alone a single space or return as this will render the image broken.

    2. You do the HTML thing on another PHP, say test92.php. To the HTML logic here, like:

      1. get image data
      2. loop the data
      3. display image => <img src="image.php?imageID=12" alt="" />
    0 讨论(0)
提交回复
热议问题