This code is in img.php

<?php $a=rand(0,9); $b=rand(1,9); $c=$a+$b; $text=''.$a.'+'.$b.'='; $im = imagecreate(100, 30); imagecolorallocate($im, 255, 255, 255); $color = imagecolorallocate($im, 0, 0, 0); imagestring($im, 4, 3, 2, $text, $color); header('Content-type: image/png'); imagepng($im); ?> 

Then I prescribe the following in another file, content.php

 <img src="img.php"/> 

Nothing happens, please help. The picture is not displayed.

  • And what is displayed in the browser if you type the URL: http://site/path/to/img.php - chernomyrdin

2 answers 2

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

Indicate at the beginning.

  • he says everything, why write it a second time? - Artem

Most likely the reason for the error in the incorrect path to the file here

 <img src="img.php"/> 

there is simply no other, it should work in theory