php imagecolorallocate

 更新时间:2016年11月25日 16:50  点击:1938

php imagecolorallocate

imagecolorallocate - 分配一个彩色的图像

int imagecolorallocate ( resource $image , int $red , int $green , int $blue

)

返回一个颜色标识代表给定的RGB成分组成的颜色。

imagecolorallocate()必须被调用来创建每个颜色,将在由形象代表的图像中使用。

注:第一次调用imagecolorallocate()填补了调色板背景颜色的图像 - 图像创建使

用imagecreate()。

图片
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。

红色
红色分量的价值。

绿色
价值的绿色成分。

蓝色
蓝色成分的价值。

这些参数是介于0和255之间或0x00和0xFF十六进制整数。

报告错误返回值
阿色标识或FALSE如果分配失败。


<?php

$im = imagecreate(100, 100);

// sets background to red
$background = imagecolorallocate($im, 255, 0, 0);

// sets some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// hexadecimal way
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

?>
这里有一个非常简单的函数,基本上是相同imagecolorallocate(),而无需只有一个

图像资源工作。

<?php
function createcolor($r, $g, $b) {
  return hexdec(str_pad(dechex($r), 2, 0, STR_PAD_LEFT).str_pad(dechex($g),

2, 0, STR_PAD_LEFT).str_pad(dechex($b), 2, 0, STR_PAD_LEFT));
}

/ *正如前面所说的,这个函数不完全一样的事情作为imagecolorallocate(),而不

需要一个图像资源。这意味着,下面的两个区块中的代码的结果完全相同的事情:* /

$color = colorcreate(105, 199, 204);

//Block 2
$img = imagecreatetruecolor(100, 100); //the arguments here don't really

matter
$color = imagecolorallocate($img, 105, 199, 204);
imagedestroy($img);
?>

addcslashes - 函数给'与"增加斜线

描述
字符串addcslashes($str,字符串$ charlist中)
返回前与charlist中的参数是上市反斜杠字符字符串

该字符串转义。

charlist中
字符转义名单。
如果charlist中包含字符 n, R等,它们被转换在C等风格,而对其他非字母数字的ASCII码低于32和高于126转换为八进制表示的字符。

当您在charlist中定义参数的字符序列,确保您知道什么字符之间的字符,你为开端,范围的结束设置来

<?php
echo addcslashes('foo[ ]''A..z'
);
// output:  foo[ ]
// All upper and lower-case letters will be escaped
// ... but so will the []^_`
?>


charlist中如“ 0 .. 37”,这将与ASCII逃脱0到31之间的所有字符代码。

例子1 addcslashes()例子

<?php
$escaped = addcslashes($not_escaped, "..37!@177..377");
?>

imageantialias
(PHP 4 >= 4.3.2, PHP 5)
描述
布尔imageantialias($sourc,$bool)
激活的行反走样快速绘制方法和有线多边形。它不支持阿尔法组件。它可以使用直接混合操作。但它只能在真彩色图像。

厚度和风格不支持。

使用透明背景颜色抗锯齿原语可以结束一些意想不到的结果。混合方法使用任何其他颜色的背景颜色。阿尔法组件的支持,缺乏不允许一个字母为基础的抗锯齿方法

图片
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。

启用
是否启用抗锯齿与否。

返回值
返回TRUE,成功或失败则返回FALSE

<?php
// Setup an anti-aliased image and a normal image
$aa = imagecreatetruecolor(400, 100);
$normal = imagecreatetruecolor(200, 100);

// Switch antialiasing on for one image
imageantialias($aa, true);

// Allocate colors
$red = imagecolorallocate($normal, 255, 0, 0);
$red_aa = imagecolorallocate($aa, 255, 0, 0);

// Draw two lines, one with AA enabled
imageline($normal, 0, 0, 200, 100, $red);
imageline($aa, 0, 0, 200, 100, $red_aa);

// Merge the two images side by side for output (AA: left, Normal: Right)
imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);

// Output image
header('Content-type: image/png');

imagepng($aa);
imagedestroy($aa);
imagedestroy($normal);
?>

imagealphablending
(PHP 4中“= 4.0.6,PHP 5中)

imagealphablending - 设置图像混合模式

报告错误描述
布尔imagealphablending($img,$blendMode $)
imagealphablending()两对真彩色图像绘制不同的模式允许。在混合模式下,供应的,如imagesetpixel所有绘图功能,颜色的alpha通道组件()决定了底层的颜色应允许穿透。因此,广东在混合自动绘图与现有的色点的颜色,在图像存储的结果。由此产生的像素是不透明的。在非混合模式,绘图颜色复制其字面alpha通道信息,替换目标像素。混合模式用时没有对调色板图像绘图。

报告错误参数

图片
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。

将对blendMode
是否启用了混合模式或不。默认为FALSE。


报告错误返回值
返回TRUE,成功或失败则返回FALSE。

报告错误的例子
例子1 imagealphablending()使用示例

<?php
// Create image
$im = imagecreatetruecolor(100, 100);

// Set alphablending to on
imagealphablending($im, true);

// Draw a square
imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));

// Output
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

php imagecreatetruecolor创建高清图片函数
imagecreatetruecolor()返回一个图像标识符代表指定大小的黑色形象。

根据你的PHP和GD版本中函数定义与否。对于PHP 4.0.6通过4.1.x这个函数总是存在的

,如果广东模块加载,但它要求GD2的情况下被安装了PHP将发出一个致命错误并退出。

用PHP 4.2.x版这种行为是不同的人发出警告,而不是一个错误。其他版本只定义此功

能,

看看实例

<?php
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>


我提出这方面合作 - 结合一些例子,然后动态生成的文本。但是,与此设置,我能得

到透明背景的工作也。

<?php
// Set the content-type

header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);

// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';

// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);

// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

[!--infotagslink--]

相关文章