本文整理汇总了PHP中imageFilledRectangle函数的典型用法代码示例。如果您正苦于以下问题:PHP imageFilledRectangle函数的具体用法?PHP imageFilledRectangle怎么用?PHP imageFilledRectangle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageFilledRectangle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: code39
public static function code39($text, $height = 50, $widthScale = 1)
{
// if (!preg_match('/^[A-Z0-9-. $+\/%]+$/i', $text)) {
// throw new Exception('Invalid text input.');
// }
// $text = '*' . strtoupper($text) . '*'; // *UPPERCASE TEXT*
$length = strlen($text);
$barcode = imageCreate($length * 16 * $widthScale, $height);
$bg = imagecolorallocate($barcode, 255, 255, 255);
//sets background to yellow
imagecolortransparent($barcode, $bg);
//makes that yellow transparent
$black = imagecolorallocate($barcode, 0, 0, 0);
//defines a color for black
$chars = str_split($text);
$colors = '';
foreach ($chars as $char) {
$colors .= self::$code39[$char];
}
foreach (str_split($colors) as $i => $color) {
if ($color == 'b') {
// imageLine($barcode, $i, 0, $i, $height-13, $black);
// imageFilledRectangle($barcode, $widthScale * $i, 0, $widthScale * ($i+1) -1 , $height-13, $black);
imageFilledRectangle($barcode, $widthScale * $i, 0, $widthScale * ($i + 1) - 1, $height, $black);
}
}
//16px per bar-set, halved, minus 6px per char, halved (5*length)
// $textcenter = $length * 5 * $widthScale;
//$textcenter = ($length * 8 * $widthScale) - ($length * 3);
//
// imageString($barcode, 2, $textcenter, $height-13, $text, $black);
header("Content-type: image/png");
// out out the image
imagepng($barcode);
}
示例2: create
/**
* 显示验证码
*/
function create()
{
$this->image = imageCreate($this->width, $this->height);
$this->back = $this->getColor($this->bgcolor);
imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back);
$size = $this->width / $this->charLen - 4;
if ($size > $this->height) {
$size = $this->height;
}
$left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5;
$code = '';
for ($i = 0; $i < $this->charLen; $i++) {
$randKey = rand(0, count($this->arrChr) - 1);
$randText = $this->arrChr[$randKey];
$code .= $randText;
$textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100));
$font = $this->fontPath . '/' . rand(1, 5) . ".ttf";
$randsize = rand($size - $size / 10, $size + $size / 10);
$location = $left + ($i * $size + $size / 10);
@imagettftext($this->image, $randsize, rand(-18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $randText);
}
if ($this->showNoisePix == true) {
$this->setNoisePix();
}
if ($this->showNoiseLine == true) {
$this->setNoiseLine();
}
if ($this->showBorder == true) {
$this->borderColor = $this->getColor($this->borderColor);
imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor);
}
$this->text = strtolower($code);
}
示例3: king_def
function king_def()
{
global $king;
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// 过去的时间
header("Content-type: image/png");
$salt = kc_get('salt', 1, 1);
$width = $king->config('verifywidth');
//图片长度
$height = $king->config('verifyheight');
//图片高度
$size = $king->config('verifysize');
//文字大小
$num = $king->config('verifynum');
//文字数量
$content = $king->config('verifycontent');
//随机字符
$array_content = explode('|', $content);
$array_content = array_diff($array_content, array(null));
$array_font = kc_f_getdir('system/verify_font', 'ttf|ttc');
$str = '';
$img = imageCreate($width, $height);
//创建一个空白图像
imageFilledRectangle($img, 0, 0, $width, $height, imagecolorallocate($img, 255, 255, 255));
//写字
for ($i = 0; $i < $num; $i++) {
$code = $array_content[array_rand($array_content)];
$str .= $code;
//验证码字符
$color = imageColorAllocate($img, rand(0, 128), rand(0, 128), rand(0, 128));
$font = 'verify_font/' . $array_font[array_rand($array_font)];
//随机读取一个字体
$left = rand(round($size * 0.2), round($size * 0.4)) + $i * $size;
imagettftext($img, rand(round($size * 0.7), $size), rand(-20, 20), $left, rand(round($size * 1.2), $size * 1.4), $color, $font, $code);
}
//画星号
$max = $width * $height / 400;
for ($i = 0; $i < $max; $i++) {
imagestring($img, 15, rand(0, $width), rand(0, $height), '*', rand(192, 250));
}
//画点
$max = $width * $height / 40;
for ($i = 0; $i < $max; $i++) {
imageSetPixel($img, rand(0, $width), rand(0, $height), rand(1, 200));
}
//画线
$max = $width * $height / 800;
for ($i = 0; $i < $max; $i++) {
imageline($img, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), rand(0, 255));
}
//写验证码到verify中
$verify = new KC_Verify_class();
$verify->Put($salt, $str);
imagePng($img);
imageDestroy($img);
$verify->Clear();
}
示例4: updateBackground
/**
* Generates a wallpaper with the latest data and updates desktop background
*
* @param array $data Array with the latest build history per project
*/
private function updateBackground($data)
{
$this->updatedAt = microtime(true);
$this->image = imagecreatetruecolor($this->get('image_width'), $this->get('image_height'));
imageantialias($this->image, true);
$this->initializeColors();
imagefill($this->image, 0, 0, $this->get('background_color'));
$numProject = 0;
foreach ($data['projects'] as $project => $builds) {
// the most recent build is always shown on top
rsort($builds);
$x1 = $this->get('horizontal_padding') + ($this->get('bar_width') + $this->get('horizontal_gutter')) * $numProject;
$x2 = $x1 + $this->get('bar_width');
// plot each project slug
$this->addTextToImage(substr($project, 0, $this->get('max_number_letters')), $x1, $this->get('vertical_padding') - 0.2 * $this->get('font_size'));
foreach ($builds as $i => $build) {
$y1 = $this->get('vertical_padding') + $this->get('font_size') + ($this->get('bar_height') + $this->get('vertical_gutter')) * $i;
$y2 = $y1 + $this->get('bar_height');
$color = 'ok' == $build ? $this->get('success_color') : $this->get('failure_color');
// plot a bar for each project build
imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
}
$numProject++;
}
$this->addTextToImage('Last update: ' . $data['last_update'], $this->get('horizontal_padding'), $this->get('image_height') - $this->get('font_size'));
// Hack: two different images are needed to update the wallpaper
// One holds the current wallpaper and the other is the new one
// If you use just one image and modify it, the OS doesn't reload it
if (file_exists($this->evenBackgroundImagePath)) {
$this->imagePath = $this->oddBackgroundImagePath;
unlink($this->evenBackgroundImagePath);
} elseif (file_exists($this->oddBackgroundImagePath)) {
$this->imagePath = $this->evenBackgroundImagePath;
unlink($this->oddBackgroundImagePath);
} else {
$this->imagePath = $this->oddBackgroundImagePath;
}
imagepng($this->image, $this->imagePath);
imagedestroy($this->image);
// Wallpaper is reloaded via AppleScript
$scriptPath = $this->dir . '/update-background.scpt';
file_put_contents($scriptPath, <<<END
tell application "System Events"
tell current desktop
set picture to POSIX file "file://localhost/{$this->imagePath}"
end tell
end tell
END
);
system("osascript {$scriptPath}");
}
示例5: placeholder
/**
* Placeholder code adapted from dummyimage.com
*/
public static function placeholder($width, $height)
{
$file_format = 'gif';
$width = $width;
$height = $height;
$text_angle = 0;
$font = Load::getModulePath('media') . 'assets/mplus-1c-medium.ttf';
$img = imageCreate($width, $height);
$bg_color = imageColorAllocate($img, 196, 196, 196);
$fg_color = imageColorAllocate($img, 94, 94, 94);
$lines = 1;
$text = $width . 'x' . $height;
$fontsize = max(min($width / strlen($text) * 1.15, $height * 0.5), 5);
$textBox = self::_imagettfbbox_t($fontsize, $text_angle, $font, $text);
$textWidth = ceil(($textBox[4] - $textBox[1]) * 1.07);
$textHeight = ceil((abs($textBox[7]) + abs($textBox[1])) * 1);
$textX = ceil(($width - $textWidth) / 2);
$textY = ceil(($height - $textHeight) / 2 + $textHeight);
imageFilledRectangle($img, 0, 0, $width, $height, $bg_color);
imagettftext($img, $fontsize, $text_angle, $textX, $textY, $fg_color, $font, $text);
$offset = 60 * 60 * 24 * 14;
//14 Days
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($ExpStr);
//Set a far future expire date. This keeps the image locally cached by the user for less hits to the server.
header('Cache-Control: max-age=120');
header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - $offset) . " GMT");
header('Content-type: image/' . $file_format);
//Set the header so the browser can interpret it as an image and not a bunch of weird text.
switch ($file_format) {
case 'gif':
imagegif($img);
break;
case 'png':
imagepng($img);
break;
case 'jpg':
imagejpeg($img);
break;
case 'jpeg':
imagejpeg($img);
break;
}
imageDestroy($img);
exit;
}
示例6: _image
/**
* Make image
*
*/
protected function _image()
{
$this->_image = imagecreate($this->config['width'], $this->config['height']);
imageFilledRectangle($this->_image, 0, 0, $this->config['width'], $this->config['height'], $this->_color($this->config['bgColor']));
$seed = $this->_seed();
$fonts = $this->_fonts();
$_SESSION[$this->config['sessionValueKey']] = $seed;
$_SESSION[$this->config['sessionTtlKey']] = time() + $this->config['ttl'];
for ($i = 0; $i < $this->config['length']; $i++) {
$char = substr($seed, $i, 1);
$x = $this->config['padding'] + $i * ($this->config['size'] + $this->config['space']);
$y = mt_rand(0.7 * $this->config['height'], 0.9 * $this->config['height']);
$charColor = imageColorAllocate($this->_image, mt_rand(50, 155), mt_rand(50, 155), mt_rand(50, 155));
imagettftext($this->_image, $this->config['size'], mt_rand(-18, 18), $x, $y, $charColor, $fonts[$i], $char);
}
$this->_noise();
}
示例7: textToImg
function textToImg($text, $backRGB, $strRGB, $fontPath, $fontSize, $margin)
{
// 大きさを測定
$result = imageTTFBBox($fontSize, 0, $fontPath, $text);
// 幅と高さを取得
$width = abs($result[4]) + abs($result[6]) + $margin * 2;
$height = abs($result[1]) + abs($result[7]) + $margin * 2;
// イメージリソースを生成
$img = imageCreateTrueColor($width, $height);
// 色を生成
$backColor = imageColorAllocate($img, $backRGB['red'], $backRGB['green'], $backRGB['blue']);
$strColor = imageColorAllocate($img, $strRGB['red'], $strRGB['green'], $strRGB['blue']);
// 背景を塗りつぶす
imageFilledRectangle($img, 0, 0, $width, $height, $backColor);
// 文字を描く
imageTTFText($img, $fontSize, 0, $margin + abs($result[0]), $margin + abs($result[7]), $strColor, $fontPath, $text);
return $img;
}
示例8: createTestImage
/**
* Create test image.
*
* @param string $filename
* @return void
*/
protected function createTestImage($filename)
{
$filename = $this->getFullPath($filename);
if (!file_exists($filename)) {
// Create an image with the specified dimensions
$image = imageCreate(300, 200);
// Create a color (this first call to imageColorAllocate
// also automatically sets the image background color)
$colorYellow = imageColorAllocate($image, 255, 255, 0);
// Draw a rectangle
imageFilledRectangle($image, 50, 50, 250, 150, $colorYellow);
$directory = dirname($filename);
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
imageJpeg($image, $filename);
// Release memory
imageDestroy($image);
}
}
示例9: getPNG
public function getPNG()
{
// создаем картинку
$image = imageCreate($this->width + $this->widthLegend, $this->height);
$backColor = imageColorAllocate($image, $this->colorBG >> 16, ($this->colorBG >> 8) % 256, $this->colorBG % 256);
$centerColor = imageColorAllocate($image, $this->colorCenter >> 16, ($this->colorCenter >> 8) % 256, $this->colorCenter % 256);
$pointsColor = imageColorAllocate($image, $this->colorPoints >> 16, ($this->colorPoints >> 8) % 256, $this->colorPoints % 256);
$legendColor = imageColorAllocate($image, $this->colorLegend >> 16, ($this->colorLegend >> 8) % 256, $this->colorLegend % 256);
// background
imageFilledRectangle($image, 0, 0, $this->width, $this->height, $backColor);
imageRectangle($image, $this->width, 0, $this->widthLegend + $this->width - 1, $this->height - 1, $legendColor);
// добавляем масштаб в легенду
imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2 - 1, $this->width + 10, $this->height - $this->fontSize * 2 + 1, $legendColor);
imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2, $this->width + 20, $this->height - $this->fontSize * 2, $legendColor);
imageLine($image, $this->width + 20, $this->height - $this->fontSize * 2 - 1, $this->width + 20, $this->height - $this->fontSize * 2 + 1, $legendColor);
imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize + 20, $this->height - $this->fontSize * 1.5, $legendColor, $this->pathToFont, "{$this->metersIn10Pix} {$this->metersLabel}");
// center
imageFilledEllipse($image, $this->centerWidth, $this->centerHeight, $this->sizePoints, $this->sizePoints, $centerColor);
imageTTFText($image, $this->fontSize, 0, $this->centerWidth, $this->centerHeight + $this->fontSize + $this->sizePoints, $centerColor, $this->pathToFont, "0");
imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2, $legendColor, $this->pathToFont, "0 - {$this->centerLabel}");
// points
$i = 1;
foreach ($this->pointsBased as $v) {
$angle = $v->getPoint()->getAzimuth() - 90;
// угол для тригонометрии
$pointWidth = $this->centerWidth + $this->k * ($v->getPoint()->getDistance() * cos(deg2rad($angle)));
$pointHeight = $this->centerHeight + $this->k * ($v->getPoint()->getDistance() * sin(deg2rad($angle)));
// рисуем точку
imageEllipse($image, $pointWidth, $pointHeight, $this->sizePoints, $this->sizePoints, $pointsColor);
// подпись
imageTTFText($image, $this->fontSize, 0, $pointWidth, $pointHeight + $this->fontSize + $this->sizePoints, $pointsColor, $this->pathToFont, $i);
// в легенду
imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2 * ($i + 1), $legendColor, $this->pathToFont, "{$i} - " . $v->getTitle());
$i++;
}
ob_start();
imagePng($image);
$str = ob_get_clean();
return $str;
}
示例10: show
public static function show()
{
$width = self::$width;
$height = self::$height;
$len = self::$len;
$bgcolor = self::$bgcolor;
$noise = self::$noise;
$noisenum = self::$noisenum;
$border = self::$border;
$bordercolor = self::$bordercolor;
self::$_image = imageCreate($width, $height);
$back = self::getcolor($bgcolor);
imageFilledRectangle(self::$_image, 0, 0, $width, $height, $back);
$size = $width / $len;
if ($size > $height) {
$size = $height;
}
$left = ($width - $len * ($size + $size / 10)) / $size;
for ($i = 0; $i < $len; $i++) {
$randtext = self::vchar();
self::$_code .= $randtext;
$textColor = imageColorAllocate(self::$_image, rand(0, 100), rand(0, 100), rand(0, 100));
$font = dirname(__FILE__) . "/3.ttf";
$randsize = rand($size - $size / 5, $size - $size / 10);
$location = $left + ($i * $size + $size / 10);
imagettftext(self::$_image, $randsize, rand(-18, 18), $location, rand($size - $size / 100, $size + $size / 100), $textColor, $font, $randtext);
}
if ($noise == true) {
self::setnoise();
}
self::setCode(self::$_code);
//setrawcookie("code",$code,time()+3600,"/");
//setcookie("code", $code, time()+120);
$bordercolor = self::getcolor($bordercolor);
if ($border == true) {
imageRectangle(self::$_image, 0, 0, $width - 1, $height - 1, $bordercolor);
}
return self::$_image;
}
示例11: show
/**
* 显示验证码
*
*/
function show()
{
$this->image = imageCreate($this->width, $this->height);
$this->back = $this->getColor($this->bgcolor);
imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back);
$size = $this->width / $this->charLen - 4;
if ($size > $this->height) {
$size = $this->height;
}
$left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5;
$code = '';
for ($i = 0; $i < $this->charLen; $i++) {
$randKey = rand(0, count($this->arrChr) - 1);
$randText = $this->arrChr[$randKey];
$code .= $randText;
$textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100));
$font = $this->fontPath . "1.ttf";
$randsize = rand($size - $size / 10, $size + $size / 10);
$location = $left + ($i * $size + $size / 10);
imagestring($this->image, mt_rand(3, 5), $location, 5, $randText, imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)));
//imagettftext($this->image, $randsize, rand(- 18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $code);
}
if ($this->showNoisePix == true) {
$this->setNoisePix();
}
if ($this->showNoiseLine == true) {
$this->setNoiseLine();
}
if ($this->showBorder == true) {
$this->borderColor = $this->getColor($this->borderColor);
imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor);
}
$this->CI->session->set_userdata('auth_code', $code);
ob_clean();
header("Content-type: image/jpeg");
imagejpeg($this->image);
imagedestroy($this->image);
}
示例12: output
private function output($saveStr = false)
{
$this->image = ImageCreate($this->larguaImagem, $this->alturaImagem);
$background = $this->color($this->corDeFundo);
imageFilledRectangle($this->image, 0, 0, $this->larguaImagem, $this->alturaImagem, $background);
srand($this->make_seed());
# space in chars
$percent80 = $this->larguaImagem - $this->larguaImagem * 0.15;
#$textSpace = ceil(($this->larguaImagem-40)/$this->maxChars) ;
$textSpace = ceil($percent80 / $this->maxChars);
$topMargim = $this->alturaImagem > 20 ? $this->alturaImagem / 2.2 : 5;
# generate chars
for ($i = 0; $i < $this->maxChars; $i++) {
$this->gerarValor = str_shuffle($this->gerarValor);
shuffle($this->hexcolors);
shuffle($this->fonts);
# select a char on array
$char = $this->gerarValor[0];
# rotarion of chars
$rotate = $this->rotateImg > 1 ? rand(-9, 10) : 0;
# join chars value
$saveStr .= $char;
# make captcha
imagettftext($this->image, $this->fontSize, $rotate, 10 + $i * $textSpace, rand($this->alturaImagem, $topMargim), $this->randcolor(), "{$this->serverRoot}{$this->path}{$this->fonts[0]}", $char);
}
for ($k = 0; $k < $this->maxChars / 2; $k++) {
if ($this->noSquare == 0) {
$this->randsquare();
}
$this->randline();
}
header("Content-type: image/jpeg");
imagejpeg($this->image);
imagedestroy($this->image, '', 100);
return $saveStr;
}
示例13: draw_rectangle
function draw_rectangle($x1, $y1, $x2, $y2, $color, $filled)
{
if ($filled) {
imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
} else {
imageRectangle($this->image, $x1, $y1, $x2, $y2, $color);
}
}
示例14: abs
// this works because Julian dates specify an absolute number
// of days -> the difference between Julian birthday and
// "Julian today" gives the number of days alive
$daysGone = abs(gregorianToJD($birthMonth, $birthDay, $birthYear) - gregorianToJD(date("m"), date("d"), date("Y")));
// create image
$image = imageCreate($diagramWidth, $diagramHeight);
// allocate all required colors
$colorBackgr = imageColorAllocate($image, 192, 192, 192);
$colorForegr = imageColorAllocate($image, 255, 255, 255);
$colorGrid = imageColorAllocate($image, 0, 0, 0);
$colorCross = imageColorAllocate($image, 0, 0, 0);
$colorPhysical = imageColorAllocate($image, 0, 0, 255);
$colorEmotional = imageColorAllocate($image, 255, 0, 0);
$colorIntellectual = imageColorAllocate($image, 0, 255, 0);
// clear the image with the background color
imageFilledRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $colorBackgr);
// calculate start date for diagram and start drawing
$nrSecondsPerDay = 60 * 60 * 24;
$diagramDate = time() - $daysToShow / 2 * $nrSecondsPerDay + $nrSecondsPerDay;
for ($i = 1; $i < $daysToShow; $i++) {
$thisDate = getDate($diagramDate);
$xCoord = $diagramWidth / $daysToShow * $i;
// draw day mark and day number
imageLine($image, $xCoord, $diagramHeight - 25, $xCoord, $diagramHeight - 20, $colorGrid);
imageString($image, 3, $xCoord - 5, $diagramHeight - 16, $thisDate["mday"], $colorGrid);
$diagramDate += $nrSecondsPerDay;
}
// draw rectangle around diagram (marks its boundaries)
imageRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 20, $colorGrid);
// draw middle cross
imageLine($image, 0, ($diagramHeight - 20) / 2, $diagramWidth, ($diagramHeight - 20) / 2, $colorCross);
示例15: imageFilledRectangle
protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color)
{
$color = $this->gdColor($color);
if ($color === false) {
return false;
}
return imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
}