begin_document("",""); $pdf->set_info("Creator","colourwheel.php"); $pdf->set_info("Author","Telyn Z."); $pdf->set_info("Title","Colour Wheel"); $pdf->begin_page_ext($size,$size,""); //$pdf->setcolor("fill","rgb",0,0,0,0); //uncomment this line to get a black background $pdf->rect(0,0,$size,$size); $pdf->fill(); $font = $pdf->load_font("Helvetica","iso8859-1",""); $pdf->setfont($font,$fontsize); define("DEG_TO_RAD",M_PI/180); //define the origin $ox = $size/2; $oy = $ox; $radius = $ox - $size/10; $mysql = new MySQLi("mysql","root","password","colourwheel"); $result = $mysql->query("SELECT name,red,green,blue,hue,saturation,value FROM colours"); while($colour = $result->fetch_array()) { //Each colour's hsv & rgb are between 0 and 1. $angle = -90; //this puts the angle at the top right now. $angle -= ($colour['hue']*360); //puts the angle in the right place. $width = $pdf->stringwidth($colour['name'],$font,$fontsize); $distance = ($width/2) + ($colour['value']*$radius); //offset text length. $radians = $angle*DEG_TO_RAD; $x = cos($radians)*$distance; $y = sin($radians)*$distance; $y = $oy-$y; $x += $ox; $pdf->setcolor("fill","rgb",$colour['red'],$colour['green'],$colour['blue'],0); $pdf->fit_textline($colour['name'],$x,$y,"rotate=".-$angle); } $pdf->end_page_ext(""); $pdf->end_document(""); $buffer = $pdf->get_buffer(); $length = strlen($buffer); $pdf->delete(); # header("Content-Type: application/pdf"); # header("Content-Length: $len"); # header("Content-Disposition: inline; filename=colourwheel.pdf"); echo $buffer; ?>