本文整理汇总了PHP中imagestring函数的典型用法代码示例。如果您正苦于以下问题:PHP imagestring函数的具体用法?PHP imagestring怎么用?PHP imagestring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagestring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translucentWatermark
public static function translucentWatermark($originalImage, $watermark, $saveFile = null, $outputFileTipe = 'jpg')
{
$tempFolder = "temp/";
//$fileRandomValue = 0;
$cache = $tempFolder . $saveFile . '.' . $outputFileTipe;
// Load the stamp and the photo to apply the watermark to
if (strstr($originalImage, '.jpg') !== false) {
$im = imagecreatefromjpeg($originalImage);
} elseif (strstr($originalImage, '.png') !== false) {
$im = imagecreatefrompng($originalImage);
}
// First we create our stamp image manually from GD
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0, 0, 99, 69, 0xff);
imagefilledrectangle($stamp, 9, 9, 90, 60, 0xffffff);
//$im = imagecreatefromjpeg('photo.jpeg');
imagestring($stamp, 5, 20, 20, 'libGD', 0xff);
imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0xff);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Merge the stamp onto our photo with an opacity of 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Save the image to file and free memory
imagepng($im, $cache);
imagedestroy($im);
}
示例2: getCode
function getCode($num, $w, $h)
{
// 去掉了 0 1 O l 等
$str = "23456789abcdefghijkmnpqrstuvwxyz";
$code = '';
for ($i = 0; $i < $num; $i++) {
$code .= $str[mt_rand(0, strlen($str) - 1)];
}
//将生成的验证码写入session,备验证页面使用
$_SESSION["my_checkcode"] = $code;
//创建图片,定义颜色值
Header("Content-type: image/PNG");
$im = imagecreate($w, $h);
$black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
$gray = imagecolorallocate($im, 118, 151, 199);
$bgcolor = imagecolorallocate($im, 235, 236, 237);
//画背景
imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
//画边框
imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
//imagefill($im, 0, 0, $bgcolor);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
}
//将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx = rand(5, 10);
for ($i = 0; $i < $num; $i++) {
$strpos = rand(1, 6);
imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
$strx += $w / 5;
}
imagepng($im);
imagedestroy($im);
}
示例3: image
/**
* Displays the captcha image
*
* @access public
* @param int $key Captcha key
* @return mixed Captcha raw image data
*/
function image($key)
{
$value = Jaws_Utils::RandomText();
$result = $this->update($key, $value);
if (Jaws_Error::IsError($result)) {
$value = '';
}
$bg = dirname(__FILE__) . '/resources/simple.bg.png';
$im = imagecreatefrompng($bg);
imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
// Write it in a random position..
$darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
$x = 5;
$y = 20;
$text_length = strlen($value);
for ($i = 0; $i < $text_length; $i++) {
$fnt = rand(7, 10);
$y = rand(6, 10);
imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
$x = $x + rand(15, 25);
}
header("Content-Type: image/png");
ob_start();
imagepng($im);
$content = ob_get_contents();
ob_end_clean();
imagedestroy($im);
return $content;
}
示例4: action_index
/**
* Processes incoming text
*/
public function action_index()
{
$this->request->headers['Content-type'] = 'image/png';
// Grab text and styles
$text = arr::get($_GET, 'text');
$styles = $_GET;
$hover = FALSE;
try {
// Create image
$img = new PNGText($text, $styles);
foreach ($styles as $key => $value) {
if (substr($key, 0, 6) == 'hover-') {
// Grab hover associated styles and override existing styles
$hover = TRUE;
$styles[substr($key, 6)] = $value;
}
}
if ($hover) {
// Create new hover image and stack it
$hover = new PNGText($text, $styles);
$img->stack($hover);
}
echo $img->draw();
} catch (Exception $e) {
if (Kohana::config('pngtext.debug')) {
// Dump error message in an image form
$img = imagecreatetruecolor(strlen($e->getMessage()) * 6, 16);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
imagestring($img, 2, 0, 0, $e->getMessage(), imagecolorallocate($img, 0, 0, 0));
echo imagepng($img);
}
}
}
示例5: codeimage
static function codeimage()
{
$image = imagecreatetruecolor(100, 30);
$bgcolor = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bgcolor);
$code = '';
for ($i = 0; $i < 4; $i++) {
$fontsize = 6;
$fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
$data = "abcdefghjkmnpqrstuvwxy3456789";
$fontcontent = substr($data, rand(1, strlen($data) - 1), 1);
$code .= $fontcontent;
$x = $i * 100 / 4 + rand(5, 10);
$y = rand(5, 10);
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
}
for ($i = 0; $i < 200; $i++) {
$pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor);
}
for ($i = 0; $i < 2; $i++) {
$linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor);
}
$return['code'] = $code;
$return['image'] = $image;
return $return;
// header('content-type:image/png');
// imagepng($image);
}
示例6: imgcode
function imgcode($nums, $width, $high)
{
//去除了數字0和1 字母小寫O和L,為了避免辨識不清楚
//$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMOPQRSTUBWXYZ";
$str = "0123456789";
$code = '';
for ($i = 0; $i < $nums; $i++) {
$code .= $str[mt_rand(0, strlen($str) - 1)];
}
$_SESSION['captcha'] = $code;
//建立圖示,設置寬度及高度與顏色等等條件
$image = imagecreate($width, $high);
$black = imagecolorallocate($image, mt_rand(0, 200), mt_rand(0, 200), mt_rand(0, 200));
$border_color = imagecolorallocate($image, 21, 106, 235);
$background_color = imagecolorallocate($image, 235, 236, 237);
//建立圖示背景
imagefilledrectangle($image, 0, 0, $width, $high, $background_color);
//建立圖示邊框
imagerectangle($image, 0, 0, $width - 1, $high - 1, $border_color);
//在圖示布上隨機產生大量躁點
for ($i = 0; $i < 80; $i++) {
imagesetpixel($image, rand(0, $width), rand(0, $high), $black);
}
$strx = rand(3, 8);
for ($i = 0; $i < $nums; $i++) {
$strpos = rand(1, 6);
imagestring($image, 5, $strx, $strpos, substr($code, $i, 1), $black);
$strx += rand(10, 30);
}
imagepng($image);
imagedestroy($image);
}
示例7: __construct
/**
* Class constructor generates the CAPTCHA image.
*
* @return blob the image
* @access public
*/
function __construct()
{
session_start();
$image = imagecreate($this->width, $this->height);
$random_str = $this->gen_str($this->chars_nr);
#md5( microtime() ); // md5 to generate the random string
$result_str = substr($random_str, 0, $this->chars_nr);
//trim $chars_nr digit
$bg_color = imagecolorallocate($image, $this->background_color['red'], $this->background_color['green'], $this->background_color['blue']);
// background color
$tx_color = imagecolorallocate($image, $this->text_color['red'], $this->text_color['gree'], $this->text_color['blue']);
// text color
for ($i = 0; $i <= $this->lines; $i++) {
$line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
//line color
imageline($image, rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), $line_color);
// Create lines on image
}
imagestring($image, 5, 20, 10, $result_str, $tx_color);
// Draw a random string horizontally
$_SESSION['key'] = $result_str;
// Carry the data through session
header("Content-type: image/png");
// Out out the image
imagepng($image);
// Output image to browser
}
示例8: generateCaptcha
public function generateCaptcha()
{
//make image
$im = imagecreatetruecolor($this->width, $this->height);
//set background
$bg_color = imagecolorallocate($im, mt_rand($this->bg_color_min, $this->bg_color_max), mt_rand($this->bg_color_min, $this->bg_color_max), mt_rand($this->bg_color_min, $this->bg_color_max));
//padding
imagefill($im, 0, 0, $bg_color);
//add lines
for ($i = 0; $i < $this->lines; $i++) {
//set color
$line_color = imagecolorallocate($im, mt_rand($this->line_color_min, $this->line_color_max), mt_rand($this->line_color_min, $this->line_color_max), mt_rand($this->line_color_min, $this->line_color_max));
//draw line
imageline($im, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $line_color);
}
//add pixels
for ($i = 0; $i < $this->pixels; $i++) {
//set color
$pixels_color = imagecolorallocate($im, mt_rand($this->pixels_color_min, $this->pixels_color_max), mt_rand($this->pixels_color_min, $this->pixels_color_max), mt_rand($this->pixels_color_min, $this->pixels_color_max));
//draw pixels
imagesetpixel($im, mt_rand(0, $this->width), mt_rand(0, $this->height), $pixels_color);
}
//get captcha string
$captcha = $this->generateString();
//set color of font
$str_color = imagecolorallocate($im, mt_rand($this->font_color_min, $this->font_color_max), mt_rand($this->font_color_min, $this->font_color_max), mt_rand($this->font_color_min, $this->font_color_max));
//put string to picture
imagestring($im, $this->font, ceil($this->width / 2) - 20, ceil($this->height / 2) - 10, $captcha, $str_color);
//save or output
imagepng($im);
//destroy res
imagedestroy($im);
}
示例9: makeGraphicalCaptcha
/**
* Makes a graphical captcha from the provided text string
*
* @param string $captcha_text string to make image captcha from
* @return string $data_url a data url containing the obfuscated image
*/
function makeGraphicalCaptcha($captcha_text)
{
$image = @imagecreatetruecolor(195, 35);
// defines background color, random lines color and text color
$bg_color = imagecolorallocate($image, mt_rand(0, 255), 255, 0);
imagefill($image, 0, 0, $bg_color);
$lines_color = imagecolorallocate($image, 0x99, 0xcc, 0x99);
$text_color = imagecolorallocate($image, mt_rand(0, 255), 0, 255);
// draws random lines
for ($i = 0; $i < 4; $i++) {
imageline($image, 0, rand(0, 35), 195, rand(0, 35), $lines_color);
}
$captcha_letter_array = str_split($captcha_text);
foreach ($captcha_letter_array as $i => $captcha_letter) {
imagesetthickness($image, 1);
imagestring($image, 5, 5 + $i * 35, rand(2, 14), $captcha_letter, $text_color);
}
// creates image
ob_start();
imagejpeg($image);
$image_data = ob_get_contents();
ob_end_clean();
$data_url = "data:image/jpeg;base64," . base64_encode($image_data);
imagedestroy($image);
return $data_url;
}
示例10: imagecharx
function imagecharx($img, $char, $x0, $y0, $ylist)
{
global $bk_color, $fg_color;
$da = @imagecreate(10, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($da, $bk_color[0], $bk_color[1], $bk_color[2]);
$text_color = imagecolorallocate($da, $fg_color[0], $fg_color[1], $fg_color[2]);
$color = imagecolorallocate($img, $fg_color[0], $fg_color[1], $fg_color[2]);
$arg = rand(0, 18) / 100.0 * pi();
imagestring($da, 18, 0, 0, $char, $text_color);
for ($i = 0; $i < 200; $i++) {
$y = @floor($i / 10);
$x = $i % 10;
$point_color = imagecolorat($da, $x, $y);
if ($point_color == $text_color) {
for ($j = 0; $j < 12; $j++) {
$dx = 0;
$dy = 0;
$p = 6;
for ($s = 0; $s < $p; $s++) {
$dx += rand(0, 1000 / $p) / 100;
$dy += rand(0, 1000 / $p) / 100;
}
$xx = $x * 5 + $dx - 25;
$yy = $y * 5 + $dy - 50;
$x1 = cos($arg) * $xx - sin($arg) * $yy + 25;
$y1 = sin($arg) * $xx + cos($arg) * $yy + 50;
imagesetpixel($img, $x0 + $x1, $y0 + $y1, $color);
}
}
}
imagedestroy($da);
}
示例11: create_image
function create_image()
{
header("Content-Type: image/png");
$image = imagecreatetruecolor(200, 50) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 122, 111, 255);
$line_color = imagecolorallocate($image, 64, 64, 64);
$pixel_color = imagecolorallocate($image, 0, 0, 255);
imagefilledrectangle($image, 0, 0, 200, 50, $background_color);
for ($i = 0; $i < 3; $i++) {
imageline($image, 0, rand(0, 255) % 50, 200, rand(0, 255) % 50, $line_color);
}
for ($i = 0; $i < 1000; $i++) {
imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color);
}
$letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$len = strlen($letters);
$letter = $letters[rand(0, $len - 1)];
# $text_color = imagecolorallocate($image, 0, 0, 0);
$word = "";
for ($i = 0; $i < 6; $i++) {
$letter = $letters[rand(0, $len - 1)];
imagestring($image, 7, 5 + $i * 30, 20, $letter, $text_color);
$word .= $letter;
}
$_SESSION['solution'] = $word;
imagepng($image);
imagedestroy($image);
}
示例12: createImage
protected function createImage($width, $height)
{
$im = imagecreate($width, $height);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "Простая Текстовая Строка", $text_color);
imagepng($im, $this->tmpFile);
}
示例13: drawRating
function drawRating($rating, $max, $type)
{
if ($type == 0) {
$image = imagecreatetruecolor(102, 15);
$back = ImageColorAllocate($image, 250, 250, 250);
$border = ImageColorAllocate($image, 0, 0, 0);
$fill = ImageColorAllocate($image, 0, 235, 0);
ImageFilledRectangle($image, 0, 0, 101, 14, $back);
ImageFilledRectangle($image, 1, 1, $rating / $max * 100, 14, $fill);
ImageRectangle($image, 0, 0, 101, 14, $border);
$textcolor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 35, 0, $rating / $max * 100 . '%', $textcolor);
} else {
if ($rating > $max) {
$rating = $max;
}
$image = imagecreatetruecolor(10 * ($rating + 2) + 2, 15);
$back = ImageColorAllocate($image, 250, 250, 250);
$border = ImageColorAllocate($image, 0, 0, 0);
$fill = ImageColorAllocate($image, 235, 0, 0);
ImageFilledRectangle($image, 0, 0, 10 * ($rating + 2) + 1, 14, $back);
ImageFilledRectangle($image, 1, 1, 10 * $rating, 14, $fill);
ImageRectangle($image, 0, 0, 10 * $rating + 1, 14, $border);
$textcolor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 10 * ($rating + 1), 0, $rating, $textcolor);
}
imagepng($image);
imagedestroy($image);
}
示例14: getCode
function getCode($num, $w, $h)
{
$code = "";
for ($i = 0; $i < $num; $i++) {
$code .= rand(0, 9);
}
//4位验证码也可以用rand(1000,9999)直接生成
//将生成的验证码写入session,备验证页面使用
$_SESSION['yzm'] = $code;
//setcookie("mimi", md5($code), time()+1200);
//创建图片,定义颜色值
Header("Content-type: image/PNG");
$im = imagecreate($w, $h);
$black = imagecolorallocate($im, 255, 0, 63);
$gray = imagecolorallocate($im, 200, 200, 200);
$bgcolor = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bgcolor);
//画边框
//imagerectangle($im, 0, 0, $w-1, $h-1, $black);
//在画布上随机生成大量黑点,起干扰作用;
for ($i = 0; $i < 10; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
}
//将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx = rand(1, 3);
for ($i = 0; $i < $num; $i++) {
$strpos = rand(2, 6);
imagestring($im, 5, $strx, $strpos, substr($code, $i, 1), $black);
$strx += rand(8, 12);
}
imagepng($im);
imagedestroy($im);
}
示例15: create_image
function create_image()
{
// *** Generate a passcode using md5
// (it will be all lowercase hex letters and numbers ***
$md5 = md5(rand(0, 9999));
$pass = substr($md5, 10, 5);
// *** Set the session cookie so we know what the passcode is ***
$_SESSION["pass"] = $pass;
// *** Create the image resource ***
$image = ImageCreatetruecolor(100, 20);
// *** We are making two colors, white and black ***
$clr_white = ImageColorAllocate($image, 255, 255, 255);
$clr_black = ImageColorAllocate($image, 0, 0, 0);
// *** Make the background black ***
imagefill($image, 0, 0, $clr_black);
// *** Set the image height and width ***
imagefontheight(15);
imagefontwidth(15);
// *** Add the passcode in white to the image ***
imagestring($image, 5, 30, 3, $pass, $clr_white);
// *** Throw in some lines to trick those cheeky bots! ***
imageline($image, 5, 1, 50, 20, $clr_white);
imageline($image, 60, 1, 96, 20, $clr_white);
// *** Return the newly created image in jpeg format ***
return imagejpeg($image);
// *** Just in case... ***
imagedestroy($image);
}