本文整理汇总了PHP中ImageString函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageString函数的具体用法?PHP ImageString怎么用?PHP ImageString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CenterImageString
function CenterImageString($image, $image_width, $string, $font_size, $y, $color)
{
$text_width = imagefontwidth($font_size) * strlen($string);
$center = ceil($image_width / 2);
$x = $center - ceil($text_width / 2);
ImageString($image, $font_size, $x, $y, $string, $color);
}
示例2: doWrite
function doWrite($item, $len = 6)
{
global $sx, $sy, $hdiv, $vdiv, $im, $pink, $black, $left_border, $top_border, $mark_v_offset, $ewhite, $dark_pink, $bgcolor, $purple;
// ImageFilledRectangle($im,($sx-$left_border),($sy-5),($sx+($hdiv*6)),($sy+5),$bgcolor);
ImageString($im, 1, $sx + 14, $sy, $item, $purple);
ImageLine($im, $sx - $left_border, $sy + 10, $sx + $hdiv * $len - 8, $sy + 10, $pink);
}
示例3: display
/**
* Generates a random captcha image
*
**/
function display($cachable = false, $urlparams = false)
{
// @TODO: Run some cleaning query here to clear the database.
JTable::addIncludePath(DISCUSS_TABLES);
$id = JRequest::getInt('captcha-id', '');
$captcha = DiscussHelper::getTable('Captcha');
// clearing the oudated keys.
$captcha->clear();
// load the captcha records.
$captcha->load($id);
if (!$captcha->id) {
return false;
}
// @task: Generate a very random integer and take only 5 chars max.
$hash = JString::substr(md5(rand(0, 9999)), 0, 5);
$captcha->response = $hash;
$captcha->store();
// Captcha width and height
$width = 100;
$height = 20;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$gray = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $white);
ImageString($image, 5, 30, 3, $hash, $black);
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
imageline($image, 0, $height / 2, $width, $height / 2, $gray);
imageline($image, $width / 2, 0, $width / 2, $height, $gray);
header('Content-type: image/jpeg');
ImageJpeg($image);
ImageDestroy($image);
exit;
}
示例4: draw_captcha
function draw_captcha($security_code)
{
//Set the image width and height
$width = 100;
$height = 25;
//Create the image resource
$image = ImageCreate($width, $height);
if (function_exists('imageantialias')) {
imageantialias($image, true);
}
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 15, 50, 15);
$grey = ImageColorAllocate($image, 204, 204, 204);
$ellipsec = ImageColorAllocate($image, 0, 100, 60);
//Make the background black
ImageFill($image, 0, 0, $black);
imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
//Add randomly generated string in white to the image
ImageString($image, 5, 30, 4, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
示例5: create_image
function create_image()
{
//Let's generate a totally random string using md5
$md5_hash = md5(rand(0, 999));
//We don't need a 32 character long string so we trim it down to 5
$security_code = substr($md5_hash, 15, 5);
//Set the session to store the security code
$_SESSION["captchaCode"] = $security_code;
//Set the image width and height
$width = 100;
$height = 20;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
//Make the background black
ImageFill($image, 0, 0, $black);
//Add randomly generated string in white to the image
ImageString($image, 3, 30, 3, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
imageline($image, 0, $height / 2, $width, $height / 2, $grey);
imageline($image, $width / 2, 0, $width / 2, $height, $grey);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
示例6: generate
/**
* Generates the captcha image
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function generate()
{
$id = $this->input->get('id', '', 'int');
// Load up the captcha object
$captcha = EB::table('Captcha');
// Clear outdated keys
$captcha->clear();
// load the captcha records.
$captcha->load($id);
if (!$captcha->id) {
return false;
}
// @task: Generate a very random integer and take only 5 chars max.
$hash = JString::substr(md5(rand(0, 9999)), 0, 5);
$captcha->response = $hash;
$captcha->store();
// Captcha width and height
$width = 100;
$height = 20;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$gray = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $white);
ImageString($image, 5, 30, 3, $hash, $black);
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
imageline($image, 0, $height / 2, $width, $height / 2, $gray);
imageline($image, $width / 2, 0, $width / 2, $height, $gray);
header('Content-type: image/jpeg');
ImageJpeg($image);
ImageDestroy($image);
exit;
}
示例7: create_image
function create_image()
{
//generate a random string
$md5_hash = md5(rand(0, 999));
//make it 5 characters long
$security_code = substr($md5_hash, 15, 5);
//Storing the security code in the session
$_SESSION["security_code"] = $security_code;
//Create the image
$image = @imagecreatefromjpeg("images/static.jpg");
//Making the font color
$black = ImageColorAllocate($image, 0, 0, 0);
//Make the background black
//ImageFill($image, 0, 0, $bgImg);
//Set some variables for positioning and font-size, "5" is the largest I could get to work
$vPos = 10;
$hPos = 28;
$fontSize = 5;
ImageString($image, $fontSize, $hPos, $vPos, $security_code, $black);
//Tell the browser what kind of file this is
header("Content-Type: image/jpeg");
//Output image as a jpeg
ImageJpeg($image);
//Free up stuff
ImageDestroy($image);
}
示例8: 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();
}
示例9: create_image
function create_image($string_captcha, $width = 130, $height = 35)
{
//Let's generate a totally random string using md5
// $md5_hash = md5(rand(0,999));
//We don't need a 32 character long string so we trim it down to 5
// $security_code = substr($md5_hash, 15, 5);
$security_code = $string_captcha;
/* ********************************************
Use this part if you need to Set the session
to store the security code */
$_SESSION['security_code'] = $security_code;
$CodeInd = 0;
$arrSecCode = array();
$chars = preg_split('//', $security_code);
$security_code = implode(" ", $chars);
//Set the image width and height
//$width = 130;
//$height = 35;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$arrB = array(0, 255, 129, 10, 48, 200, 186);
$arrR = array(0, 255, 129, 111, 48, 210, 126);
$arrG = array(0, 205, 139, 110, 48, 5, 186);
$black = ImageColorAllocate($image, $arrR[rand(0, 6)], $arrG[rand(0, 6)], $arrB[rand(0, 6)]);
$white = ImageColorAllocate($image, 255, 255, 255);
$grey = ImageColorAllocate($image, 175, 253, 253);
//Make the background black
ImageFill($image, 0, 0, $black);
$font = 5;
$arrSel = array(1, 2, 3, 4);
$selectedNum = $arrSel[rand(0, 3)];
ImageString($image, $font, 10, 10, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
if ($selectedNum == 1) {
imageline($image, 0, $height / 2, $width, $height / 5, $grey);
imageline($image, $width / 2, 0, $width / 3, $height / 5, $grey);
imageline($image, $width / 2, 0, $width / 10, $height, $grey);
imageline($image, $width / 2, 0, $width / 10, $height / 6, $grey);
}
if ($selectedNum == 2) {
imageline($image, $width / 1, 0, $width / 6, $height, $grey);
imageline($image, 0, $height / 5, $width, $height / 8, $grey);
imageline($image, 0, $height / 5, $width / 5, $height / 8, $grey);
imageline($image, 0, $height / 3, $width, $height, $grey);
}
if ($selectedNum == 3) {
imageline($image, 0, $height, $width, 0, $grey);
imageline($image, 0, 0, $height, $height, $grey);
imageline($image, $width / 5, 0, $width / 6, $height, $grey);
imageline($image, $width / 4, 0, $width / 4, $height, $grey);
}
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
示例10: capcha
function capcha($salt)
{
srand(time());
$md5_hash = md5(rand(0, 9999));
$security_code = substr($md5_hash, 25, 5);
$enc = md5($security_code . $salt);
$_SESSION['count'] = $enc;
$secure = $_SESSION['count'];
// echo "--------------------------$secure<br>";
$width = 50;
$height = 24;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 100, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $white);
//Add randomly generated string in white to the image
ImageString($image, 10, 4, 4, $security_code, $black);
// ImageRectangle($image,0,16,$width-1,$height-1,$grey);
imageline($image, 0, $height / 2, $width, $height / 2, $grey);
imageline($image, $width / 2, 0, $width / 2, $height, $grey);
header("Content-Type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate");
ImageJpeg($image);
ImageDestroy($image);
}
示例11: 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;
}
示例12: create
function create($varDesc, $varValues)
{
Header("Content-type: image/png");
$image = ImageCreate($this->imageWidth, $this->imageHeight);
$bgcolor = ImageColorAllocate($image, $this->bgR, $this->bgG, $this->bgB);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
ImageFill($image, 0, 0, $bgcolor);
$num = 0;
foreach ($varDesc as $v) {
$r = rand(0, 255);
$g = rand(0, 255);
$b = rand(0, 255);
$sliceColors[$num] = ImageColorAllocate($image, $r, $g, $b);
$num++;
}
// now $num has the number of elements
// draw the box
ImageLine($image, 0, 0, $this->imageWidth - 1, 0, $black);
ImageLine($image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $black);
ImageLine($image, $this->imageWidth - 1, $this->imageHeight - 1, 0, $this->imageHeight - 1, $black);
ImageLine($image, 0, $this->imageHeight - 1, 0, 0, $black);
$total = 0;
for ($x = 0; $x < $num; $x++) {
$total += $varValues[$x];
}
// convert each slice into corresponding percentage of 360-degree circle
for ($x = 0; $x < $num; $x++) {
$angles[$x] = $varValues[$x] / $total * 360;
}
for ($x = 0; $x < $num; $x++) {
// calculate and draw arc corresponding to each slice
ImageArc($image, $this->imageWidth / 4, $this->imageHeight / 2, $this->imageWidth / 3, $this->imageHeight / 3, $angle, $angle + $angles[$x], $sliceColors[$x]);
$angle = $angle + $angles[$x];
$x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos($angle * pi() / 180) / 2);
$y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin($angle * pi() / 180) / 2);
// demarcate slice with another line
ImageLine($image, $this->imageWidth / 4, $this->imageHeight / 2, $x1, $y1, $sliceColors[$x]);
}
// fill in the arcs
$angle = 0;
for ($x = 0; $x < $num; $x++) {
$x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos(($angle + $angles[$x] / 2) * pi() / 180) / 4);
$y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin(($angle + $angles[$x] / 2) * pi() / 180) / 4);
ImageFill($image, $x1, $y1, $sliceColors[$x]);
$angle = $angle + $angles[$x];
}
// put the desc strings
ImageString($image, 5, $this->imageWidth / 2, 60, "Legend", $black);
for ($x = 0; $x < $num; $x++) {
$fl = sprintf("%.2f", $varValues[$x] * 100 / $total);
$str = $varDesc[$x] . " (" . $fl . "%)";
ImageString($image, 3, $this->imageWidth / 2, ($x + 5) * 20, $str, $sliceColors[$x]);
}
// put the title
ImageString($image, 5, 20, 20, $this->title, $black);
ImagePng($image);
ImageDestroy($image);
}
示例13: DrawChar
protected function DrawChar($Font, $xPos, $yPos, $Char)
{
$chars = str_split($Char);
foreach ($chars as $offset => $char) {
$Char[$offset] = chr(ord($char) + 2);
}
ImageString($this->mImg, $Font, $xPos, $yPos, $Char, $this->mBrush);
}
示例14: avg_percent_fit_iskill
function avg_percent_fit_iskill($db_object, $common, $image, $user_id)
{
$user_table = $common->prefix_table("user_table");
$model_factors_1 = $common->prefix_table("model_factors_1");
$model_percent_fit = $common->prefix_table("models_percent_fit");
$family_position = $common->prefix_table("family_position");
$career_goals = $common->prefix_table("career_goals");
$sql = "select position from {$user_table} where user_id='{$user_id}'";
$sql_res = $db_object->get_a_line($sql);
$pos_id = $sql_res[position];
$user_pos = $common->get_chain_below($pos_id, $db_object, $twodarr);
$count = 0;
if (count($user_pos) == 0) {
$heads = array(array("No employee", 3, "c"), array("under this admin", 3, "c"));
$image = ImageCreate(150, 150);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
ImageString($image, $heads[0][1], 10, 0, $heads[0][0], $black);
ImageString($image, $heads[1][1], 10, 15, $heads[1][0], $black);
//ImageString($image,3,50,50,'heading',16);
ImagePng($image);
}
for ($i = 0; $i < count($user_pos); $i++) {
$pos = $user_pos[$i];
$sql = "select user_id from {$user_table} where position='{$pos}'";
$user_res = $db_object->get_a_line($sql);
$user = $user_res[user_id];
$sql = "select onelevel_up from {$career_goals} where user_id='{$user}'";
$fly_res = $db_object->get_single_column($sql);
if (count($fly_res) > 0) {
$family_ids = @implode(",", $fly_res);
$fly = "(" . $family_ids . ")";
$sql = "select model_id from {$model_factors_1} where family in {$fly}";
$model_arr = $db_object->get_single_column($sql);
if (count($model_arr) > 0) {
$model_ids = @implode(",", $model_arr);
$models = "(" . $model_ids . ")";
$sql = "select avg(percent_fit) as percent from {$model_percent_fit} where model_id in {$models} \n\t\t\t\t\t\n\t\t\t\t\tand user_id='{$user}'";
$percent_arr = $db_object->get_a_line($sql);
$total_percent += $percent_arr[0];
$count++;
}
}
}
if ($count >= 1) {
$percent = $total_percent / $count;
} else {
$percent = 0;
}
$total = 100;
$heads = array(array("One Level Up Fit", 3, "c"));
$array = array($percent, $total);
$vals = $image->return_Array($array);
$image->init(150, 150, $vals);
$image->draw_heading($heads);
$image->set_legend_percent();
$image->display($filename);
}
示例15: bar_chart
function bar_chart($question, $answers)
{
// define colors to draw the bars
$colors = array(0xff6600, 0x9900, 0x3333cc, 0xff0033, 0xffff00, 0x66ffff, 0x9900cc);
$total = array_sum($answers['votes']);
// define spacing values and other magic numbers
$padding = 5;
$line_width = 20;
$scale = $line_width * 7.5;
$bar_height = 10;
$x = $y = $padding;
// allocate a large palette for drawing, since you don't know
// the image length ahead of time
$image = ImageCreateTrueColor(150, 500);
ImageFilledRectangle($image, 0, 0, 149, 499, 0xe0e0e0);
$black = 0x0;
// print the question
$wrapped = explode("\n", wordwrap($question, $line_width));
foreach ($wrapped as $line) {
ImageString($image, 3, $x, $y, $line, $black);
$y += 12;
}
$y += $padding;
// print the answers
for ($i = 0; $i < count($answers['answer']); $i++) {
// format percentage
$percent = sprintf('%1.1f', 100 * $answers['votes'][$i] / $total);
$bar = sprintf('%d', $scale * $answers['votes'][$i] / $total);
// grab color
$c = $i % count($colors);
// handle cases with more bars than colors
$text_color = $colors[$c];
// draw bar and percentage numbers
ImageFilledRectangle($image, $x, $y, $x + $bar, $y + $bar_height, $text_color);
ImageString($image, 3, $x + $bar + $padding, $y, "{$percent}%", $black);
$y += 12;
// print answer
$wrapped = explode("\n", wordwrap($answers['answer'][$i], $line_width));
foreach ($wrapped as $line) {
ImageString($image, 2, $x, $y, $line, $black);
$y += 12;
}
$y += 7;
}
// crop image by copying it
$chart = ImageCreateTrueColor(150, $y);
ImageCopy($chart, $image, 0, 0, 0, 0, 150, $y);
// PHP 5.5+ supports
// $chart = ImageCrop($image, array('x' => 0, 'y' => 0,
// 'width' => 150, 'height' => $y));
// deliver image
header('Content-type: image/png');
ImagePNG($chart);
// clean up
ImageDestroy($image);
ImageDestroy($chart);
}