-3

I am creating an image generating tool. According to the tool, when a user types his name the image is generated with his/her name.

The problem is that the image appears on the side of the browser window. I want it on the center of the browser. I tried <img src="path_of_php_file.php"> , but it didn't work .

My php code

<?php
$name = $_POST['imagename'];

if($_POST['imagename'] != ''){



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



$name = $_POST['imagename'];

   $im = @imagecreate(800, 600);

   $background_color = imagecolorallocate($im, 0xFF, 0xCC, 0xDD);

   $text_color = imagecolorallocate($im, 133, 14, 91);

   imagestring($im, 5, 300, 300,  " Hey $name Whats Up Bro ?", $text_color);



   imagepng($sim);


   imagedestroy($sim);

}

else echo "no image created";
?>

My html code

<html>
<body>

<form action="images.php" method="post">

Enter Your Name :<input type="text" name="imagename">

<br></br>

<input type="submit" name="submit">

</form>

</body>

</html>

It would be really helpful if you guys tell me how to make my generated image to center. Thanks

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72

1 Answers1

0

The problem is that on submit, you're returning the image object (without html).

If you want to center that, you'll need to return some html page, add a tag linking to the image generated, and use some css to center it.

If you don't want to save the image anywhere, you could use a data uri:

http://css-tricks.com/data-uris/

TurboHz
  • 2,146
  • 2
  • 16
  • 14