本文整理汇总了PHP中ImageFontWidth函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageFontWidth函数的具体用法?PHP ImageFontWidth怎么用?PHP ImageFontWidth使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageFontWidth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gd_button
function gd_button()
{
if (file_exists($this->save_dir . $this->filename)) {
return $this->filename;
}
$this->font_size = 5;
$text_width = ImageFontWidth($this->font_size) * strlen($this->font_text);
$text_height = ImageFontHeight($this->font_size);
$this->width = $this->xspace * 2 + $text_width;
$this->height = $this->yspace + $text_height;
$this->xpos = $this->width / 2 - $text_width / 2;
if ($this->xpos < 0) {
$this->xpos = $this->xspace;
}
$this->ypos = $this->height / 2 - $text_height / 2;
if ($this->ypos < 0) {
$this->ypos = $this->yspace;
}
$this->button_init();
$black = ImageColorAllocate($this->image, 0, 0, 0);
ImageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $black);
$white = ImageColorAllocate($this->image, 255, 255, 255);
ImageRectangle($this->image, 0, 0, $this->width, $this->height, $white);
ImageString($this->image, $this->font_size, intval($this->xpos + 1), intval($this->ypos), $this->font_text, $black);
ImageString($this->image, $this->font_size, intval($this->xpos), intval($this->ypos - 1), $this->font_text, $white);
return $this->save_button();
}
示例2: ConvertToImage
function ConvertToImage($content)
{
$imageFile = ".counter.png";
$relativePath = ".counter.png";
$noOfChars = strlen($content);
$charHeight = ImageFontHeight(5);
$charWidth = ImageFontWidth(5);
$strWidth = $charWidth * $noOfChars;
$strHeight = $charHeight;
//15 padding
$imgWidth = $strWidth + 15;
$imgHeight = $strHeight + 15;
$imgCenterX = $imgWidth / 2;
$imgCenterY = $imgHeight / 2;
$im = ImageCreate($imgWidth, $imgHeight);
$script = ImageColorAllocate($im, 0, 255, 0);
$outercolor = ImageColorAllocate($im, 99, 140, 214);
$innercolor = ImageColorAllocate($im, 0, 0, 0);
ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor);
ImageFilledRectangle($im, 3, 3, $imgWidth - 4, $imgHeight - 4, $innercolor);
//draw string
$drawPosX = $imgCenterX - $strWidth / 2 + 1;
$drawPosY = $imgCenterY - $strHeight / 2;
ImageString($im, 5, $drawPosX, $drawPosY, $content, $script);
//save image and return
ImagePNG($im, $imageFile);
return $relativePath;
}
示例3: generateImage
function generateImage($token)
{
$iFont = 5;
// Font ID
$iSpacing = 2;
// Spacing between characters
$iDisplacement = 5;
// Vertical chracter displacement
// Establish font metric and image size
$iCharWidth = ImageFontWidth($iFont);
$iCharHeight = ImageFontHeight($iFont);
$iWidth = strlen($token) * ($iCharWidth + $iSpacing);
$iHeight = $iCharHeight + 2 * $iDisplacement;
// Create the image
$pic = ImageCreate($iWidth, $iHeight);
// Allocate a background and foreground colour
$col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200));
for ($x = 0; $x < $iWidth; $x += 2) {
for ($y = 0; $y < $iHeight; $y += 2) {
ImageSetPixel($pic, $x, $y, $col['grey']);
}
}
$iX = 1;
for ($i = 0; $i < strlen($token); $i++) {
ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']);
$iX += $iCharWidth + $iSpacing;
}
$iX = 2;
$c = array('blue', 'green', 'red', 'purple');
for ($i = 0; $i < strlen($token); $i++) {
$colour = $c[rand(0, count($c) - 1)];
ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]);
$iX += $iCharWidth + $iSpacing;
}
for ($x = 1; $x < $iWidth; $x += 4) {
for ($y = 1; $y < $iHeight; $y += 4) {
ImageSetPixel($pic, $x, $y, $col['white']);
}
}
// Draw some lines
for ($i = 0; $i < 4; $i++) {
ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']);
}
ob_start();
if (function_exists('imagejpeg')) {
ImageJPEG($pic);
} elseif (function_exists('imagepng')) {
ImagePNG($pic);
} else {
ob_end_clean();
return false;
}
$data = ob_get_contents();
ob_end_clean();
ImageDestroy($pic);
return $data;
}
示例4: image_create
function image_create($image, $size, $x, $y, $text, $color, $maxwidth)
{
$fontwidth = ImageFontWidth($size);
$fontheight = ImageFontHeight($size);
if ($maxwidth != NULL) {
$maxchar = floor($maxwidth / $fontwidth);
$text = wordwrap($text, $maxchar, "\n", 1);
}
$lines = explode("\n", $text);
while (list($numl, $line) = each($lines)) {
ImageString($image, $size, $x, $y, $line, $color);
$y += $fontheight;
}
}
示例5: render_png
function render_png($string, $hash)
{
$font = 4;
$width = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);
$im = @imagecreate($width, $height);
$background_color = imagecolorallocate($im, 255, 255, 255);
//white background
$text_color = imagecolorallocate($im, 0, 0, 0);
//black text
imagecolortransparent($im, $background_color);
imagestring($im, $font, 0, 0, $string, $text_color);
$pngdata = imagepng($im, $this->CACHE_DIR . "/{$hash}.png");
chdir($current_dir);
}
示例6: fatal_error
function fatal_error($message)
{
// send an image
if (function_exists('ImageCreate')) {
$width = ImageFontWidth(5) * strlen($message) + 10;
$height = ImageFontHeight(5) + 10;
if ($image = ImageCreate($width, $height)) {
$background = ImageColorAllocate($image, 255, 255, 255);
$text_color = ImageColorAllocate($image, 0, 0, 0);
ImageString($image, 5, 5, 5, $message, $text_color);
header('Content-type: image/png');
ImagePNG($image);
ImageDestroy($image);
exit;
}
}
// send 500 code
header("HTTP/1.0 500 Internal Server Error");
print $message;
exit;
}
示例7: ts_gfx
function ts_gfx($ts_random)
{
global $site_key;
$datekey = date("F j");
$rcode = hexdec(md5($_SERVER[HTTP_USER_AGENT] . $sitekey . $ts_random . $datekey));
$code = substr($rcode, 2, 6);
$circles = 5;
$lines = 1;
$width = 100;
$height = 40;
$font = 5;
$fontwidth = ImageFontWidth($font) * strlen($string);
$fontheight = ImageFontHeight($font);
$im = @imagecreate($width, $height);
$background_color = imagecolorallocate($im, 255, 138, 0);
$text_color = imagecolorallocate($im, rand(200, 255), rand(200, 255), rand(200, 255));
// Random Text
#rgb(1%, 51%, 87%)
$r = 0.87;
$g = 0.51;
$b = 0.0;
for ($i = 1; $i <= $circles; $i++) {
$value = rand(200, 255);
$randomcolor = imagecolorallocate($im, $value * $r, $value * $g, $value * $b);
imagefilledellipse($im, rand(0, $width - 20), rand(0, $height - 6), rand(15, 70), rand(15, 70), $randomcolor);
}
imagerectangle($im, 0, 0, $width - 1, $height - 1, $text_color);
imagestring($im, $font, 22, 12, $code, $text_color);
for ($i = 0; $i < $lines; $i++) {
$y1 = rand(14, 23);
$y2 = rand(15, 24);
$randomcolor = imagecolorallocate($im, rand(100, 255), 0, rand(100, 255));
imageline($im, 0, $y1, $width, $y2, $randomcolor);
}
header("Content-type: image/jpeg");
imagejpeg($im, '', 85);
ImageDestroy($im);
die;
}
示例8: createImage
function createImage($text, $width, $height, $font = 5)
{
global $fontColor, $bgColor, $lineColor;
if ($img = @ImageCreate($width, $height)) {
list($R, $G, $B) = convertRGB($fontColor);
$fontColor = ImageColorAllocate($img, $R, $G, $B);
list($R, $G, $B) = convertRGB($bgColor);
$bgColor = ImageColorAllocate($img, $R, $G, $B);
list($R, $G, $B) = convertRGB($lineColor);
$lineColor = ImageColorAllocate($img, $R, $G, $B);
ImageFill($img, 0, 0, $bgColor);
for ($i = 0; $i <= $width; $i += 5) {
@ImageLine($img, $i, 0, $i, $height, $lineColor);
}
for ($i = 0; $i <= $height; $i += 5) {
@ImageLine($img, 0, $i, $width, $i, $lineColor);
}
$hcenter = $width / 2;
$vcenter = $height / 2;
$x = round($hcenter - ImageFontWidth($font) * strlen($text) / 2);
$y = round($vcenter - ImageFontHeight($font) / 2);
ImageString($img, $font, $x, $y, $text, $fontColor);
if (function_exists('ImagePNG')) {
header('Content-Type: image/png');
@ImagePNG($img);
} else {
if (function_exists('ImageGIF')) {
header('Content-Type: image/gif');
@ImageGIF($img);
} else {
if (function_exists('ImageJPEG')) {
header('Content-Type: image/jpeg');
@ImageJPEG($img);
}
}
}
ImageDestroy($img);
}
}
示例9: print_image
function print_image($text)
{
$w = 50;
$image = imagecreate($w, 25);
$light = ImageColorAllocate($image, 255, 255, 0);
$dark = ImageColorAllocate($image, 0, 0, 0);
$gray = ImageColorAllocate($image, 0, 0, 0);
ImageFill($image, 0, 0, $light);
$width_two = ImageFontWidth(5) * strlen($text);
$height = ImageFontHeight(100);
$width = ($w - $width_two) / 2;
# vertical lines
for ($x = 0; $x <= 100; $x += 10) {
ImageLine($image, $x, 0, $x, 100, $dark);
}
# horizontal lines
for ($x = 0; $x <= 100; $x += 10) {
ImageLine($image, 0, $x, 100, $x, $dark);
}
ImageString($image, 5, $width, 4, $text, $dark);
ImagePNG($image, '', 80);
ImageDestroy($image);
}
示例10: SetFontGD
function SetFontGD($which_elem, $which_font, $which_spacing = NULL)
{
if ($which_font < 1 || 5 < $which_font) {
return $this->PrintError(__FUNCTION__ . ': Font size must be 1, 2, 3, 4 or 5');
}
if (!$this->CheckOption($which_elem, 'generic, title, legend, x_label, y_label, x_title, y_title', __FUNCTION__)) {
return FALSE;
}
# Store the font parameters: name/size, char cell height and width.
$this->fonts[$which_elem] = array('ttf' => FALSE, 'font' => $which_font, 'height' => ImageFontHeight($which_font), 'width' => ImageFontWidth($which_font), 'line_spacing' => $which_spacing);
return TRUE;
}
示例11: WatermarkText
//.........这里部分代码省略.........
//$text_height = round($max_y - $min_y + ($size * 0.5));
$text_height_line = round($max_y_line - $min_y_line);
switch ($alignment) {
// $text_origin_y set above, just re-set $text_origin_x here as needed
case 'L':
case 'TL':
case 'BL':
// no change neccesary
break;
case 'C':
case 'T':
case 'B':
$text_origin_x = $originOffsetX ? $originOffsetX - round($text_width_line / 2) : round((ImageSX($gdimg) - $text_width_line) / 2);
break;
case 'R':
case 'TR':
case 'BR':
$text_origin_x = $originOffsetX ? $originOffsetX - $text_width_line : ImageSX($gdimg) - $text_width_line + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
break;
}
//ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
$this->DebugMessage('WatermarkText() calling ImageTTFtext($gdimg, ' . $size . ', ' . $angle . ', ' . $text_origin_x . ', ' . ($text_origin_y + $y_offset) . ', $letter_color_text, ' . $ttffont . ', ' . $line . ')', __FILE__, __LINE__);
ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $letter_color_text, $ttffont, $line);
$y_offset += $char_height;
}
}
return true;
} else {
$size = min(5, max(1, $size));
$this->DebugMessage('Using built-in font (size=' . $size . ') for text watermark' . ($ttffont ? ' because $ttffont !is_readable(' . $ttffont . ')' : ''), __FILE__, __LINE__);
$text_width = 0;
$text_height = 0;
foreach ($textlines as $dummy => $line) {
$text_width = max($text_width, ImageFontWidth($size) * strlen($line));
$text_height += ImageFontHeight($size);
}
if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
ImageAlphaBlending($img_watermark, false);
if (phpthumb_functions::IsHexColor($bg_color)) {
$text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
$text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, $bg_color, false, $text_background_alpha);
} else {
$text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, 'FFFFFF', false, 127);
}
$this->DebugMessage('WatermarkText() calling ImageFilledRectangle($img_watermark, 0, 0, ' . ImageSX($img_watermark) . ', ' . ImageSY($img_watermark) . ', $text_color_background)', __FILE__, __LINE__);
ImageFilledRectangle($img_watermark, 0, 0, ImageSX($img_watermark), ImageSY($img_watermark), $text_color_background);
if ($angle && function_exists('ImageRotate')) {
// using $img_watermark_mask is pointless if ImageRotate function isn't available
if ($img_watermark_mask = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
$mask_color_background = ImageColorAllocate($img_watermark_mask, 0, 0, 0);
ImageAlphaBlending($img_watermark_mask, false);
ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $mask_color_background);
$mask_color_watermark = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
}
}
$text_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
foreach ($textlines as $key => $line) {
switch ($alignment) {
case 'C':
$x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
$originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
break;
case 'T':
$x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
示例12: drawYLables
function drawYLables($image, $w, $h, $col, $top, $right, $left, $bottom, $max)
{
$gHeight = $h - ($top + $bottom);
$space = $gHeight / 4;
$y = $top;
$quater = round($max / 4, 0);
for ($a = 1; $a < 5; $a++) {
$len = strlen($max);
$width = ImageFontWidth(1) * $len;
ImageString($image, 0, 32 - $width, $y - 2, $max, $col);
$y = $y + $space;
$max = $max - $quater;
}
}
示例13: DrawXDataLabel
function DrawXDataLabel($xlab, $xpos)
{
//xpos comes in in PIXELS not in world coordinates.
//Draw an x data label centered at xlab
if ($this->use_ttf) {
$xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $xlab);
//An array
$y = $this->plot_area[3] + $xlab_size[1] + 4;
//in pixels
$x = $xpos - $xlab_size[0] / 2;
ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
} else {
$xlab_size = array(ImageFontWidth($this->axis_font) * StrLen($xlab), $this->small_font_height * 3);
if ($this->x_datalabel_angle == 90) {
$y = $this->plot_area[3] + ImageFontWidth($this->axis_font) * StrLen($xlab);
//in pixels
$x = $xpos - $this->small_font_height;
ImageStringUp($this->img, $this->axis_font, $x, $y, $xlab, $this->ndx_text_color);
} else {
$y = $this->plot_area[3] + ImageFontHeight($this->axis_font);
//in pixels
$x = $xpos - ImageFontWidth($this->axis_font) * StrLen($xlab) / 2;
ImageString($this->img, $this->axis_font, $x, $y, $xlab, $this->ndx_text_color);
}
}
}
示例14: textHeight
/**
* Get the height of a text.
*
* Note! This method can give some peculiar results, since ImageTTFBBox() returns the total
* bounding box of a text, where ImageTTF() writes the text on the baseline of the text, that
* is 'g', 'p', 'q' and other letters that dig under the baseline will appear to have a larger
* height than they actually do. Have a look at the tests/text.php test case - the first two
* columns, 'left and 'center', both look alright, whereas the last column, 'right', appear
* with a larger space between the first text and the second. This is because the total height
* is actually smaller by exactly the number of pixels that the 'g' digs under the baseline.
* Remove the 'g' from the text and they appear correct.
*
* @param string $text The text to get the height of
* @param bool $force Force the method to calculate the size
* @return int The height of the text
*/
function textHeight($text, $force = false)
{
if (isset($this->_font['file'])) {
$angle = 0;
if (isset($this->_font['angle'])) {
$angle = $this->_font['angle'];
}
$linebreaks = substr_count($text, "\n");
if ($angle == 0 && $force === false) {
/*
* if the angle is 0 simply return the size, due to different
* heights for example for x-axis labels, making the labels
* _not_ appear as written on the same baseline
*/
return $this->_font['size'] + ($this->_font['size'] + 2) * $linebreaks;
}
$height = 0;
$lines = explode("\n", $text);
foreach ($lines as $line) {
$bounds = ImageTTFBBox($this->_font['size'], $angle, $this->_font['file'], $line);
$y0 = min($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
$y1 = max($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
$height += abs($y0 - $y1);
}
return $height + $linebreaks * 2;
} else {
if (isset($this->_font['vertical']) && $this->_font['vertical']) {
$width = 0;
$lines = explode("\n", $text);
foreach ($lines as $line) {
$width = max($width, ImageFontWidth($this->_font['font']) * strlen($line));
}
return $width;
} else {
return ImageFontHeight($this->_font['font']) * (substr_count($text, "\n") + 1);
}
}
}
示例15: imagestring
imagestring($im, 2, $x1, $height - $space + 5, $lts[$i], $black);
}
$bar_width = ($width - $left_space - $space - 15) / $cols / $g < 10 ? ($width - $left_space - $space - 15) / $cols / $g - 1 : 10;
for ($n = 0; $n < $g; $n++) {
$ps = $_GET['ps' . ($n + 1)];
//点坐标
$pa = explode(',', $ps);
//点坐标数组
$cnt = count($pa);
$clr = isset($_GET['clr' . ($n + 1)]) ? $_GET['clr' . ($n + 1)] : '';
if ($clr != '') {
$ca = explode(',', $clr);
} else {
$ca = array(0, 0, 0);
}
$color = imagecolorallocate($im, $ca[0], $ca[1], $ca[2]);
for ($i = 0; $i < $cnt; $i++) {
$x1 = intval($left_space + ($width - $left_space - $space - 5) / $cols * $i) + $bar_width * $n + 1;
$y1 = intval($height - $space - ($pa[$i] - $rmi) / ($rma - $rmi) * ($height - 2 * $space - 5));
$x2 = $x1 + $bar_width;
$y2 = $height - $space - 1;
imagefilledrectangle($im, $x1, $y1, $x2, $y2, $color);
}
}
$wf5 = ImageFontWidth(5);
$t_len = $wf5 * strlen($title);
//echo $cw.' '.$ch;die();
imagestring($im, 5, $width / 2 - $t_len / 2, 5, $title, $black);
Header("Content-type: image/gif");
ImageGif($im);
ImageDestroy($im);