$maxwidth) { $lines[] = $words[$i]; //make new line with word $last_line++; } else { $lines[$last_line] .= " " . $words[$i]; //add word to last line } $linesize = textWidth($lines[$last_line], $size, $font); } } function imgWordWrap($string, &$lines, $maxwidth, $textsize, $textfont) { $sentences = explode("\n", $string); $nsentences = count($sentences); for ($i=0; $i<$nsentences; $i++) { $lines[] = ''; splitSentence($sentences[$i], $lines, $maxwidth, $textsize, $textfont); } $nlines = count($lines); for ($i=0; $i<$nlines; $i++) { $lines[$i] = trim($lines[$i]); } } function drawText(&$picture, $lines, $textsize, $lineheight, $textfont, $colors, $blueball, $noptions) { $startpoint = 20 + $textsize; $nlines = count($lines['question']); for ($i=0; $i<$nlines; $i++) { $drawpoint = $startpoint + $lineheight*$i; imageTTFText($picture, $textsize, 0, 20, $drawpoint, 1*$colors['black'], $textfont, $lines['question'][$i]); } for ($h=0; $h<$noptions; $h++) { $nlines = count($lines['options'][$h]); $startpoint = $drawpoint + $lineheight + $textsize; //empty line imageCopy($picture, $blueball, 20, $startpoint-10, 0, 0, imagesx($blueball), imagesy($blueball)); for ($i=0; $i<$nlines; $i++) { $drawpoint = $startpoint + $lineheight*$i; imageTTFText($picture, $textsize, 0, 40, $drawpoint, 1*$colors['black'], $textfont, $lines['options'][$h][$i]); } } } function getLines($question, $options, $textsize, $textfont, $noptions) { $lines = array(); $lines['question'] = array(); $lines['options'] = array(array()); imgWordWrap($question, $lines['question'], 210, $textsize, $textfont); for ($i=0; $i<$noptions; $i++) { imgWordWrap($options[$i], $lines['options'][$i], 190, $textsize, $textfont); } return $lines; } function getBoxHeight($lines, $textsize, $lineheight, $noptions) { $boxheight = count($lines['question']) * $lineheight; for ($i=0; $i<$noptions; $i++) { $boxheight += $textsize; $boxheight += count($lines['options'][$i]) * $lineheight; } $boxheight -= $textsize; return $boxheight; } function getColors(&$picture) { $colors = array(); $colors['white'] = imageColorAllocate($picture, 255, 255, 255); $colors['beige'] = imageColorAllocate($picture, 255, 255, 204); $colors['black'] = imageColorAllocate($picture, 1, 1, 1); //0 can not anti alias (0*-1=0) $colors['red'] = imageColorAllocate($picture, 255, 0, 0); return $colors; } function drawPoint ($picture, $colors, $height) { $xoffset = 100; $yoffset = $height+20+7; $xsize = 10; $ysize = 15; $points = array($xoffset, $yoffset, $xoffset+$xsize, $yoffset, $xoffset+$xsize, $yoffset+$ysize); $npoints = 3; imageFilledPolygon($picture, $points, $npoints, $colors['beige']); imageLine($picture, $xoffset, $yoffset, $xoffset+$xsize, $yoffset+$ysize, $color['black']); imageLine($picture, $xoffset+$xsize, $yoffset, $xoffset+$xsize, $yoffset+$ysize, $color['black']); } function makeImage($question, $options, $noptions, $pathfix) { $textsize = 9; $textfont = $pathfix . "../fonts/arial.ttf"; $lineheight = $textsize*2; $lines = getLines($question, $options, $textsize, $textfont, $noptions); $boxheight = getBoxHeight($lines, $textsize, $lineheight, $noptions); $clippy = imageCreateFromPNG($pathfix . "./clippy.png"); $clippyheight = imagesy($clippy); $url = imageCreateFromPNG($pathfix . "./url.png"); $urlheight = imagesy($url); $picture = imagecreatetruecolor(250, $boxheight + 40 + $clippyheight + $urlheight + 10); $colors = getColors($picture); //make background imagefill($picture, 0, 0, $colors['white']); drawRoundedBox($picture, 20, 20, 230, 20+$boxheight, 7, $colors['beige'], $colors['black']); imageCopy($picture, $clippy, 100, $boxheight+40, 0, 0, imagesx($clippy), $clippyheight); drawPoint($picture, $colors, $boxheight); imageCopy($picture, $url, imagesx($picture)/2 - imagesx($url)/2, imagesy($picture)-$urlheight, 0, 0, imagesx($url), imagesy($url)); //draw text $blueball = imageCreateFromPNG($pathfix . "./blueball.png"); drawText($picture, $lines, $textsize, $lineheight, $textfont, $colors, $blueball, $noptions); //output header("Content-type: image/png"); imagePNG($picture); //cleanup imageDestroy($picture); imageDestroy($blueball); imageDestroy($clippy); } if (INCLUDED == "true") //verkrijg variabelen uit parent document { $pathfix = './clippy/'; $question = $rij['question']; $options = array(); if (!empty($rij['option1']) && trim($rij['option1']) != '') $options[] = $rij['option1']; if (!empty($rij['option2']) && trim($rij['option2']) != '') $options[] = $rij['option2']; if (!empty($rij['option3']) && trim($rij['option3']) != '') $options[] = $rij['option3']; if (!empty($rij['option4']) && trim($rij['option4']) != '') $options[] = $rij['option4']; $noptions = count($options); } else { include '../inc_hotlinkcheck.php'; $pathfix = ''; if (isset($_GET['question'])) { if (get_magic_quotes_gpc()) $question = stripslashes($_GET['question']); else $question = $_GET['question']; } else $question = 'Hi there!'; $options = array(); if (isset($_GET['option1']) && !empty($_GET['option1']) && trim($_GET['option1']) != '') { if (get_magic_quotes_gpc()) $options[] = stripslashes($_GET['option1']); else $options[] = $_GET['option1']; } if (isset($_GET['option2']) && !empty($_GET['option2']) && trim($_GET['option2']) != '') { if (get_magic_quotes_gpc()) $options[] = stripslashes($_GET['option2']); else $options[] = $_GET['option2']; } if (isset($_GET['option3']) && !empty($_GET['option3']) && trim($_GET['option3']) != '') { if (get_magic_quotes_gpc()) $options[] = stripslashes($_GET['option3']); else $options[] = $_GET['option3']; } if (isset($_GET['option4']) && !empty($_GET['option4']) && trim($_GET['option4']) != '') { if (get_magic_quotes_gpc()) $options[] = stripslashes($_GET['option4']); else $options[] = $_GET['option4']; } $noptions = count($options); } makeImage($question, $options, $noptions, $pathfix); ?>