Jump to content

PHP GD help


toolman

Recommended Posts

Hi there,

 

I am trying to insert two php created image on one page, but I cannot get the second to appear.

 

This is my code:

 

index.php:

<?php header("Content-type: image/png"); //prints the image header ?>
<?php include("head.php"); ?>
<?php include("body.php"); ?>


<?php echo"<img src='head.php' />"; ?>
<?php echo"<img src='body.php' />"; ?>

 

head.php:

<?php
$head = isset($_GET['text']) ? $_GET['text'] : "this is the head"; //gets the text from the URL, I modified this to not throw errors
$im     = imagecreatefrompng("images/head_image.png"); //Makes an image object
$orange = imagecolorallocate($im, 220, 210, 60);  //creates a reference to the color orange
$px     = (imagesx($im) - 7.5 * strlen($head)) / 2;  
imagestring($im, 3, $px, 9, $head, $orange); //writes the texst "string" in orange on the image
imagepng($im); //outputs the image as binary data
imagedestroy($im); //destroys the memory for the resource of the image  
?>

 

body.php:

<?php
$body = isset($_GET['text_body']) ? $_GET['text_body'] : "this is the body"; //gets the text from the URL, I modified this to not throw errors
$im_body     = imagecreatefrompng("images/body_image.png"); //Makes an image object
$orange_body = imagecolorallocate($im_body, 220, 210, 60);  //creates a reference to the color orange
$px_body     = (imagesx($im_body) - 7.5 * strlen($body)) / 2;  
imagestring($im_body, 3, $px_body, 9, $body, $orange_body); //writes the texst "string" in orange on the image
imagepng($im_body); //outputs the image as binary data
imagedestroy($im_body); //destroys the memory for the resource of the image 
?>



 

Any ideas what is wrong?

 

Thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/188636-php-gd-help/
Share on other sites

Hi

I have tried this, but it still doesn't work.

 

<?php header("Content-type: image/png"); //prints the image header ?>
<?php include("head.php"); ?>
<?php echo"<img src='head.php' />"; ?>


<?php include("body.php"); ?>
<?php echo"<img src='body.php' />"; ?>

 

 

Any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/188636-php-gd-help/#findComment-999502
Share on other sites

Hi

I have tried this, but it still doesn't work.

 

<?php header("Content-type: image/png"); //prints the image header ?>
<?php include("head.php"); ?>
<?php echo"<img src='head.php' />"; ?>


<?php include("body.php"); ?>
<?php echo"<img src='body.php' />"; ?>

 

 

Any ideas?

 

Thanks

You need to be setting the content type

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

 

On the first line of head.php and body.php

 

You'd display your images like so

<?php

echo"<img src='head.php' />
<br />
<img src='body.php' />"; 

?>

Link to comment
https://forums.phpfreaks.com/topic/188636-php-gd-help/#findComment-999505
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.