0

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:

example:

<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:

imagepng($im);

then he wont execute the

imagedestroy($im);

I'm not sure how to do this

0

2 Answers 2

1

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.

1

You need get image from other script via http.

<span>Here comes the image</span>
<img src="/path/to/image_handler.php"/>
<span>and here we continue with some HTML</span>

where image_handler.php - your php script:

<?php
…
header('Content-type: image/png');
imagepng($im);

NOTE: never output something before call header

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.