public static function write($image, $fontfile, $x, $y, $text, $color, $maxwidth, $size = 11, $spacingx = 2, $spacingy = 2, $mx = 1, $my = 1, $angle = 0) { if (!Common::isFile($fontfile)) { echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array(htmlspecialchars($fontfile))); return false; } $dim = GWF_GDText::getFontSize($fontfile, $size, $angle); $fontwidth = $dim->w; $fontheight = $dim->h; if ($maxwidth != NULL) { // die(''.$maxwidth); $maxcharsperline = floor($maxwidth / $fontwidth); $text = wordwrap($text, $maxcharsperline, "\n", 1); // die($text); } // die(var_dump($color)); $lines = explode("\n", $text); $x += $mx; $y += $my; foreach ($lines as $line) { $y += $fontheight + $spacingy; imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $line); } return true; }
private function displayBanner(GWF_User $user, $format = self::FORMAT, $bg = self::BGCOLOR, $fg = self::FGCOLOR, $size, $spacingx = 1, $spacingy = 1, $mx, $my, $divider) { $this->box_logo = new GWF_GDRect(); $this->box_stats = new GWF_GDRect(0, 0, self::WIDTH, self::HEIGHT); $this->box_avatar = new GWF_GDRect(); // echo $this->box_stats->toString().PHP_EOL; # Image if (false === ($image = imagecreatetruecolor(self::WIDTH, self::HEIGHT))) { echo GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); return false; } # Colors $bg = GWF_GDColor::fromHTML($image, $bg); $fg = GWF_GDColor::fromHTML($image, $fg); # BG imagefilledrectangle($image, 0, 0, self::WIDTH, self::HEIGHT, $bg); $format2 = ''; for ($i = 0; $i < strlen($format); $i++) { $c = $format[$i]; $pos = $this->parsePos($format, $i); switch ($c) { case 'L': $this->copyLogo($image, $pos); break; case 'A': $this->copyAvatar($image, $user, $pos); break; case 'S': $this->copySites($image); break; default: $format2 .= $c; break; } } // echo $this->box_stats->toString().PHP_EOL; $text = ''; for ($i = 0; $i < strlen($format2); $i++) { $c = $format2[$i]; switch ($c) { case 'U': $text .= $divider . $user->getVar('user_name'); break; case 'R': $text .= $divider . 'Registered: ' . GWF_Time::displayAge($user->getVar('user_regdate')); break; case 'T': $text .= $divider . $this->module->langUser($user, 'th_totalscore') . ': ' . $user->getVar('user_level'); break; case 'G': $text .= $divider . $this->module->langUser($user, 'th_rank2') . ': ' . WC_RegAt::calcExactRank($user); break; case 'C': $text .= $divider . $this->module->langUser($user, 'th_crank') . ': ' . WC_RegAt::calcExactCountryRank($user); break; case 'X': $text .= $divider . $this->getSignature($user); break; } } // die($this->getFontPath()); $text = substr($text, strlen($divider)); if (!GWF_GDText::write($image, $this->getFontPath(), $this->box_stats->x, $this->box_stats->y, $text, $fg, $this->box_stats->w, $size, $spacingx, $spacingy, $mx, $my)) { return false; } // die(); # Output header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); }