0

i tried to make a PHP GD banner like a plugin to make users copy and paste the image link and put in their websites, which worked ok so far for me, the problem is that when i load the image, other page content such as text , etc doesn't show into the browser

here is my php code to draw the image

<?php
    header("Content-type: image/png");
    $string = $_GET['text']. '  Click Here';
    $im     = imagecreatefrompng("../../images/banner.png");
    $orange = imagecolorallocate($im, 0, 0, 0);
    $px     = (imagesx($im) - 1.5 * strlen($string)) / 2;
    $font = 'verdana.ttf';
    imagestring($im,50, $px, 45, $string, $orange);
    imagepng($im);
    imagedestroy($im);
        ?>

hint: i put this code at the top of the page to make the header work

now other html code is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>add plugin</title>
</head>

<body>
<h3>Select One or More Plugin to connect your website for your reservation</h3>

<h4>Just A Button</h4>
<br />
<p>Instructions</p>
<p>Copy this code and paste into your website</p>

</body>
</html>

can someone suggest any solution to overcome this problem ?

Bader H Al Rayyes
  • 514
  • 2
  • 7
  • 24

2 Answers2

3

if your PHP script produces an image, then you should appropriately wrap the output of that in an IMG tag.

try, for an example to add this to your html page: <img id="banner" src="/path/to/your.php?text=Click%20Here"/>

if you're using jQuery client-side you can dynamically alter the src attribute of the image. See for an example here: Changing the image source using jQuery

Community
  • 1
  • 1
Vincent Briglia
  • 3,068
  • 17
  • 13
3

hint: i put this code at the top of the page to make the header work

That's your problem. You've basically done the equivalent of opening an image file on your computer in a text editor and typing random characters at the end of the file. It'll break the image, and you'll never see the characters as they're meaningless within image data.

Your PHP code can't return both image and HTML in one HTTP request. Instead, you can have two different PHP files, one for images, and one for HTML. Have the HTML include the image PHP via a standard <img src="image.php" alt="" /> tag.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368