/** * Generate both the HTML and PNG components of the fan chart * * The HTML and PNG components both require the same co-ordinate calculations, * so we generate them using the same code, but we send them in separate * HTTP requests. * * @param string $what "png" or "html" * * @return string */ public function generateFanChart($what) { $treeid = $this->sosaAncestors($this->generations); $fanw = 640 * $this->fan_width / 100; $fandeg = 90 * $this->fan_style; $html = ''; $treesize = count($treeid) + 1; // 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 / 640; // image init $image = ImageCreate($fanw, $fanh); $white = ImageColorAllocate($image, 0xff, 0xff, 0xff); ImageFilledRectangle($image, 0, 0, $fanw, $fanh, $white); ImageColorTransparent($image, $white); $color = ImageColorAllocate($image, hexdec(substr(Theme::theme()->parameter('chart-font-color'), 0, 2)), hexdec(substr(Theme::theme()->parameter('chart-font-color'), 2, 2)), hexdec(substr(Theme::theme()->parameter('chart-font-color'), 4, 2))); $bgcolor = ImageColorAllocate($image, hexdec(substr(Theme::theme()->parameter('chart-background-u'), 0, 2)), hexdec(substr(Theme::theme()->parameter('chart-background-u'), 2, 2)), hexdec(substr(Theme::theme()->parameter('chart-background-u'), 4, 2))); $bgcolorM = ImageColorAllocate($image, hexdec(substr(Theme::theme()->parameter('chart-background-m'), 0, 2)), hexdec(substr(Theme::theme()->parameter('chart-background-m'), 2, 2)), hexdec(substr(Theme::theme()->parameter('chart-background-m'), 4, 2))); $bgcolorF = ImageColorAllocate($image, hexdec(substr(Theme::theme()->parameter('chart-background-f'), 0, 2)), hexdec(substr(Theme::theme()->parameter('chart-background-f'), 2, 2)), hexdec(substr(Theme::theme()->parameter('chart-background-f'), 4, 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); $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) { $person = $treeid[$sosa]; if ($person) { $name = $person->getFullName(); $addname = $person->getAddName(); $text = I18N::reverseText($name); if ($addname) { $text .= "\n" . I18N::reverseText($addname); } $text .= "\n" . I18N::reverseText($person->getLifeSpan()); switch ($person->getSex()) { case 'M': $bg = $bgcolorM; break; case 'F': $bg = $bgcolorF; break; default: $bg = $bgcolor; break; } ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bg, IMG_ARC_PIE); // split and center text by lines $wmax = (int) ($angle * 7 / Theme::theme()->parameter('chart-font-size') * $scale); $wmax = min($wmax, 35 * $scale); if ($gen == 0) { $wmax = min($wmax, 17 * $scale); } $text = $this->splitAlignText($text, $wmax); // text angle $tangle = 270 - ($deg1 + $angle / 2); if ($gen == 0) { $tangle = 0; } // calculate text position $deg = $deg1 + 0.44; if ($deg2 - $deg1 > 40) { $deg = $deg1 + ($deg2 - $deg1) / 11; } if ($deg2 - $deg1 > 80) { $deg = $deg1 + ($deg2 - $deg1) / 7; } if ($deg2 - $deg1 > 140) { $deg = $deg1 + ($deg2 - $deg1) / 4; } if ($gen == 0) { $deg = 180; } $rad = deg2rad($deg); $mr = ($rx - $rw / 4) / 2; if ($gen > 0 && $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, Theme::theme()->parameter('chart-font-size'), $tangle, $tx, $ty, $color, Theme::theme()->parameter('chart-font-name'), $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}"; // add action url $pid = $person->getXref(); $imagemap .= '" href="#' . $pid . '"'; $tempURL = 'fanchart.php?rootid=' . $pid . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width . '&fan_style=' . $this->fan_style . '&ged=' . $person->getTree()->getNameUrl(); $html .= '<div id="' . $pid . '" class="fan_chart_menu">'; $html .= '<div class="person_box"><div class="details1">'; $html .= '<a href="' . $person->getHtmlUrl() . '" class="name1">' . $name; if ($addname) { $html .= $addname; } $html .= '</a>'; $html .= '<ul class="charts">'; $html .= '<li><a href="pedigree.php?rootid=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '" >' . I18N::translate('Pedigree') . '</a></li>'; if (Module::getModuleByName('googlemap')) { $html .= '<li><a href="module.php?mod=googlemap&mod_action=pedigree_map&rootid=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '">' . I18N::translate('Pedigree map') . '</a></li>'; } $gedcomid = $person->getTree()->getUserPreference(Auth::user(), 'gedcomid'); if ($gedcomid && $gedcomid != $pid) { $html .= '<li><a href="relationship.php?pid1=' . $gedcomid . '&pid2=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '">' . I18N::translate('Relationship to me') . '</a></li>'; } $html .= '<li><a href="descendancy.php?rootid=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '" >' . I18N::translate('Descendants') . '</a></li>'; $html .= '<li><a href="ancestry.php?rootid=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '">' . I18N::translate('Ancestors') . '</a></li>'; $html .= '<li><a href="compact.php?rootid=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '">' . I18N::translate('Compact tree') . '</a></li>'; $html .= '<li><a href="' . $tempURL . '">' . I18N::translate('Fan chart') . '</a></li>'; $html .= '<li><a href="hourglass.php?rootid=' . $pid . '&ged=' . $person->getTree()->getNameUrl() . '">' . I18N::translate('Hourglass chart') . '</a></li>'; if (Module::getModuleByName('tree')) { $html .= '<li><a href="module.php?mod=tree&mod_action=treeview&ged=' . $person->getTree()->getNameUrl() . '&rootid=' . $pid . '">' . I18N::translate('Interactive tree') . '</a></li>'; } $html .= '</ul>'; // spouse(s) and children foreach ($person->getSpouseFamilies() as $family) { $spouse = $family->getSpouse($person); if ($spouse) { $html .= '<a href="' . $spouse->getHtmlUrl() . '" class="name1">' . $spouse->getFullName() . '</a>'; $kids = $family->getChildren(); if ($kids) { $html .= '<ul class="children">'; foreach ($kids as $child) { $html .= '<li><a href="' . $child->getHtmlUrl() . '" class="name1">' . $child->getFullName() . '</a></li>'; } $html .= '</ul>'; } } } // siblings foreach ($person->getChildFamilies() as $family) { $children = $family->getChildren(); if ($children) { $html .= '<div class="name1">'; // With two children in a family, you have only one sibling. $html .= count($children) > 2 ? I18N::translate('Siblings') : I18N::translate('Sibling'); $html .= '</div>'; $html .= '<ul class="siblings">'; foreach ($children as $sibling) { if ($sibling !== $person) { $html .= '<li><a href="' . $sibling->getHtmlUrl() . '" class="name1"> ' . $sibling->getFullName() . '</a></li>'; } } $html .= '</ul>'; } } $html .= '</div></div>'; $html .= '</div>'; $imagemap .= ' alt="' . strip_tags($person->getFullName()) . '" title="' . strip_tags($person->getFullName()) . '">'; } $deg1 -= $angle; $deg2 -= $angle; $sosa--; } $rx -= $rw; $gen--; } $imagemap .= '</map>'; switch ($what) { case 'html': return $html . $imagemap . '<div id="fan_chart_img"><img src="' . WT_SCRIPT_NAME . '?rootid=' . $this->root->getXref() . '&fan_style=' . $this->fan_style . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width . '&img=1" width="' . $fanw . '" height="' . $fanh . '" alt="' . strip_tags($this->getPageTitle()) . '" usemap="#fanmap"></div>'; case 'png': ImageStringUp($image, 1, $fanw - 10, $fanh / 3, WT_BASE_URL, $color); ob_start(); ImagePng($image); ImageDestroy($image); return ob_get_clean(); default: throw new \InvalidArgumentException(__METHOD__ . ' ' . $what); } }
/** * print ancestors on a fan chart * * @param array $treeid ancestry pid * @param int $fanw fan width in px (default=640) * @param int $fandeg fan size in deg (default=270) */ function print_fan_chart($treeid, $fanw = 640, $fandeg = 270) { global $PEDIGREE_GENERATIONS, $fan_width, $fan_style; global $name, $pgv_lang, $SHOW_ID_NUMBERS, $view, $TEXT_DIRECTION; global $stylesheet, $print_stylesheet; global $PGV_IMAGE_DIR, $PGV_IMAGES, $LINK_ICONS, $GEDCOM; // check for GD 2.x library if (!defined("IMG_ARC_PIE")) { print "<span class=\"error\">" . $pgv_lang["gd_library"] . "</span>"; print " <a href=\"" . $pgv_lang["gd_helplink"] . "\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["help"]["small"] . "\" class=\"icon\" alt=\"\" /></a><br /><br />"; return false; } if (!function_exists("ImageTtfBbox")) { print "<span class=\"error\">" . $pgv_lang["gd_freetype"] . "</span>"; print " <a href=\"" . $pgv_lang["gd_helplink"] . "\"><img src=\"" . $PGV_IMAGE_DIR . "/" . $PGV_IMAGES["help"]["small"] . "\" class=\"icon\" alt=\"\" /></a><br /><br />"; return false; } // parse CSS file include "includes/cssparser.inc.php"; $css = new cssparser(false); if ($view == "preview") { $css->Parse($print_stylesheet); } else { $css->Parse($stylesheet); } // check for fontfile $fontfile = $css->Get(".fan_chart", "font-family"); $fontsize = $css->Get(".fan_chart", "font-size"); $fontfile = str_replace("url(", "", $fontfile); $fontfile = str_replace(")", "", $fontfile); if (!file_exists($fontfile)) { if (!empty($fontfile)) { print "<span class=\"error\">" . $pgv_lang["fontfile_error"] . " : {$fontfile}</span>"; } $fontfile = "./includes/fonts/DejaVuSans.ttf"; } if ($fontfile[0] != '/') { $fontfile = dirname(__FILE__) . "/" . $fontfile; } if (!file_exists($fontfile)) { print "<span class=\"error\">" . $pgv_lang["fontfile_error"] . " : {$fontfile}</span>"; 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 / 640; // 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); ImageColorTransparent($image, $white); $rgb = $css->Get(".fan_chart", "color"); if (empty($rgb)) { $rgb = "#000000"; } $color = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); $rgb = $css->Get(".fan_chart", "background-color"); if (empty($rgb)) { $rgb = "#EEEEEE"; } $bgcolor = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); $rgb = $css->Get(".fan_chart_box", "background-color"); if (empty($rgb)) { $rgb = "#D0D0AC"; } $bgcolorM = ImageColorAllocate($image, hexdec(substr($rgb, 1, 2)), hexdec(substr($rgb, 3, 2)), hexdec(substr($rgb, 5, 2))); $rgb = $css->Get(".fan_chart_boxF", "background-color"); if (empty($rgb)) { $rgb = "#D0ACD0"; } $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); $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]; if (!empty($pid)) { $indirec = find_person_record($pid); if (!$indirec) { $indirec = find_updated_record($pid); } if ($sosa % 2) { $bg = $bgcolorF; } else { $bg = $bgcolorM; } if ($sosa == 1) { $bg = $bgcolor; // sex unknown if (preg_match("/1 SEX F/", $indirec) > 0) { $bg = $bgcolorF; } else { if (preg_match("/1 SEX M/", $indirec) > 0) { $bg = $bgcolorM; } } } ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bg, IMG_ARC_PIE); $person = Person::getInstance($pid); $name = $person->getFullName(); $addname = $person->getAddName(); //$name = str_replace(array('<span class="starredname">', '</span>'), '', $name); //$addname = str_replace(array('<span class="starredname">', '</span>'), '', $addname); //$name = str_replace(array('<span class="starredname">', '</span>'), array('<u>', '</u>'), $name); //@@ //$addname = str_replace(array('<span class="starredname">', '</span>'), array('<u>', '</u>'), $addname); //@@ // ToDo - print starred names underlined - 1985154 // Todo - print Arabic letters combined - 1360209 $text = reverseText($name) . "\n"; if (!empty($addname)) { $text .= reverseText($addname) . "\n"; } if (displayDetailsById($pid)) { $birthrec = get_sub_record(1, "1 BIRT", $indirec); $ct = preg_match("/2 DATE.*(\\d\\d\\d\\d)/", $birthrec, $match); if ($ct > 0) { $text .= trim($match[1]); } $deathrec = get_sub_record(1, "1 DEAT", $indirec); $ct = preg_match("/2 DATE.*(\\d\\d\\d\\d)/", $deathrec, $match); if ($ct > 0) { $text .= "-" . trim($match[1]); } } $text = unhtmlentitiesrtl($text); $text = strip_tags($text); //Do we still need? // split and center text by lines $wmax = floor($angle * 7 / $fontsize * $scale); $wmax = min($wmax, 35 * $scale); if ($gen == 0) { $wmax = min($wmax, 17 * $scale); } $text = split_align_text($text, $wmax); // text angle $tangle = 270 - ($deg1 + $angle / 2); if ($gen == 0) { $tangle = 0; } // calculate text position $bbox = ImageTtfBbox((double) $fontsize, 0, $fontfile, $text); $textwidth = $bbox[4]; $deg = $deg1 + 0.44; if ($deg2 - $deg1 > 40) { $deg = $deg1 + ($deg2 - $deg1) / 11; } if ($deg2 - $deg1 > 80) { $deg = $deg1 + ($deg2 - $deg1) / 7; } if ($deg2 - $deg1 > 140) { $deg = $deg1 + ($deg2 - $deg1) / 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) $fontsize, $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}"; // add action url $tempURL = "javascript://" . htmlspecialchars(strip_tags($name)); if ($SHOW_ID_NUMBERS) { $tempURL .= " (" . $pid . ")"; } $imagemap .= "\" href=\"{$tempURL}\" "; $tempURL = "fanchart.php?rootid={$pid}&PEDIGREE_GENERATIONS={$PEDIGREE_GENERATIONS}&fan_width={$fan_width}&fan_style={$fan_style}"; if (!empty($view)) { $tempURL .= "&view={$view}"; } $count = 0; $lbwidth = 200; print "<div id=\"I" . $pid . "." . $count . "links\" style=\"position:absolute; >"; print "left:" . $tx . "px; top:" . $ty . "px; width: " . $lbwidth . "px; visibility:hidden; z-index:'100';\">"; print "<table class=\"person_box\"><tr><td class=\"details1\">"; print "<a href=\"individual.php?pid={$pid}\" class=\"name1\">" . PrintReady($name); if (!empty($addname)) { print "<br />" . PrintReady($addname); } print "</a>"; print "<br /><a href=\"pedigree.php?rootid={$pid}\" >" . $pgv_lang["index_header"] . "</a>"; print "<br /><a href=\"descendancy.php?pid={$pid}\" >" . $pgv_lang["descend_chart"] . "</a>"; if (PGV_USER_GEDCOM_ID) { print "<br /><a href=\"" . encode_url("relationship.php?pid1=" . PGV_USER_GEDCOM_ID . "&pid2={$pid}&ged={$GEDCOM}") . "\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["relationship_to_me"] . "</a>"; } print "<br /><a href=\"ancestry.php?rootid={$pid}\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["ancestry_chart"] . "</a>"; print "<br /><a href=\"compact.php?rootid={$pid}\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["compact_chart"] . "</a>"; print "<br /><a href=\"" . encode_url($tempURL) . "\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["fan_chart"] . "</a>"; print "<br /><a href=\"hourglass.php?pid={$pid}\" onmouseover=\"clear_family_box_timeout('" . $pid . "." . $count . "');\" onmouseout=\"family_box_timeout('" . $pid . "." . $count . "');\">" . $pgv_lang["hourglass_chart"] . "</a>"; if ($sosa >= 1) { $famids = find_sfamily_ids($pid); //-- make sure there is more than 1 child in the family with parents $cfamids = find_family_ids($pid); $num = 0; for ($f = 0; $f < count($cfamids); $f++) { $famrec = find_family_record($cfamids[$f]); if ($famrec) { $num += preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER); } } if ($famids || $num > 1) { //-- spouse(s) and children for ($f = 0; $f < count($famids); $f++) { $famrec = find_family_record(trim($famids[$f])); if ($famrec) { $parents = find_parents($famids[$f]); if ($parents) { if ($pid != $parents["HUSB"]) { $spid = $parents["HUSB"]; } else { $spid = $parents["WIFE"]; } $person = Person::getInstance($spid); if ($person) { echo '<br /><a href="', $person->getLinkUrl(), '" class="name1">', $person->getFullName(), '</a>'; } } $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER); for ($i = 0; $i < $num; $i++) { $person = Person::getInstance($smatch[$i][1]); if ($person) { echo '<br /> <a href="', $person->getLinkUrl(), '" class="name1">< ', $person->getFullName(), '</a>'; } } } } //-- siblings for ($f = 0; $f < count($cfamids); $f++) { $famrec = find_family_record($cfamids[$f]); if ($famrec) { $num = preg_match_all("/1\\s*CHIL\\s*@(.*)@/", $famrec, $smatch, PREG_SET_ORDER); if ($num > 2) { print "<br /><span class=\"name1\">" . $pgv_lang["siblings"] . "</span>"; } if ($num == 2) { print "<br /><span class=\"name1\">" . $pgv_lang["sibling"] . "</span>"; } for ($i = 0; $i < $num; $i++) { $cpid = $smatch[$i][1]; if ($cpid != $pid) { $person = Person::getInstance($cpid); if ($person) { echo '<br /> <a href="', $person->getLinkUrl(), '" class="name1"> ', $person->getFullName(), '</a>'; } } } } } } } print "</td></tr></table>"; print "</div>"; $imagemap .= " onclick=\"show_family_box('" . $pid . "." . $count . "', 'relatives'); return false;\""; $imagemap .= " onmouseout=\"family_box_timeout('" . $pid . "." . $count . "'); return false;\""; $imagemap .= " alt=\"" . PrintReady(strip_tags($name)) . "\" title=\"" . PrintReady(strip_tags($name)) . "\" />"; } $deg1 -= $angle; $deg2 -= $angle; $sosa--; } $rx -= $rw; $gen--; } $imagemap .= "</map>"; echo $imagemap; // PGV banner ;-) ImageStringUp($image, 1, $fanw - 10, $fanh / 3, PGV_PHPGEDVIEW_URL, $color); // here we cannot send image to browser ('header already sent') // and we dont want to use a tmp file // step 1. save image data in a session variable 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; // step 2. call imageflush.php to read this session variable and display image // note: arg "image_name=" is to avoid image miscaching $image_name = "V" . time(); unset($_SESSION[$image_name]); // statisticsplot.php uses this to hold a file name to send to browser $image_title = preg_replace("~<.*>~", "", $name) . " " . $pgv_lang["fan_chart"]; echo "<p align=\"center\" >"; echo "<img src=\"imageflush.php?image_type=png&image_name={$image_name}&height={$fanh}&width={$fanw}\" width=\"{$fanw}\" height=\"{$fanh}\" border=\"0\" alt=\"{$image_title}\" title=\"{$image_title}\" usemap=\"#fanmap\" />"; echo "</p>"; ImageDestroy($image); }
/** * MakeLogo * The main function which checks all the input values and returns the logo * image with the new text if succesful. If any errors occur, they are * stored in the $Error class variable * * @return string The image binary data */ function MakeLogo() { // if GD isn't enabled, we can't do anything so lets get out of here! if (!$this->GDEnabled) { $this->NoGDError(); return false; } // if we don't know what file type it is, we can't work with it! if (!in_array($this->FileType, array('png', 'gif', 'jpg'))) { $this->Error = 'The logo image is not a known file format'; return false; } // lets make sure GD has the right functions enabled to deal with our // particular file type. if (!$this->CanUseImageFile()) { $this->Error = 'The image file format "' . $FileType . '" is not supported by this copy of GD'; return false; } if ($this->BackgroundImage != null && is_file($this->BackgroundImage) && $this->BackgroundRepeat == LOGOMAKER_NO_REPEAT && !$this->BackgroundColor) { // everything seems good so far, lets make the new logo! $this->ImageHandle = $this->CreateNewImage($this->BackgroundImage); } else { if (function_exists('imagecreatetruecolor')) { $this->ImageHandle = imagecreatetruecolor($this->ImageWidth, $this->ImageHeight); if ($this->FileType == "png") { imagesavealpha($this->ImageHandle, true); if (isset($this->TransparentBackground)) { imagealphablending($this->ImageHandle, false); } else { imagealphablending($this->ImageHandle, true); } $trans_color = imagecolorallocatealpha($this->ImageHandle, 255, 255, 255, 127); imagefilledrectangle($this->ImageHandle, 0, 0, $this->ImageWidth, $this->ImageHeight, $trans_color); imagecolortransparent($this->ImageHandle, $trans_color); } else { if ($this->FileType == "gif") { $trans_color = imagecolorallocate($this->ImageHandle, 255, 255, 255); imagefill($this->ImageHandle, 0, 0, $trans_color); imagecolortransparent($this->ImageHandle, $trans_color); } } } else { $this->ImageHandle = imagecreate($this->ImageWidth, $this->ImageHeight); } if ($this->BackgroundColor) { $bg = $this->AddColor($this->BackgroundColor); imagefilledrectangle($this->ImageHandle, 0, 0, $this->ImageWidth, $this->ImageHeight, $bg); } // If we have a repeating background image, then we need to apply that now if ($this->BackgroundImage != null && is_file($this->BackgroundImage)) { $InsertHandle = $this->CreateNewImage($this->BackgroundImage); imagealphablending($InsertHandle, true); $insert_x = imagesx($InsertHandle); $insert_y = imagesy($InsertHandle); $start_x = 0; $start_y = 0; switch ($this->BackgroundRepeat) { case LOGOMAKER_REPEAT_X: while ($start_x < $this->ImageWidth) { imagecopy($this->ImageHandle, $InsertHandle, $start_x, $start_y, 0, 0, $insert_x, $insert_y); $start_x += $insert_x; } break; case LOGOMAKER_REPEAT_Y: while ($start_y < $this->ImageHeight) { imagecopy($this->ImageHandle, $InsertHandle, $start_x, $start_y, 0, 0, $insert_x, $insert_y); $start_y += $insert_y; } break; case LOGOMAKER_REPEAT: while ($start_x < $this->ImageWidth) { while ($start_y < $this->ImageHeight) { imagecopy($this->ImageHandle, $InsertHandle, $start_x, $start_y, 0, 0, $insert_x, $insert_y); $start_y += $insert_y; } imagecopy($this->ImageHandle, $InsertHandle, $start_x, $start_y, 0, 0, $insert_x, $insert_y); $start_x += $insert_x; $start_y = 0; } break; case LOGOMAKER_NO_REPEAT: imagecopy($this->ImageHandle, $InsertHandle, 0, 0, 0, 0, $insert_x, $insert_y); break; } } } // Loop through any lines and draw them if (is_array($this->Lines) && !empty($this->Lines)) { foreach ($this->Lines as $line) { $color = $this->AddColor($line['color']); imageline($this->ImageHandle, $line['x'], $line['y'], $line['x'] + $line['width'], $line['y'], $color); } } // Draw any shapes we need to if (is_array($this->Shapes) && !empty($this->Shapes)) { foreach ($this->Shapes as $shape) { switch ($shape['type']) { case "rectangle": if ($shape['filled']) { $func = "imagefilledrectangle"; } else { $func = "imagerectangle"; } $color = $this->AddColor($shape['color']); $func($this->ImageHandle, $shape['x'], $shape['y'], $shape['x'] + $shape['width'], $shape['y'] + $shape['height'], $color); break; } } } // loop through any images and add them to the current image if (is_array($this->Images) && count($this->Images) > 0) { foreach ($this->Images as $key => $Image) { $InsertHandle = $this->CreateNewImage($Image['ImageFile']); imagealphablending($InsertHandle, true); $insert_x = imagesx($InsertHandle); $insert_y = imagesy($InsertHandle); imagecopy($this->ImageHandle, $InsertHandle, $Image['x'], $Image['y'], 0, 0, $insert_x, $insert_y); } } // loop through any text and add them to the current image if (is_array($this->ImageText) && count($this->ImageText) > 0) { foreach ($this->ImageText as $key => $Text) { $FontColor = $this->AddColor($Text['Color']); ImageTtfText($this->ImageHandle, $Text['Size'], $Text['Angle'], $Text['x'], $Text['y'], $FontColor, $Text['FontFile'], $Text['Text']); } } // Are we cropping the image to the set dimensions? if (isset($this->CropImage)) { $this->CropImageToDimensions(); } // we're all done, lets return the file image return $this->FinishImage(); }
function DrawTitle($title) { // Figure out where this goes $spacing = 10; $fontsize = 16; $x0 = $spacing; $x1 = $this->canvas_size[0] - $spacing; $y0 = $spacing; $y1 = $this->canvas_offset[1] - $spacing; // Fake a border by +1/-1... $this->_RoundedBox($x0, $y0, $x1, $y1, $spacing, $this->color['line']); $this->_RoundedBox($x0 + 1, $y0 + 1, $x1 - 1, $y1 - 1, $spacing, $this->color['titlebox']); // Determine text positioning $bbox = ImageTtfBBox($fontsize, 0, $this->font, $title); $width = $bbox[2] - $bbox[0]; $height = $bbox[3] - $bbox[7]; ImageTtfText($this->graph, $fontsize, 0, $this->canvas_size[0] / 2 - $width / 2, ($y1 - $y0) / 2 + $height / 2 + $spacing, $this->color['text'], $this->font, $title); }
function do_ticket($formatter, $options) { global $DBInfo; $word_length = 4; if (!empty($options['__seed'])) { // check seed // check referer $passwd = getTicket($options['__seed'], $_SERVER['REMOTE_ADDR'], $word_length); } else { $options['title'] = _("Invalid use of ticket"); do_invalid($formatter, $options); return; } if (!empty($DBInfo->gdfontpath)) { putenv('GDFONTPATH=' . $DBInfo->gdfontpath); } else { // set default GDFONTPATH $old = getenv('GDFONTPATH'); $path = $DBInfo->data_dir; if ($old) { $path = $old . ':' . $new; } putenv('GDFONTPATH=' . $path); } if (function_exists('ImageTtfText')) { while (!empty($DBInfo->ticket_font)) { if (is_numeric($DBInfo->ticket_font)) { break; } $FONT = $DBInfo->ticket_font; //$FONT="/home/foobar/data/PenguinAttack.ttf"; if ($FONT[0] == '/' and !file_exists($FONT)) { $use_ttf = 0; } else { $FONT = $DBInfo->ticket_font; $use_ttf = 1; } break; } } if (!empty($use_ttf)) { $pointsize = !empty($DBInfo->ticket_font_size) ? $DBInfo->ticket_font_size : 16; $angle = 0; //$size = Imagettfbbox($pointsize, 0, $FONT, $passwd); // XXX segfault :( $margin = $pointsize / 2; $size = array(0, 0, 0, 20, 65); //$size=array(0,0,0,20,50); //$w=$size[4]+20; # margin=20 ? $w = $pointsize * $word_length + $margin; $h = $pointsize + $margin; if ($DBInfo->use_ticket & 23) { $h += $pointsize / 3; } } else { $FONT = 5; // giant if (!empty($DBInfo->ticket_gdfont)) { $FONT = $DBInfo->ticket_gdfont; } $w = imagefontwidth($FONT) * strlen($passwd) + 10; $h = imagefontheight($FONT); $pointsize = $h; $h += 10; } $im = ImageCreate($w, $h); $color = array(); if (isset($DBInfo->captcha_bgcolor) and preg_match('/^#[0-9a-fA-F]$/', $DBInfo->captcha_bgcolor)) { $r = substr($DBInfo->captcha_bgcolor, 1, 2); $g = substr($DBInfo->captcha_bgcolor, 3, 2); $b = substr($DBInfo->captcha_bgcolor, 5, 2); $color[] = ImageColorAllocate($im, hexdec($r), hexdec($g), hexdec($b)); // background } else { $color[] = ImageColorAllocate($im, 240, 240, 240); // default background } $color[] = ImageColorAllocate($im, 0, 0, 0); // black $color[] = ImageColorAllocate($im, 255, 255, 255); // white $pen = rand(3, 19); $pen1 = rand(3, 19); for ($i = 0; $i < 18; $i++) { $color[] = ImageColorAllocate($im, rand(100, 200), rand(100, 200), rand(100, 200)); } if (!empty($use_ttf)) { $sx = $margin; $sy = $margin / 2 + $pointsize; ImageTtfText($im, $pointsize, $angle, $sx, $sy + 1, $color[$pen], $FONT, $passwd); ImageTtfText($im, $pointsize, $angle, $sx + 1, $sy, $color[$pen], $FONT, $passwd); } else { ImageString($im, $FONT, 5, 3, $passwd, $color[$pen]); ImageString($im, $FONT, 4, 4, $passwd, $color[$pen]); } $grad = ''; if ($DBInfo->use_ticket & 8) { $grad = 1; } if ($DBInfo->use_ticket & 4) { _effect_distort($im, $pointsize, $grad); } else { if ($DBInfo->use_ticket & 16) { _effect_distort($im, $pointsize, $grad, 1); } } if ($DBInfo->use_ticket & 1) { _effect_blur($im, $color, 1, 1); } if ($DBInfo->use_ticket & 2) { _effect_grid($im, $color, $pen1); } if (function_exists("imagepng")) { header("Content-Type: image/png"); imagepng($im); } else { if (function_exists("imagegif")) { header("Content-Type: image/gif"); imagegif($im); } else { if (function_exists("imagejpeg")) { $jpeg_quality = 5; header("Content-Type: image/jpeg"); imagejpeg($im, null, $jpeg_quality); } } } ImageDestroy($im); }
/** * Generate both the HTML and PNG components of the fan chart * * The HTML and PNG components both require the same co-ordinate calculations, * so we generate them using the same code, but we send them in separate * HTTP requests. * * @param string $what "png" or "html" * @param string[] $fanChart Presentation parameters, provided by the theme. * * @return string */ public function generate_fan_chart($what, $fanChart) { $treeid = ancestry_array($this->root->getXref(), $this->generations); $fanw = 640 * $this->fan_width / 100; $fandeg = 90 * $this->fan_style; $html = ''; $treesize = count($treeid); // 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 / 640; // image init $image = ImageCreate($fanw, $fanh); $white = ImageColorAllocate($image, 0xff, 0xff, 0xff); ImageFilledRectangle($image, 0, 0, $fanw, $fanh, $white); ImageColorTransparent($image, $white); $color = ImageColorAllocate($image, hexdec(substr($fanChart['color'], 1, 2)), hexdec(substr($fanChart['color'], 3, 2)), hexdec(substr($fanChart['color'], 5, 2))); $bgcolor = ImageColorAllocate($image, hexdec(substr($fanChart['bgColor'], 1, 2)), hexdec(substr($fanChart['bgColor'], 3, 2)), hexdec(substr($fanChart['bgColor'], 5, 2))); $bgcolorM = ImageColorAllocate($image, hexdec(substr($fanChart['bgMColor'], 1, 2)), hexdec(substr($fanChart['bgMColor'], 3, 2)), hexdec(substr($fanChart['bgMColor'], 5, 2))); $bgcolorF = ImageColorAllocate($image, hexdec(substr($fanChart['bgFColor'], 1, 2)), hexdec(substr($fanChart['bgFColor'], 3, 2)), hexdec(substr($fanChart['bgFColor'], 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); $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]; $person = WT_Individual::getInstance($pid); if ($person) { $name = $person->getFullName(); $addname = $person->getAddName(); $text = WT_I18N::reverseText($name); if ($addname) { $text .= "\n" . WT_I18N::reverseText($addname); } $text .= "\n" . WT_I18N::reverseText($person->getLifeSpan()); switch ($person->getSex()) { case 'M': $bg = $bgcolorM; break; case 'F': $bg = $bgcolorF; break; case 'U': $bg = $bgcolor; break; } ImageFilledArc($image, $cx, $cy, $rx, $rx, $deg1, $deg2, $bg, IMG_ARC_PIE); // split and center text by lines $wmax = (int) ($angle * 7 / $fanChart['size'] * $scale); $wmax = min($wmax, 35 * $scale); if ($gen == 0) { $wmax = min($wmax, 17 * $scale); } $text = $this->split_align_text($text, $wmax); // text angle $tangle = 270 - ($deg1 + $angle / 2); if ($gen == 0) { $tangle = 0; } // calculate text position $deg = $deg1 + 0.44; if ($deg2 - $deg1 > 40) { $deg = $deg1 + ($deg2 - $deg1) / 11; } if ($deg2 - $deg1 > 80) { $deg = $deg1 + ($deg2 - $deg1) / 7; } if ($deg2 - $deg1 > 140) { $deg = $deg1 + ($deg2 - $deg1) / 4; } if ($gen == 0) { $deg = 180; } $rad = deg2rad($deg); $mr = ($rx - $rw / 4) / 2; if ($gen > 0 && $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) $fanChart['size'], $tangle, $tx, $ty, $color, $fanChart['font'], $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}"; // add action url $imagemap .= '" href="#' . $pid . '"'; $tempURL = 'fanchart.php?rootid=' . $pid . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width . '&fan_style=' . $this->fan_style . '&ged=' . WT_GEDURL; $html .= '<div id="' . $pid . '" class="fan_chart_menu">'; $html .= '<div class="person_box"><div class="details1">'; $html .= '<a href="' . $person->getHtmlUrl() . '" class="name1">' . $name; if ($addname) { $html .= $addname; } $html .= '</a>'; $html .= '<ul class="charts">'; $html .= "<li><a href=\"pedigree.php?rootid={$pid}&amp;ged=" . WT_GEDURL . "\" >" . WT_I18N::translate('Pedigree') . "</a></li>"; if (array_key_exists('googlemap', WT_Module::getActiveModules())) { $html .= "<li><a href=\"module.php?mod=googlemap&mod_action=pedigree_map&rootid=" . $pid . "&ged=" . WT_GEDURL . "\">" . WT_I18N::translate('Pedigree map') . "</a></li>"; } if (WT_USER_GEDCOM_ID && WT_USER_GEDCOM_ID != $pid) { $html .= "<li><a href=\"relationship.php?pid1=" . WT_USER_GEDCOM_ID . "&pid2={$pid}&ged=" . WT_GEDURL . "\">" . WT_I18N::translate('Relationship to me') . "</a></li>"; } $html .= "<li><a href=\"descendancy.php?rootid={$pid}&ged=" . WT_GEDURL . "\" >" . WT_I18N::translate('Descendants') . "</a></li>"; $html .= "<li><a href=\"ancestry.php?rootid={$pid}&ged=" . WT_GEDURL . "\">" . WT_I18N::translate('Ancestors') . "</a></li>"; $html .= "<li><a href=\"compact.php?rootid={$pid}&ged=" . WT_GEDURL . "\">" . WT_I18N::translate('Compact tree') . "</a></li>"; $html .= "<li><a href=\"" . $tempURL . "\">" . WT_I18N::translate('Fan chart') . "</a></li>"; $html .= "<li><a href=\"hourglass.php?rootid={$pid}&ged=" . WT_GEDURL . "\">" . WT_I18N::translate('Hourglass chart') . "</a></li>"; if (array_key_exists('tree', WT_Module::getActiveModules())) { $html .= '<li><a href="module.php?mod=tree&mod_action=treeview&ged=' . WT_GEDURL . '&rootid=' . $pid . '">' . WT_I18N::translate('Interactive tree') . '</a></li>'; } $html .= '</ul>'; // spouse(s) and children foreach ($person->getSpouseFamilies() as $family) { $spouse = $family->getSpouse($person); if ($spouse) { $html .= '<a href="' . $spouse->getHtmlUrl() . '" class="name1">' . $spouse->getFullName() . '</a>'; $kids = $family->getChildren(); if ($kids) { $html .= '<ul class="children">'; foreach ($kids as $child) { $html .= '<li><a href="' . $child->getHtmlUrl() . '" class="name1">' . $child->getFullName() . '</a></li>'; } $html .= '</ul>'; } } } // siblings foreach ($person->getChildFamilies() as $family) { $children = $family->getChildren(); if ($children) { $html .= '<div class="name1">' . WT_I18N::plural('Sibling', 'Siblings', count($children) - 1) . '</div>'; $html .= '<ul class="siblings">'; foreach ($children as $sibling) { if ($sibling !== $person) { $html .= '<li><a href="' . $sibling->getHtmlUrl() . '" class="name1"> ' . $sibling->getFullName() . '</a></li>'; } } $html .= '</ul>'; } } $html .= '</div></div>'; $html .= '</div>'; $imagemap .= ' alt="' . strip_tags($person->getFullName()) . '" title="' . strip_tags($person->getFullName()) . '">'; } $deg1 -= $angle; $deg2 -= $angle; $sosa--; } $rx -= $rw; $gen--; } $imagemap .= '</map>'; switch ($what) { case 'html': $image_title = WT_I18N::translate('Fan chart of %s', strip_tags($person->getFullName())); return $html . $imagemap . '<div id="fan_chart_img"><img src="' . WT_SCRIPT_NAME . '?rootid=' . $this->rootid . '&fan_style=' . $this->fan_style . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width . '&img=1" width="' . $fanw . '" height="' . $fanh . '" alt="' . $image_title . '" title="' . $image_title . '" usemap="#fanmap"></div>'; case 'png': header('Content-Type: image/png'); ImageStringUp($image, 1, $fanw - 10, $fanh / 3, WT_SERVER_NAME . WT_SCRIPT_PATH, $color); ImagePng($image); ImageDestroy($image); } }
/** * Create Timeline Image * * @param $date * @param $draw if FALSE return coordinates only, for imagemap * @param $translate for translate * @param $img_type [normal | small] * @return image */ public function createTimelineImage($date, $draw = true, $translate = null, $img_type = 'normal') { $this->GetDataTimeline($date); if (empty($this->atime)) { // Nothing data to graph return; } $this->calculateImageData($img_type); if (!$draw) { $img_map = array(); } $ttf_font_error = 0; // созд-е пустого холста // Create a new true color image : // resource imagecreatetruecolor ( int width, int height ) $img = ImageCreateTrueColor($this->img_width, $this->img_height); if (!$img) { // Handle the error $this->view->result = null; $this->getResponse()->setHeader('Content-Type', 'text/html; charset=utf-8'); throw new Zend_Exception('Internal ERROR: ImageCreateTrueColor'); return; } // цвета $white = ImageColorAllocate($img, 255, 255, 255); $black = ImageColorAllocate($img, 0, 0, 0); $blue = ImageColorAllocate($img, 0x49, 0x74, 0xbc0); // массив цветов для полос $acolor = array(ImageColorAllocate($img, 0xea, 0xea, 0x33), ImageColorAllocate($img, 0xff, 0xba, 0xba), ImageColorAllocate($img, 0xd0, 0xae, 0xff), ImageColorAllocate($img, 0x9d, 0xed, 0x0), ImageColorAllocate($img, 0xdc, 0xdc, 0xdc)); $acolor_count = count($acolor); // кол-во цветов для рисования полос $bg_color = $white; $text_color = $black; // создание фона для рисования // Draw a filled rectangle : bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color ) if ($draw) { ImageFilledRectangle($img, 0, 0, $this->img_width, $this->img_height, $bg_color); } // контур фона // Draw a rectangle : bool imagerectangle ( resource image, int x1, int y1, int x2, int y2, int color ) if ($draw) { ImageRectangle($img, 0, 0, $this->img_width - 1, $this->img_height - 1, $blue); } // --------------------------------- вычерчивание координатной сетки --------------------------------------- // ось X // Draw a line : // bool imageline ( resource image, int x1, int y1, int x2, int y2, int color ) // $y0, $x0 - начало координат $y0 = $y2 = $this->img_height - $this->margin_bottom - $this->margin_top + $this->bar_space; $x0 = $this->margin_left; if ($draw) { ImageLine($img, $x0, $y0, $this->img_width - $this->margin_right, $y2, $blue); } // ось X // вертикальные линии - часы // пунктирная линия $style_dash = array_merge(array_fill(0, 1, $blue), array_fill(0, 3, IMG_COLOR_TRANSPARENT)); if ($draw) { ImageSetStyle($img, $style_dash); } $hour1 = ceil(($this->img_width - $x0 - $this->margin_right) / 24); // шаг засечек или 1 час в пикселах $y2 = 0; for ($i = 0; $i <= 23; $i++) { $x1 = $x0 + $i * $hour1; ImageLine($img, $x1, $y0, $x1, $y2, IMG_COLOR_STYLED); } if ($img_type == 'normal') { // подписи к оси X $y1 = $this->img_height - $this->margin_bottom - $this->margin_top + $this->bar_space + $this->font_size; for ($i = 0; $i <= 23; $i++) { // Draw a string horizontally : // bool imagestring ( resource image, int font, int x, int y, string sring, int color ) // Can be 1, 2, 3, 4, 5 for built-in fonts (where higher numbers corresponding to larger fonts) // для учета кол-ва символов в цифрах часов if ($i < 10) { $div2 = 10; } else { $div2 = 5; } $x1 = $x0 - $div2 + $i * $hour1; if ($draw) { ImageString($img, 4, $x1, $y1, sprintf("% 2d", $i), $blue); } } // X axis title / название оси X if (empty($this->font_name)) { // use system fixed font / ось подписываем встроенным шрифтом if ($draw) { ImageString($img, $this->fixfont, floor($this->img_width / 2), $this->img_height - floor(($this->img_height - $y0) / 2), "Hours", $blue); } // do not to translate (перевод не нужен) } else { if ($draw) { @($ares = ImageTtfText($img, $this->font_size, 0, floor($this->img_width / 2), $this->img_height - floor(($this->img_height - $y0) / 3), $blue, $this->font_name, $translate->_("Hours"))); if (empty($ares)) { $ttf_font_error = 1; // TTF font not loaded/found if ($draw) { ImageString($img, 4, 5, 5, "Font " . $this->font_name . " not loaded/found.", $black); } // do not to translate (перевод не нужен) } } } } //---------------- draw graph (рисуем график) -------------------------------------------- $yt = $this->margin_top; $c = 0; for ($i = 0; $i <= $this->bar_count - 1; $i++) { $str = '(' . $this->atime[$i]['jobid'] . ') ' . $this->atime[$i]['name']; // для заданий не уложившихся в сутки, рисуем знаки с определенной стороны switch ($this->atime[$i]['flag']) { case -1: $str = '<--' . $str; // задание началось ранее break; case 1: $str = $str . '-->'; // задание закончилось позднее break; case 2: $str = '<--' . $str . '-->'; // задание началось ранее и закончилось позднее (очень длинное задание) break; } // Draw a filled rectangle: // bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color ) // полосы $yr1 = $yt - ceil($this->font_size / 2) - ceil($this->bar_height / 2); $yr2 = $yr1 + $this->bar_height; $xr1 = $x0 + floor($hour1 * $this->atime[$i]['h1']); $xr2 = $x0 + floor($hour1 * $this->atime[$i]['h2']); // если слишком маленькая полоса if ($xr2 - $xr1 < 3) { $xr2 = $xr1 + 3; } // цвет if ($c > $acolor_count - 1) { $c = 0; } // draw restangle if ($draw) { ImageFilledRectangle($img, $xr1, $yr1, $xr2, $yr2, $acolor[$c++]); } // Write text to the image using TrueType fonts : // array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text ) // x - The coordinates given by x and y will define the basepoint of the first character // (roughly the lower-left corner of the character). // This is different from the imagestring(), where x and y define the upper-left corner of the first character. // For example, "top left" is 0, 0. // size - The font size. Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2) // **************** text ***************** // array imagettfbbox ( float size, float angle, string fontfile, string text ) // где расположить текст // расчет координат текста // левая координата X = $abox[0], правая X = $abox[2] if (!$ttf_font_error && !empty($this->font_name)) { // TTF font loaded OK $abox = ImageTtfBbox($this->font_size, 0, $this->font_name, $str); $xt = $xr1 + $this->margin_text_left; if ($xt + $abox[2] > $this->img_width) { $xt = $xr2 - $abox[2] - $this->margin_text_left; if (!$draw) { $xt > $xr2 ? $x2 = $xt : ($x2 = $xr2); } // coordinates for imagemap } else { if (!$draw) { $xt + $abox[2] > $xr2 ? $x2 = $xt + $abox[2] : ($x2 = $xr2); } // coordinates for imagemap } // draw text if ($draw) { ImageTtfText($img, $this->font_size, 0, $xt, $yt, $text_color, $this->font_name, $str); } } else { // fix font $lenfix = strlen($str) * imagefontwidth($this->fixfont); if ($xr1 + $lenfix > $this->img_width) { $xt = $xr2 - $lenfix - $this->margin_text_left; if (!$draw) { $xt > $xr2 ? $x2 = $xt : ($x2 = $xr2); } // coordinates for imagemap } else { $xt = $xr1; if (!$draw) { $xt + $lenfix > $xr2 ? $x2 = $xt + $lenfix : ($x2 = $xr2); } // coordinates for imagemap } // draw text if ($draw) { ImageString($img, $this->fixfont, $xt, $yr1, $str, $text_color); } } // save coordinates if (!$draw) { $xt < $xr1 ? $x1 = $xt : ($x1 = $xr1); $img_map[$i]['jobid'] = $this->atime[$i]['jobid']; $img_map[$i]['name'] = $this->atime[$i]['name']; $img_map[$i]['short_desc'] = $this->atime[$i]['short_desc']; $img_map[$i]['x1'] = $x1; $img_map[$i]['y1'] = $yr1; $img_map[$i]['x2'] = $x2; $img_map[$i]['y2'] = $yr2; } $yt = $yt + $this->bar_height + $this->bar_space; } if ($draw) { return $img; } else { return $img_map; } }
function Text($xpos, $ypos, $color, $text, $max_length = NULL, $angle = NULL) { global $cfg; if ($max_length > 4) { if (strlen($text) > $max_length) { $text = substr($text, 0, $max_length - 3) . "..."; } } if ($angle == "") { $angle = 0; } if ($this->free_type) { ImageTtfText($this->img, $this->font_size, $angle, $xpos, $ypos + $this->font_size, $color, $this->font, $text); } else { $ypos = $ypos - 3; $text_parts = split("\r\n", $text); $i = 0; while (list($key, $val) = each($text_parts)) { ImageString($this->img, 2, $xpos, $ypos + $i, $val, $color); $i += $this->font_size + 2; } } }
/** * Функция наложения водяного текстового знака на изображение * * @return bool */ static function textWatermark() { // текст водяного знака $text = CONF_FILES_IMG_WATERMARK_TEXT; // файл шрифта $font = 'core/fonts/' . CONF_FILES_IMG_WATERMARK_FONT; if (!@file_exists($font)) { self::setError(ERROR_FILE_NOT_FOUND_FONT); return false; } // Если кодировка не windows-1251 преобразовуем текст в юникод if (strtolower(CONF_DEFAULT_CHARSET) === 'windows-1251') { $text = strings::WinToUtf8($text); //$text = strings::Utf8ToWin($text); } // создем дескриптор изображения if (!($resImg = self::createImgFromFile())) { self::setError(ERROR_FILE_CREATE_WATERMARK); return false; } // получаем обрамляющий бокс водяного знака $wmBox = @ImageTtfbBox(CONF_FILES_IMG_WATERMARK_FONT_SIZE, 0, $font, $text); // получаем размеры загруженного изображения и размер водяного знака $srcWidth = @ImageSX($resImg); $srcHeight = @ImageSY($resImg); $wmWidth = abs($wmBox[2]); $wmHeight = abs($wmBox[5]); // если водяной знак больше изображения, оставляем без водяного знака if ($srcWidth < $wmWidth) { return true; } // определяем координаты размещения водяного знака $margin = 10; $alignment = explode(':', CONF_FILES_IMG_WATERMARK_ALIGNMENT); // если вдруг расположение получено не правильно, устанавливаем значение по дефолту if (count($alignment) != 2) { $alignment = array(0 => 'L', 1 => 'B'); } // определяем координату X switch ($alignment[0]) { case 'L': default: $x = $margin; break; case 'C': $x = (int) abs($srcWidth / 2 - $wmWidth / 2 + $margin); break; case 'R': $x = (int) abs($srcWidth - $wmWidth - $margin); break; } // определяем координату Y switch ($alignment[1]) { case 'T': default: $y = $margin + 30; break; case 'M': $y = (int) abs($srcHeight / 2 - $wmHeight / 2 + $margin); break; case 'B': default: $y = (int) abs($srcHeight - $wmHeight - $margin); break; } // определяем цвет текста $rgb = strings::colorHexToDec(CONF_FILES_IMG_WATERMARK_FONT_COLOR); $txt_color = ImageColorAllocateAlpha($resImg, $rgb[0], $rgb[1], $rgb[2], CONF_FILES_IMG_WATERMARK_TRANSPARENT); // накладываем водяную марку на изображение @ImageTtfText($resImg, CONF_FILES_IMG_WATERMARK_FONT_SIZE, 0, $x, $y, $txt_color, $font, $text); // сохраняем результат в файл if (!self::saveImgToFile($resImg, self::$arrImgSubj['full_path'])) { self::setError(ERROR_FILE_CREATE_WATERMARK); return false; } // уничтожаем дескриптор @ImageDestroy($resImg); return true; }
function imggd($ust) { /* Function by piotrek-d1 e-mail:piotrek-d1@o2.pl */ //---------USTAWIENIA-POCZATEK--------- $folder = "../upload/gift/"; //Adres folderu z fotkami $xd = $ust['fotd']; //Maksymalna szerokosc duzej fotki $s_min = $ust['fotm']; //Szerokosc miniaturki $m_jakos = $ust['fotmj']; //Jakos miniaturki $d_jakos = $ust['fotdj']; //Jakos duzej fotki $m_przed = "m_"; //Przedrostek miniaturek $d_przed = "d_"; //Przedrostek duzych //Kolor tekstu $c_r = "41"; //RED $c_g = "123"; //GREN $c_b = "190"; //BLUE $font = "include/font/arial.ttf"; //Czcionka $tekst = ""; //Tekst na obrazku $txt_size = "20"; //Wielkosc napisu $txt_on = "0"; //Napis naobrazku ON=1 OFF=0 //---------USTAWIENIA-KONIEC--------- $plik_tmp = $_FILES['plik1']['tmp_name']; $plik_nazwa = $_FILES['plik1']['name']; $plik_rozmiar = $_FILES['plik1']['size']; $sp = explode(".", $plik_nazwa); //wyciaganie rozszerzenia srand(); $l = rand(10, 255); // Losowanie Liczby $name2x = time() * $l; //Generowanie Nazwy czas * liczba $namenowa = "{$name2x}.{$sp['1']}"; //Nowa nazwa z rozszerzeniem //Upload fotek if (is_uploaded_file($plik_tmp)) { move_uploaded_file($plik_tmp, "" . $folder . "d_" . $namenowa . ""); chmod("" . $folder . "d_" . $namenowa . "", 0644); } else { $upif = 1; } //---------POCZATEK-JPG--------- if ($sp[1] == "jpg" or $sp[1] == "jpeg" or $sp[1] == "JPG" or $sp[1] == "JPEG") { header("Content-type: image/jpeg"); $org = imagecreatefromjpeg("" . $folder . "" . $d_przed . "" . $namenowa . ""); $s_org = imagesx($org); $w_org = imagesy($org); if (($w_min = floor($s_min * $w_org / $s_org)) > 150) { $w_min = 150; } $min = ImageCreateTrueColor($s_min, $w_min); imagecopyresampled($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org); imagejpeg($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagejpeg($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagejpeg($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { if ($sp[1] == "gif" or $sp[1] == "GIF") { header("Content-type: image/gif"); $org = imagecreatefromgif("" . $folder . "" . $d_przed . "" . $namenowa . ""); $s_org = imagesx($org); $w_org = imagesy($org); if (($w_min = floor($s_min * $w_org / $s_org)) > 150) { $w_big = 150; } $min = ImageCreateTrueColor($s_min, $w_min); imagecopyresampled($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org); imagegif($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagegif($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagegif($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { if ($sp[1] == "png" or $sp[1] == "PNG") { header("Content-type: image/png"); $org = imagecreatefrompng("" . $folder . "" . $d_przed . "" . $namenowa . ""); $s_org = imagesx($org); $w_org = imagesy($org); if (($w_min = floor($s_min * $w_org / $s_org)) > 150) { $w_big = 150; } $min = ImageCreateTrueColor($s_min, $w_min); imagecopyresampled($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org); imagepng($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagepng($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagepng($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { header("Location: " . $ust['adres'] . "admin/index.php?page=galerie&e=error_typ"); } } } $fotm = "" . $m_przed . "" . $namenowa . ""; $fotd = $d_przed . "" . $namenowa; return $fotm; }
function pie($var) { $val = explode(",", $var["values"]); $desc = explode(",", $var["labels"]); $sum = array_sum($val); $count = count($val); $width = 200; $padding = 15; $max_width = 400; $height = $width * 0.5; $text_height = $count * 20; if ($height < $text_height) { $height = $text_height; if ($height > $max_width) { $center_y = $height / 2 + $padding; $height = $max_width; } $width = $height * (1 + (1 - ($height - $width / 2) / ($max_width - $width / 2))); } else { $text_height = $height; } $think = ($width - $height) * 30 / $width; $center_x = $width / 2 + $padding + 0.5; $center_y = $text_height / 2 + $padding + 0.5; $img = imagecreate($width + $padding * 2 + 300, $text_height + $think + $padding * 2); $bg = ImageColorAllocate($img, 255, 255, 255); ImageColorTransparent($img, $bg); $white = ImageColorAllocate($img, 255, 255, 255); $black = ImageColorAllocate($img, 0, 0, 0); $blue = ImageColorAllocate($img, 0, 255, 0); ImageArc($img, $center_x, $center_y, $width, $height, 180, 360, $white); ImageArc($img, $center_x, $center_y + $think, $width, $height, 0, 180, $white); ImageLine($img, $center_x - $width / 2, $center_y, $center_x - $width / 2, $center_y + $think, $white); ImageLine($img, $center_x + $width / 2, $center_y, $center_x + $width / 2, $center_y + $think, $white); $i = 0; $c = 0; ImageLine($img, $center_x, $center_y, $center_x + $width / 2, $center_y, $black); $p_c = array(); $p_x = array(); $p_y = array(); $p_a = array(); foreach ($val as $v) { $p = $v / $sum; $t = $p * pi() + $c; $c += $p * pi() * 2; $y1 = sin($c) * $height / 2 + $center_y; $x1 = cos($c) * $width / 2 + $center_x; $r = 255; $g = 80; $b = 80; $a = ++$i / $count; getColor($a, $r, $g, $b); $x = cos($t) * $width / 3.5 + $center_x; $y = sin($t) * $height / 3.5 + $center_y; $item = array(); $item["r"] = $r; $item["g"] = $g; $item["b"] = $b; $item["x"] = $x1; $item["y"] = $y1; array_push($p_c, $item); array_push($p_x, $x); array_push($p_y, $y); array_push($p_a, round($p * 100, 2)); if ($p > 0.01) { $color = ImageColorAllocate($img, round($r * 0.7), round($g * 0.7), round($b * 0.7)); //if($aaaaa<10) ImageFill($img, $x, $y, $white); //if($aaaaa<10) ImageFill($img, $x, $y, $color); if ($i != $count) { ImageSetPixel($img, $center_x + 1, $center_y, $white); ImageLine($img, $center_x, $center_y, $x1, $y1, $white); if ($y1 > $center_y) { ImageLine($img, $x1, $y1, $x1, $y1 + $think - 1, $white); } } else { ImageLine($img, $center_x, $center_y, $x1, $y1, $color); } } } ImageArc($img, $center_x, $center_y, $width, $height, 180, 360, $white); ImageArc($img, $center_x, $center_y, $width, $height, 0, 180, $white); ImageFillToBorder($img, $center_x, $center_y, $white, $white); ImageLine($img, $center_x, $center_y, $center_x + $width / 2, $center_y, $black); foreach ($p_c as $key => $item) { $x = $p_x[$key]; $y = $p_y[$key]; if ($p_a[$key] > 1) { $color = ImageColorAllocate($img, $item['r'], $item['g'], $item['b']); ImageFill($img, $x, $y, $white); ImageFill($img, $x, $y, $color); if ($key != $count - 1) { ImageSetPixel($img, $center_x + 1, $center_y, $white); ImageLine($img, $center_x, $center_y, $item['x'], $item['y'], $white); } else { ImageLine($img, $center_x, $center_y, $item['x'], $item['y'], $color); } } } array_multisort($p_y, $p_x, $p_c, $p_a, $val, $desc); $i = 0; foreach ($p_y as $k => $y) { $x = $p_x[$k]; $y2 = $i++ * 20 + $padding + $think / 2; $x2 = abs($y - $y2) + $x; $x3 = $center_x + $width / 2 + $padding; $a = $p_a[$k]; if ($a < 10) { $a = " " . $a; } if (strlen($a) < 3) { $a .= "."; } if (strlen($a) < 4) { $a .= "0"; } if (strlen($a) < 5) { $a .= "0"; } $a = $a . "%"; ImageLine($img, $x, $y, $x2, $y2, $black); ImageLine($img, $x2, $y2, $x3, $y2, $black); ImageTtfText($img, 10, 0, $x3 + $padding, $y2 + 5, $black, "cour.ttf", $a); ImageTtfText($img, 10, 0, $x3 + $padding + 60, $y2 + 5, $black, "simsun.ttc", $desc[$k]); } ImagePNG($img); ImageDestroy($img); }
/** * 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); }
} return $phoneWithCode; } $length = strlen($_POST['userID']); $link = 'www.makeadiff.in/volunteer/' . $_POST['userID']; $frame = QRcode::text($link, false, QR_ECLEVEL_L, 4, 0); $qrcode = get_qrcode($frame); $idNumber = (string) $_POST['userID']; $idSixLength = appendZeros($idNumber, $length); //echo $idSixLength; ImageTtfText($im, 13, 0, 15, 343, $black, "fonts/BebasNeue-webfont.ttf", $_POST['Post']); ImageTtfText($im, 15, 0, 48, 382, $black, "fonts/univers.ttf", $phoneNumberAppended); ImageTtfText($im, 15, 0, 48, 410, $black, "fonts/univers.ttf", $_POST['Email']); ImageTtfText($im, 13, 0, 637, 324, $madRed, "fonts/BebasNeue-webfont.ttf", "MAD ID : "); ImageTtfText($im, 13, 0, 682, 324, $madRed, "fonts/BebasNeue-webfont.ttf", $idSixLength); ImageTtfText($im, 15, 0, 48, 432, $black, "fonts/univers.ttf", $link); imagecopyresampled($im, $qrcode, 637, 336, 0, 0, 90, 90, 100, 100); /* Parameters 1. Final Image 2. Sampled Image 3. Start X 4. Start Y 5. Source X Point 6. Source Y Point 7. Image Width 8. Image Height 9. Source Width 10. Source Height */ header('Content-Disposition: attachment; filename=' . $_POST['Name'] . ' Card.png');
function imggda($ust) { $folder = "upload/zdjecia/"; //Adres folderu z fotkami $xd = 600; //Maksymalna szerokosc duzej fotki $s_min = 110; //Szerokosc miniaturki $m_jakos = 100; //Jakosc miniaturki $d_jakos = 100; //Jakosc duzej fotki $m_przed = "m_"; //Przedrostek miniaturek $d_przed = "d_"; //Przedrostek duzych //Kolor tekstu $c_r = $ust['tekst_r']; //RED $c_g = $ust['tekst_g']; //GREN $c_b = $ust['tekst_b']; //BLUE $font = "include/font/arial.ttf"; //Czcionka $tekst = $ust['tekst']; //Tekst na obrazku $txt_size = "10"; //Wielkosc napisu $txt_on = "0"; //Napis naobrazku ON=1 OFF=0 //---------USTAWIENIA-KONIEC--------- $plik_tmp = $_FILES['plik1']['tmp_name']; $plik_typ = $_FILES['plik1']['type']; $plik_nazwa = $_FILES['plik1']['name']; $plik_rozmiar = $_FILES['plik1']['size']; $pp_ust = $ust['max_file_size'] * 1024 * 1024; if ($pp_ust <= $plik_rozmiar) { header("Location: " . $ust['adres'] . "user/moje-zdjecia/21"); exit; } if ($plik_tmp != "") { $name2x = gen_kod(15); $namenowa = $name2x . ".jpg"; //Nowa nazwa z rozszerzeniem if ($plik_typ == "image/jpeg" or $plik_typ == "image/gif" or $plik_typ == "image/png") { if (is_uploaded_file($plik_tmp)) { move_uploaded_file($plik_tmp, "" . $folder . "" . $d_przed . "" . $namenowa . ""); chmod("" . $folder . "d_" . $namenowa . "", 0644); } if ($plik_typ == "image/jpeg") { $org = imagecreatefromjpeg("" . $folder . "" . $d_przed . "" . $namenowa . ""); } else { if ($plik_typ == "image/gif") { $org = imagecreatefromgif("" . $folder . "" . $d_przed . "" . $namenowa . ""); } else { if ($plik_typ == "image/png") { $org = imagecreatefrompng("" . $folder . "" . $d_przed . "" . $namenowa . ""); } } } $s_org = imagesx($org); $w_org = imagesy($org); $min = imagecreatetruecolor($s_min, $s_min); if ($s_org == $w_org) { $nmin = $org; $ms_org = $s_org; $mw_org = $w_org; } else { if ($w_org > $s_org) { $orgm = $org; $nmin = imagecreatetruecolor($s_org, $s_org); imagecopy($nmin, $orgm, 0, 0, 0, 0, $s_org, $s_org); $ms_org = imagesx($nmin); $mw_org = imagesy($nmin); } else { $orgm = $org; $nmin = imagecreatetruecolor($w_org, $w_org); $d = $s_org - $w_org; $d = floor($d / 2); imagecopy($nmin, $orgm, 0, 0, $d, 0, $w_org, $w_org); $ms_org = imagesx($nmin); $mw_org = imagesy($nmin); } } imagecopyresampled($min, $nmin, 0, 0, 0, 0, $s_min, $s_min, $ms_org, $mw_org); imagejpeg($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagejpeg($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagejpeg($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { header("Location: " . $ust['adres'] . "user/moje-zdjecia/6"); exit; } $fotm = $name2x . ".jpg"; return $fotm; } }
function imggd3($cat, $ust, $pre) { /* Function by piotrek-d1 e-mail:piotrek-d1@o2.pl */ //---------USTAWIENIA-POCZATEK--------- $folder = "../upload/img/"; //Adres folderu z fotkami $xd = $ust['fotd']; //Maksymalna szerokosc duzej fotki $s_min = $ust['fotm']; //Szerokosc miniaturki $m_jakos = $ust['fotmj']; //Jakos miniaturki $d_jakos = $ust['fotdj']; //Jakos duzej fotki $m_przed = "m_"; //Przedrostek miniaturek $d_przed = "d_"; //Przedrostek duzych //Kolor tekstu $c_r = $ust['tekst_r']; //RED $c_g = $ust['tekst_g']; //GREN $c_b = $ust['tekst_b']; //BLUE $font = "include/font/arial.ttf"; //Czcionka $tekst = $ust['tekst']; //Tekst na obrazku $txt_size = $ust['tekst_size']; //Wielkosc napisu $txt_on = $ust['tekst_on']; //Napis naobrazku ON=1 OFF=0 //---------USTAWIENIA-KONIEC--------- $plik_tmp = $_FILES['plik3']['tmp_name']; $plik_nazwa = $_FILES['plik3']['name']; $plik_rozmiar = $_FILES['plik3']['size']; if ($plik_tmp != "") { $sp = explode(".", $plik_nazwa); //wyciaganie rozszerzenia srand(); $l = rand(100, 999); // Losowanie Liczby $name2x = time() * $l; //Generowanie Nazwy czas * liczba $namenowa = "{$name2x}.{$sp['1']}"; //Nowa nazwa z rozszerzeniem //Upload fotek if (is_uploaded_file($plik_tmp)) { move_uploaded_file($plik_tmp, "" . $folder . "d_" . $namenowa . ""); chmod("" . $folder . "d_" . $namenowa . "", 0644); } //---------POCZATEK-JPG--------- if ($sp[1] == "jpg" or $sp[1] == "jpeg" or $sp[1] == "JPG" or $sp[1] == "JPEG") { header("Content-type: image/jpeg"); $org = imagecreatefromjpeg("" . $folder . "" . $d_przed . "" . $namenowa . ""); $s_org = imagesx($org); $w_org = imagesy($org); if (($w_min = floor($s_min * $w_org / $s_org)) > 150) { $w_min = 150; } $min = ImageCreateTrueColor($s_min, $w_min); imagecopyresampled($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org); imagejpeg($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagejpeg($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagejpeg($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { if ($sp[1] == "gif" or $sp[1] == "GIF") { header("Content-type: image/gif"); $org = imagecreatefromgif("" . $folder . "" . $d_przed . "" . $namenowa . ""); $s_org = imagesx($org); $w_org = imagesy($org); if (($w_min = floor($s_min * $w_org / $s_org)) > 150) { $w_big = 150; } $min = ImageCreateTrueColor($s_min, $w_min); imagecopyresampled($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org); imagegif($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagegif($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagegif($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { if ($sp[1] == "png" or $sp[1] == "PNG") { header("Content-type: image/png"); $org = imagecreatefrompng("" . $folder . "" . $d_przed . "" . $namenowa . ""); $s_org = imagesx($org); $w_org = imagesy($org); if (($w_min = floor($s_min * $w_org / $s_org)) > 150) { $w_big = 150; } $min = ImageCreateTrueColor($s_min, $w_min); imagecopyresampled($min, $org, 0, 0, 0, 0, $s_min, $w_min, $s_org, $w_org); imagepng($min, "" . $folder . "" . $m_przed . "" . $namenowa . "", $m_jakos); if ($s_org >= $xd + 1) { if (($w_big = floor($xd * $w_org / $s_org)) > 648) { $w_big = 648; } $big = ImageCreateTrueColor($xd, $w_big); imagecopyresampled($big, $org, 0, 0, 0, 0, $xd, $w_big, $s_org, $w_org); if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($big, $c_r, $c_g, $c_b); ImageTtfText($big, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagepng($big, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } else { if ($txt_on == 1) { $txt_kolor = ImageColorAllocate($org, $c_r, $c_g, $c_b); ImageTtfText($org, $txt_size, 0, 10, $txt_size + 10, $txt_kolor, $font, $tekst); } imagepng($org, "" . $folder . "" . $d_przed . "" . $namenowa . "", $d_jakos); } } else { echo 's'; } } } $fotm = $m_przed . "" . $namenowa; $fotd = $d_przed . "" . $namenowa; if ($s_org >= $xd + 1) { $wi = $xd; $hi = imagesy($big); } else { $wi = $s_org; $hi = $w_org; } $in = "INSERT INTO " . $pre . "img(`img_cat`, `img_fm`, `img_fd`, `img_data`)VALUE('" . $cat . "', '" . $fotm . "', '" . $fotd . "', NOW())"; db_query($in); $up = "UPDATE " . $pre . "gallery SET ga_ilef=ga_ilef+1 WHERE ga_id='" . db_real_escape_string($cat) . "'"; db_query($up); } }
/** * create image and draw string using GD * * @author Won-Kyu Park <*****@*****.**> * @since 2013/12/24 * @license GPLv2 */ function image_msg($font_size, $font_face, $text, $width = 40) { $wrap = wordwrap($text, $width, "\n", true); $wrap = rtrim($wrap); $strs = explode("\n", $wrap); if (empty($font_face)) { $w = imagefontwidth($font_size) * $width; $dy = imagefontheight($font_size); $h = $dy * count($strs); $im = ImageCreate($w, $h); $y = 0; } else { putenv('GDFONTPATH=' . getcwd() . '/data'); $w = 0; $h = 0; foreach ($strs as $str) { $bbox = imagettfbbox($font_size, 0, $font_face, $str); if ($bbox[2] > $w) { $w = $bbox[2]; } $h += $bbox[3] - $bbox[5]; } $dy = $bbox[3] - $bbox[5]; $h = $dy * count($strs); $im = ImageCreateTruecolor($w, $h); $y = $dy; } $bg = ImageColorAllocate($im, 255, 255, 255); // white background $pen = ImageColorAllocate($im, 0, 0, 0); // black imagefill($im, 0, 0, $bg); foreach ($strs as $str) { if (empty($font_face)) { ImageString($im, $font_size, 0, $y, $str, 1); } else { ImageTtfText($im, $font_size, 0, 0, $y, $pen, $font_face, $str); } $y += $dy; } return $im; }
$_SESSION['token'] = $l; $code = '' . $l . ''; $size_x = 130; $size_y = 30; $space_per_char = $size_x / (strlen($code) + 1); $img = ImageCreateTrueColor($size_x, $size_y); $background = ImageColorAllocate($img, 255, 255, 255); $border = ImageColorAllocate($img, 255, 255, 255); $colors[] = ImageColorAllocate($img, 34, 64, 92); $colors[] = ImageColorAllocate($img, 192, 64, 128); $colors[] = ImageColorAllocate($img, 110, 102, 104); ImageFilledrectangle($img, 1, 1, $size_x - 2, $size_y - 2, $background); ImageRectangle($img, 0, 0, $size_x - 1, $size_y - 1, $border); for ($i = 0; $i < strlen($code); $i++) { $color = $colors[$i % count($colors)]; ImageTtfText($img, 12 + rand(6, 12), -20 + rand(0, 45), ($i + 0.3) * $space_per_char, 27 + rand(0, 5), $color, '../include/font/arial.ttf', $code[$i]); } /* ImageAntialias($img,true); for($i=0; $i<300; $i++) { $x1=rand(3,$size_x-3); $y1=rand(3,$size_y-3); $x2=$x1-8+rand(0,12); $y2=$y1-8+rand(0,12); ImageLine($img, $x1, $y1, $x2, $y2, $colors[rand(0,count($colors)-1)]); } */ Header('Content-type: image/jpeg'); ImageJpeg($img); ImageDestroy($img);