1

I have a include file called sign.php which has some code -

header('Content-type: image/png');
.....
imagepng($image_file);
.....

A file where I want to display this image - index.php

......
<what comes here?> include('../sign.php');
.....

How would I display it? Directly echo-ing it doesn't work!

Thanks.

MORE CODE:

sign.php

    .....
   {
    imagettftext($im, 22, 0, 240, 43 , $text_color, $font, $text_god);
    imagettftext($im, 22, 0, 241, 44 , $text_color, $font, $text_god);
}
imagettftext($im, 22, 0, 60, 42 , $text_color, $fontname, $text_username);
     imagettftext($im, 16, 0, 230, 72 , $text_color, $font, $text_kills);
imagettftext($im, 16, 0, 230, 102 , $text_color, $font, $text_deaths);
imagettftext($im, 16, 0, 230, 132 , $text_color, $font, $text_rwon);

imagettftext($im, 16, 0, 365, 72 , $text_color, $font, $text_alevel);
imagettftext($im, 16, 0, 365, 102, $text_color, $font, $text_dlevel);
imagettftext($im, 16, 0, 365, 132 , $text_color, $font, $text_rlost);
imagettftext($im, 16, 0, 365, 162 , $text_color, $font, $text_money);   // Prints the money in the picture. 

imagecopymerge($im, $skinImg, 505, 56,0,0,55,99,100);

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

imagepng($im); 

    imagedestroy($im); 

index.php

    .......
    <?php echo '<img src="../signature/sign.php" />'; ?>
    .......

Still doesn't work!

EDIT:

index.php

            include('../signature/sign.php');

            echo '<img src="data:image/png;base64,' + base64_encode($stringdata) + '">';

sign.php

http://pastebin.com/uz1U3V4R

3 Answers3

3

This happens because imagepng directly outputs the content of the image to the browser. You should save the content of the image into a variable like this in sign.php:

... 
imagecopymerge($im, $skinImg, 505, 56,0,0,55,99,100);  

ob_start();
imagepng($im);
$stringdata = ob_get_contents();
ob_end_clean();

imagedestroy($im);   
...

And then display it in your index.php like this:

<?php
    include('sign.php');
    echo '<img src="data:image/png;base64,' . base64_encode($stringdata) . '">';
?>
Ephi Gabay
  • 938
  • 7
  • 27
0
<img src='< ?php echo 'data:image/png;base64,' . base64_encode(file_get_contents('img.png')) ; ?> '>


<img src='<?php include("img.png"); ?>

This should work for you.

sjngm
  • 12,423
  • 14
  • 84
  • 114
Ferrakkem Bhuiyan
  • 2,741
  • 2
  • 22
  • 38
0

According that you said you tried <img src='sign.php'> and its not working, I guess something is wrong with set the header,Consider that

No output before sending headers

Functions that send/modify HTTP headers must be invoked before any output is made.

Some functions modifying the HTTP header are:

Output can be:

  • Unintentional:
  • Intentional:
    • print, echo and other functions producing output (like var_dump)
    • Raw <html> areas before <?php code.
Community
  • 1
  • 1
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57