needs_upgrade Posted April 6, 2013 Share Posted April 6, 2013 Hello guys. I'm making a website for a networking group. They follow a binary system - a parent can only have two (2) children at most. So I should have circles and straight lines in a page to show the root and its children and so on. My problem is that when i place a PHP GD sample code inside an html <div>, and error happens: Warning: Cannot modify header information - headers already sent. Even this simple code from the php manual that i'm trying wont work: <html> <head> </head> <body> <?php $img = imagecreatetruecolor(450, 450); $white = imagecolorallocate($img, 255, 255, 255); $red = imagecolorallocate($img, 255, 0, 0); $black = imagecolorallocate($img, 0, 0, 0); $grey = imagecolorallocate($img, 211, 211, 211); imagefill($img, 0, 0, $white); imagearc($img, 224, 224, 400, 400, 0, 0, $black); imagefilledarc($img, 224, 224, 15, 15, 0, 0, $black, IMG_ARC_PIE); for ($zz = 0; $zz < 60; $zz++) { $digitCoords['x'][] = 175 * cos(deg2rad(($zz-10) * (360/60))) + 224; $digitCoords['y'][] = 175 * sin(deg2rad(($zz-10) * (360/60))) + 224; } for ($zz = 0; $zz < 60; $zz++) { if ($zz % 5 == 0) imagestring($img, 5, $digitCoords['x'][$zz] - 4, $digitCoords['y'][$zz] - 6, ($zz/5) + 1, $black); else imagefilledarc($img, $digitCoords['x'][$zz], $digitCoords['y'][$zz], 3, 3, 0, 0, $grey, IMG_ARC_PIE); } $seconds = date('s'); $minutes = date('i') + ($seconds/60); $hours = date('h') + ($minutes/60); $r_sec = 175; $r_min = 175; $r_hr = 125; $x_sec = $r_sec * cos(deg2rad(($seconds-15) * (360/60))) + 224; $y_sec = $r_sec * sin(deg2rad(($seconds-15) * (360/60))) + 224; $x_min = $r_min * cos(deg2rad(($minutes-15) * (360/60))) + 224; $y_min = $r_min * sin(deg2rad(($minutes-15) * (360/60))) + 224; $x_hr = $r_hr * cos(deg2rad(($hours-3) * (360/12))) + 224; $y_hr = $r_hr * sin(deg2rad(($hours-3) * (360/12))) + 224; imageline($img, 224, 224, $x_sec, $y_sec, $red); imagesetthickness($img, 3); imageline($img, 224, 224, $x_min, $y_min, $black); imagesetthickness($img, 5); imageline($img, 224, 224, $x_hr, $y_hr, $black); header("Content-type: image/png"); imagepng($img); imagedestroy($img); ?> </body> </html> Where should I start? Would you be kind to refer me to existing similar codes if there are? Thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/276598-adding-gd-and-image-functions-in-a-website/ Share on other sites More sharing options...
TOA Posted April 6, 2013 Share Posted April 6, 2013 Read this sticky Quote Link to comment https://forums.phpfreaks.com/topic/276598-adding-gd-and-image-functions-in-a-website/#findComment-1423226 Share on other sites More sharing options...
Jessica Posted April 6, 2013 Share Posted April 6, 2013 Why would you put HTML tags in an image? Quote Link to comment https://forums.phpfreaks.com/topic/276598-adding-gd-and-image-functions-in-a-website/#findComment-1423228 Share on other sites More sharing options...
needs_upgrade Posted April 6, 2013 Author Share Posted April 6, 2013 @jessica: I am adding an image made from php gd inside html. Quote Link to comment https://forums.phpfreaks.com/topic/276598-adding-gd-and-image-functions-in-a-website/#findComment-1423229 Share on other sites More sharing options...
Barand Posted April 6, 2013 Share Posted April 6, 2013 Code to produce a GD image should be in a separate php file, say myimage.php To put the image on the page you use an img tag, just as you would with any other image <img src="myimage.php" /> Quote Link to comment https://forums.phpfreaks.com/topic/276598-adding-gd-and-image-functions-in-a-website/#findComment-1423265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.