echo '<html dir="rtl"> <head><title>Persian_log2vis Example</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head><body> <form method="get"> <textarea name="text">ایــن متن برای تست میباشد: بالا فَعّال الف abc ب ۲۰ و 20 - ۳۰ و 30 </textarea> <input type="submit" name="submit" value="submit"> </body></html>'; } else { $text = $_GET['text']; persian_log2vis($text); // Create the image $im = imagecreatetruecolor(400, 200); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); // Replace path by your own font path $font = './DejaVuSans.ttf'; // Add the text @imagettftext($im, 20, 0, 10, 30, $white, $font, $text); // Set the content-type header("Content-type: image/png"); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); }
/** * print ancestors on a fan chart * @param array $treeid ancestry pid * @param int $fanw fan width in px (default=840) * @param int $fandeg fan size in deg (default=270) */ function print_fan_chart($treeid, $fanw = 840, $fandeg = 270) { global $dbh, $tree_id, $db_functions, $fontsize, $date_display; global $fan_style, $family_id; global $printing, $language, $selected_language; global $pers_var, $tree_prefix_quoted; global $china_message; // check for GD 2.x library if (!defined("IMG_ARC_PIE")) { print "ERROR: NO GD LIBRARY"; return false; } if (!function_exists("ImageTtfBbox")) { print "ERROR: NO GD LIBRARY"; return false; } if (intval($fontsize) < 2) { $fontsize = 7; } $treesize = count($treeid); if ($treesize < 1) { return; } // generations count $gen = log($treesize) / log(2) - 1; $sosa = $treesize - 1; // fan size if ($fandeg == 0) { $fandeg = 360; } $fandeg = min($fandeg, 360); $fandeg = max($fandeg, 90); $cx = $fanw / 2 - 1; // center x $cy = $cx; // center y $rx = $fanw - 1; $rw = $fanw / ($gen + 1); $fanh = $fanw; // fan height if ($fandeg == 180) { $fanh = round($fanh * ($gen + 1) / ($gen * 2)); } if ($fandeg == 270) { $fanh = round($fanh * 0.86); } $scale = $fanw / 840; // image init $image = ImageCreate($fanw, $fanh); $black = ImageColorAllocate($image, 0, 0, 0); $white = ImageColorAllocate($image, 0xff, 0xff, 0xff); ImageFilledRectangle($image, 0, 0, $fanw, $fanh, $white); if ($printing == 1) { ImageColorTransparent($image, $white); } // *** Border colour *** $rgb = ""; if (empty($rgb)) { $rgb = "#6E6E6E"; } $grey = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); // *** Text colour *** $rgb = ""; if (empty($rgb)) { $rgb = "#000000"; } $color = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); // *** Background colour *** $rgb = ""; if (empty($rgb)) { $rgb = "#EEEEEE"; } $bgcolor = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); // *** Man colour *** $rgb = ""; if (empty($rgb)) { $rgb = "#B2DFEE"; } $bgcolorM = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); // *** wife colour *** $rgb = ""; if (empty($rgb)) { $rgb = "#FFE4C4"; } $bgcolorF = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); // imagemap $imagemap = "<map id=\"fanmap\" name=\"fanmap\">"; // loop to create fan cells while ($gen >= 0) { // clean current generation area $deg2 = 360 + ($fandeg - 180) / 2; $deg1 = $deg2 - $fandeg; ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bgcolor, IMG_ARC_PIE); ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bgcolor, IMG_ARC_EDGED | IMG_ARC_NOFILL); $rx -= 3; // calculate new angle $p2 = pow(2, $gen); $angle = $fandeg / $p2; $deg2 = 360 + ($fandeg - 180) / 2; $deg1 = $deg2 - $angle; // special case for rootid cell if ($gen == 0) { $deg1 = 90; $deg2 = 360 + $deg1; } // draw each cell while ($sosa >= $p2) { $pid = $treeid[$sosa][0]; $birthyr = $treeid[$sosa][1]; $deathyr = $treeid[$sosa][4]; $fontpx = $fontsize; if ($sosa >= 16 and $fandeg == 180) { $fontpx = $fontsize - 1; } if ($sosa >= 32 and $fandeg != 180) { $fontpx = $fontsize - 1; } if (!empty($pid)) { if ($sosa % 2) { $bg = $bgcolorF; } else { $bg = $bgcolorM; } if ($sosa == 1) { if ($treeid[$sosa][5] == "F") { $bg = $bgcolorF; } else { if ($treeid[$sosa][5] == "M") { $bg = $bgcolorM; } else { $bg = $bgcolor; // sex unknown } } } ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bg, IMG_ARC_PIE); if ($gen != 0) { ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $grey, IMG_ARC_EDGED | IMG_ARC_NOFILL); } else { ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $grey, IMG_ARC_NOFILL); } $name = $pid; // check if string is RTL language- if it is, it has to be reversed later on by persian_log2vis() $rtlstr = 0; //if(preg_match('/(*UTF8)[א-ת]/',$name)!==0 OR preg_match('/(*UTF8)[أ-ى]/',$name)!==0) { if (preg_match('/(*UTF8)[א-ת]/', $name) === 1 or preg_match('/(*UTF8)[أ-ى]/', $name) === 1) { // this is either Hebrew, Arabic or Persian -> we have to reverse the text! $rtlstr = 1; } $fontfile = CMS_ROOTPATH . "include/fanchart/dejavusans.ttf"; // this default font serves: Latin,Hebrew,Arabic,Persian,Russian //if(preg_match('/(*UTF8)\p{Han}/',$name)!==0) { // String is Chinese so use a Chinese ttf font if present in the folder if (preg_match('/(*UTF8)\\p{Han}/', $name) === 1) { // String is Chinese so use a Chinese ttf font if present in the folder if (is_dir(CMS_ROOTPATH . "include/fanchart/chinese")) { $dh = opendir(CMS_ROOTPATH . "include/fanchart/chinese"); while (false !== ($filename = readdir($dh))) { //if (strtolower(substr($filename, -3)) == "ttf"){ if (strtolower(substr($filename, -3)) == "otf" or strtolower(substr($filename, -3)) == "ttf") { $fontfile = CMS_ROOTPATH . "include/fanchart/chinese/" . $filename; } } } if ($fontfile == CMS_ROOTPATH . "include/fanchart/dejavusans.ttf") { //no Chinese ttf file found $china_message = 1; } } $text = $name; // names $text2 = ""; // dates if ($date_display == 1) { // don't show dates } else { if ($date_display == 2) { //show years only // years only chosen but we also do this if no place in outer circles $text2 .= substr($birthyr, -4) . " - " . substr($deathyr, -4); } else { if ($date_display == 3) { //show full dates (but not in narrow outer circles!) if ($gen > 5) { $text2 .= substr($birthyr, -4) . " - " . substr($deathyr, -4); } else { if ($gen > 4 and $fan_style != 4) { $text2 .= substr($birthyr, -4) . " - " . substr($deathyr, -4); } else { // full dates if ($birthyr) { $text2 .= "b." . $birthyr . "\n"; } if ($deathyr) { $text2 .= "d." . $deathyr; } } } } } } // split and center text by lines $wmax = floor($angle * 7 / $fontpx * $scale); $wmax = min($wmax, 35 * $scale); //35 //$wmax = floor((90*$wmax)/100); if ($gen == 0) { $wmax = min($wmax, 17 * $scale); } //17 $text = split_align_text($text, $wmax, $rtlstr, 1, $gen); $text2 = split_align_text($text2, $wmax, $rtlstr, 0, $gen); if ($rtlstr == 1) { persian_log2vis($text); // converts persian, arab and hebrew text from logical to visual and reverses it } $text .= "\n" . $text2; // text angle $tangle = 270 - ($deg1 + $angle / 2); if ($gen == 0) { $tangle = 0; } // calculate text position $bbox = ImageTtfBbox((double) $fontpx, 0, $fontfile, $text); $textwidth = $bbox[4]; //4 $deg = $deg1 + 0.44; if ($deg2 - $deg1 > 40) { $deg = $deg1 + ($deg2 - $deg1) / 11; } // 11 if ($deg2 - $deg1 > 80) { $deg = $deg1 + ($deg2 - $deg1) / 7; } // 7 if ($deg2 - $deg1 > 140) { $deg = $deg1 + ($deg2 - $deg1) / 4; } // 4 if ($gen == 0) { $deg = 180; } $rad = deg2rad($deg); $mr = ($rx - $rw / 4) / 2; if ($gen > 0 and $deg2 - $deg1 > 80) { $mr = $rx / 2; } $tx = $cx + $mr * cos($rad); $ty = $cy - $mr * -sin($rad); if ($sosa == 1) { $ty -= $mr / 2; } // print text ImageTtfText($image, (double) $fontpx, $tangle, $tx, $ty, $color, $fontfile, $text); $imagemap .= "<area shape=\"poly\" coords=\""; // plot upper points $mr = $rx / 2; $deg = $deg1; while ($deg <= $deg2) { $rad = deg2rad($deg); $tx = round($cx + $mr * cos($rad)); $ty = round($cy - $mr * -sin($rad)); $imagemap .= "{$tx}, {$ty}, "; $deg += ($deg2 - $deg1) / 6; } // plot lower points $mr = ($rx - $rw) / 2; $deg = $deg2; while ($deg >= $deg1) { $rad = deg2rad($deg); $tx = round($cx + $mr * cos($rad)); $ty = round($cy - $mr * -sin($rad)); $imagemap .= "{$tx}, {$ty}, "; $deg -= ($deg2 - $deg1) / 6; } // join first point $mr = $rx / 2; $deg = $deg1; $rad = deg2rad($deg); $tx = round($cx + $mr * cos($rad)); $ty = round($cy - $mr * -sin($rad)); $imagemap .= "{$tx}, {$ty}"; if (CMS_SPECIFIC == "Joomla") { $imagemap .= "\" href=\"index.php?option=com_humo-gen&task=family&id=" . $treeid[$sosa][2] . "&main_person=" . $treeid[$sosa][3] . "\""; } else { $imagemap .= "\" href=\"family.php?id=" . $treeid[$sosa][2] . "&main_person=" . $treeid[$sosa][3] . "\""; } //NEW - add first spouse to base person's tooltip $spousename = ""; if ($gen == 0 and $treeid[1][2] != "") { // base person and has spouse if ($treeid[1][5] == "F") { $spouse = "fam_man"; } else { $spouse = "fam_woman"; } $spouse_result = $dbh->query("SELECT " . $spouse . " FROM humo_families\n\t\t\t\t\t\tWHERE fam_tree_id='" . $tree_id . "' AND fam_gedcomnumber='" . $treeid[1][2] . "'"); @($spouseDb = $spouse_result->fetch()); // fetch() with no parameter deaults to array which is what we want here @($spouse2Db = $db_functions->get_person($spouseDb[$spouse])); $spouse_cls = new person_cls(); $spouse_cls->construct($spouse2Db); $spname = $spouse_cls->person_name($spouse2Db); if ($treeid[1][5] == "F") { $spouse_lan = "SPOUSE_MALE"; } else { $spouse_lan = "SPOUSE_FEMALE"; } if ($spname != "") { $spousename = "\n(" . __($spouse_lan) . ": " . $spname["standard_name"] . ")"; } } $imagemap .= " alt=\"" . $pid . "\" title=\"" . $pid . $spousename . "\">"; } $deg1 -= $angle; $deg2 -= $angle; $sosa--; } $rx -= $rw; $gen--; } $imagemap .= "</map>"; echo $imagemap; $image_title = preg_replace("~<.*>~", "", $name) . " - " . __('RELOAD FANCHART WITH \'VIEW\' BUTTON ON THE LEFT'); echo "<p align=\"center\" >"; if (CMS_SPECIFIC == "Joomla") { ImagePng($image, CMS_ROOTPATH . "include/fanchart/tmpimg.png"); $ext = "?" . time(); // add random string to file to prevent loading from cache and then replacing which is not nice echo "<img src=\"index.php?option=com_humo-gen&task=fanimage&format=raw&nochache=" . $ext . "\" width=\"{$fanw}\" height=\"{$fanh}\" border=\"0\" alt=\"{$image_title}\" title=\"{$image_title}\" usemap=\"#fanmap\">"; } else { ob_start(); ImagePng($image); $image_data = ob_get_contents(); ob_end_clean(); $image_data = serialize($image_data); unset($_SESSION['image_data']); $_SESSION['image_data'] = $image_data; echo "<img src=\"include/fanchart/fanimage.php\" width=\"{$fanw}\" height=\"{$fanh}\" border=\"0\" alt=\"{$image_title}\" title=\"{$image_title}\" usemap=\"#fanmap\">"; } echo "</p>\n"; ImageDestroy($image); }