0

I create an image dynamically using PHP GD. thus when I execute index.php it create image.png but I want image in index.php for example I can use <img src="index.php">

1

1 Answer 1

4

You have to set header content-type to header('content-type: image/jpeg');
I have implemented a similar code once for a captcha

header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$string = "Type Me";
$im     = imagecreatefrompng(IMAGEDIR."captcha.png");
$orange = imagecolorallocate($im, 0, 0, 0);
$px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 5, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.