Ralph Schipper Ralph Schipper - 2 years ago 81
PHP Question

how do I call create image function?

I found this topic: convert text to image in php

and I tested the code that Sourabh Shankar provide.

When I paste this code in a new empty php file and I adjust the font path, then it works perfect!

But when I put a echo before or after the header('Content-type: image/png'); line, then it all fails

Can someone provide me a code of how to call this image creator in a HTML file:


<span>Here comes the image</span>
<?php [call function??] ?>
<span>and here we continue with some HTML</span>

Do I need to create a php function and if so:

what do I excactly return?
if I return this:


then he wont execute the


I'm not sure how to do this

Answer Source

The PHP code you linked to works as a stand-alone file, so that when it is requested in a browser it will send back an image. Setting the header with

header('Content-type: image/png');

means that the code will return content which the browser interprets as an image file, rather than a HTML file.

You couldn't use PHP to directly output a file into HTML. You would need to use that code in a separate file and link it to the src tag of an image in your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download