本文整理汇总了PHP中imagecolorresolvealpha函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorresolvealpha函数的具体用法?PHP imagecolorresolvealpha怎么用?PHP imagecolorresolvealpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorresolvealpha函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: zbx_colormix
/**
* Calculate new color based on bg/fg colors and transparency index
*
* @param resource $image image reference
* @param array $bgColor background color, array of RGB
* @param array $fgColor foreground color, array of RGB
* @param float $alpha transparency index in range of 0-1, 1 returns unchanged fgColor color
*
* @return array new color
*/
function zbx_colormix($image, $bgColor, $fgColor, $alpha)
{
$r = $bgColor[0] + ($fgColor[0] - $bgColor[0]) * $alpha;
$g = $bgColor[1] + ($fgColor[1] - $bgColor[1]) * $alpha;
$b = $bgColor[2] + ($fgColor[2] - $bgColor[2]) * $alpha;
return imagecolorresolvealpha($image, $r, $g, $b, 0);
}
示例2: fromBlank
/**
* Creates blank image.
* @param int
* @param int
* @param array
* @return self
*/
public static function fromBlank($width, $height, $color = NULL)
{
if (!extension_loaded('gd')) {
throw new Exception('PHP extension GD is not loaded.');
}
$width = (int) $width;
$height = (int) $height;
if ($width < 1 || $height < 1) {
throw new InvalidArgumentException('Image width and height must be greater than zero.');
}
$image = imagecreatetruecolor($width, $height);
if (is_array($color)) {
$color += ['alpha' => 0];
$color = imagecolorresolvealpha($image, $color['red'], $color['green'], $color['blue'], $color['alpha']);
imagealphablending($image, FALSE);
imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $color);
imagealphablending($image, TRUE);
}
return new static($image);
}
示例3: __construct
/**
* Возвращает новый экземпляр GDImage
* @param string $source Путь к исходному файлу. NULL - создание пустого изображения
* @param Size $s Размер изображения. NULL - использовать размеры исходного файла
* @param int $resizeMode Режим изменения размера. Используется, если $s не совпадает с размерами исходного изображения
* @throws GDException
*/
function __construct($source = NULL, Size $s = NULL, $resizeMode = self::RESIZE_FIT)
{
$s !== NULL or $s = new Size(100, 100);
if (!empty($source)) {
$this->source = (string) $source;
if (!($sizes = @getimagesize($source))) {
throw new GDException('Файл не является допустимым форматом изображения.');
}
list($type, $subtype) = explode('/', $sizes['mime']);
if ($type != 'image') {
throw new GDException('Файл не является допустимым форматом изображения.');
}
switch ($subtype) {
case 'gif':
$this->handle = @imagecreatefromgif($source);
break;
case 'jpeg':
$this->handle = @imagecreatefromjpeg($source);
break;
case 'png':
$this->handle = @imagecreatefrompng($source);
break;
default:
throw new GDException('Файл не является допустимым форматом изображения.');
}
if ($this->handle === FALSE) {
$this->handle = NULL;
throw new GDException('Невозможно инициализировать GD поток');
}
$this->format = (string) $subtype;
if ($s !== NULL) {
$this->size($s, $resizeMode);
}
} else {
if (($this->handle = @imagecreatetruecolor($s->width, $s->height)) === FALSE) {
$this->handle = NULL;
throw new GDException('Невозможно инициализировать GD поток');
}
imagefill($this->handle, 0, 0, imagecolorresolvealpha($this->handle, 0, 0, 0, 127));
}
}
示例4: GetDarkColorIndex
protected function GetDarkColorIndex($color)
{
list($r, $g, $b, $a) = $color;
$r = max(0, $r - 0x30);
$g = max(0, $g - 0x30);
$b = max(0, $b - 0x30);
return imagecolorresolvealpha($this->img, $r, $g, $b, $a);
}
示例5: Allocate
function Allocate($aColor)
{
list($r, $g, $b) = $this->color($aColor);
if ($GLOBALS['gd2'] == true) {
return imagecolorresolvealpha($this->img, $r, $g, $b, 0);
} else {
$index = imagecolorexact($this->img, $r, $g, $b);
if ($index == -1) {
$index = imagecolorallocate($this->img, $r, $g, $b);
if (USE_APPROX_COLORS && $index == -1) {
$index = imagecolorresolve($this->img, $r, $g, $b);
}
}
return $index;
}
}
示例6: __call
/**
* Call to undefined method.
*
* @param string method name
* @param array arguments
* @return mixed
* @throws Nette\MemberAccessException
*/
public function __call($name, $args)
{
$function = 'image' . $name;
if (!function_exists($function)) {
return parent::__call($name, $args);
}
foreach ($args as $key => $value) {
if ($value instanceof self) {
$args[$key] = $value->getImageResource();
} elseif (is_array($value) && isset($value['red'])) {
// rgb
$args[$key] = imagecolorallocatealpha($this->image, $value['red'], $value['green'], $value['blue'], $value['alpha']) ?: imagecolorresolvealpha($this->image, $value['red'], $value['green'], $value['blue'], $value['alpha']);
}
}
array_unshift($args, $this->image);
$res = $function(...$args);
return is_resource($res) && get_resource_type($res) === 'gd' ? $this->setImageResource($res) : $res;
}
示例7: Allocate
function Allocate($aColor, $aAlpha = 0.0)
{
list($r, $g, $b, $a) = $this->color($aColor);
if ($a > 0) {
$aAlpha = $a;
}
if ($aAlpha < 0 || $aAlpha > 1) {
JpGraphError::RaiseL(25080);
}
return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127));
}
示例8: header
<?php
header('content-type:image/jpeg');
//在白色背景上绘制一个椭圆
$image = imagecreatetruecolor(150, 150);
$white = imagecolorallocate($image, 255, 255, 255);
imagealphablending($image, false);
imagefilledrectangle($image, 0, 0, 150, 150, $white);
$red = imagecolorresolvealpha($image, 255, 50, 0, 50);
imagefilledellipse($image, 75, 75, 80, 63, $red);
imagejpeg($image);
imagedestroy($image);
示例9: print_r
print_r(imagecolorsforindex($im, $c));
// with alpha
$im = imagecreatetruecolor(5, 5);
$c = imagecolorclosestalpha($im, 255, 0, 255, 100);
printf("%X\n", $c);
imagedestroy($im);
$im = imagecreate(5, 5);
$c = imagecolorclosestalpha($im, 255, 0, 255, 100);
print_r(imagecolorsforindex($im, $c));
imagedestroy($im);
$im = imagecreate(5, 5);
imagecolorallocatealpha($im, 255, 0, 255, 1);
$c = imagecolorclosestalpha($im, 255, 0, 255, 1);
print_r(imagecolorsforindex($im, $c));
imagedestroy($im);
$im = imagecreate(5, 5);
for ($i = 0; $i < 255; $i++) {
imagecolorresolvealpha($im, $i, 0, 0, 1);
}
$c = imagecolorclosestalpha($im, 255, 0, 0, 1);
print_r(imagecolorsforindex($im, $c));
$im = imagecreate(5, 5);
for ($i = 0; $i < 256; $i++) {
if ($i == 246) {
imagecolorallocatealpha($im, $i, 10, 10, 1);
} else {
imagecolorallocatealpha($im, $i, 0, 0, 100);
}
}
$c = imagecolorclosestalpha($im, 255, 10, 10, 1);
print_r(imagecolorsforindex($im, $c));
示例10: Allocate
function Allocate($aImg, $aColor, $aAlpha = 0.0)
{
$res = $this->Color($aColor);
if ($res === false) {
return false;
}
list($r, $g, $b, $a) = $res;
if ($a > 0) {
$aAlpha = $a;
}
if ($aAlpha < 0 || $aAlpha > 1) {
return false;
}
return imagecolorresolvealpha($aImg, $r, $g, $b, round($aAlpha * 127));
}
示例11: resolve
public function resolve($rgb = '')
{
if (!!is_string($rgb)) {
Error::set(lang('Error', 'stringParameter', '1.(rgb)'));
return false;
}
$rgb = explode('|', $rgb);
$red = isset($rgb[0]) ? $rgb[0] : 0;
$green = isset($rgb[1]) ? $rgb[1] : 0;
$blue = isset($rgb[2]) ? $rgb[2] : 0;
$alpha = isset($rgb[3]) ? $rgb[3] : 0;
return imagecolorresolvealpha($this->canvas, $red, $green, $blue, $alpha);
}
示例12: render
/**
* Apply tools to image.
*
* This function scan for mask color and closes colors position, grab color
* at found the position on sample image, then set the pixel color at the same
* position on destination image.
*
* @return bool|PEAR_Error TRUE on success or PEAR_Error on failure.
* @access private
* @see Image_Tools_Mask::_getNearestColors()
*/
function render()
{
if (!Image_Tools::isGDImageResource($this->_maskImage)) {
return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_maskImage');
}
if (!Image_Tools::isGDImageResource($this->_sampleImage)) {
return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_sampleImage');
}
if (!Image_Tools::isGDImageResource($this->resultImage)) {
return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage');
}
$maskWidth = imagesx($this->_maskImage);
$maskHeight = imagesy($this->_maskImage);
$sampleWidth = imagesx($this->_sampleImage);
$sampleHeight = imagesy($this->_sampleImage);
if ($this->options['antialias']) {
$closesColors = $this->_getNearestColors();
} else {
$closesColors = array($this->options['maskColor']);
}
imagealphablending($this->resultImage, true);
// scan for mask color or closes colors position
for ($x = 0; $x < $maskWidth; $x++) {
for ($y = 0; $y < $maskHeight; $y++) {
if ($x >= $sampleWidth || $y >= $sampleHeight) {
continue;
}
// grab color at x, y and convert to hex color format
$index = imagecolorat($this->_maskImage, $x, $y);
$maskRGBA = imagecolorsforindex($this->_maskImage, $index);
$maskColor = Image_Color::rgb2hex(array_values($maskRGBA));
// check color in closes colors collection
if (in_array($maskColor, $closesColors)) {
// grab color at x, y from sample image
$index = imagecolorat($this->_sampleImage, $x, $y);
$sampleRGBA = imagecolorsforindex($this->_sampleImage, $index);
// allocate color on destination image
$color = imagecolorresolvealpha($this->resultImage, $sampleRGBA['red'], $sampleRGBA['green'], $sampleRGBA['blue'], $sampleRGBA['alpha']);
// set a pixel color at destination image
imagesetpixel($this->resultImage, $x, $y, $color);
}
}
}
return true;
}
示例13: imagecolorresolve
} else {
imagecolorresolve($im, $i, 0, 0);
}
}
$c = imagecolorresolve($im, 255, 10, 10);
print_r(imagecolorsforindex($im, $c));
// with alpha
$im = imagecreatetruecolor(5, 5);
$c = imagecolorresolvealpha($im, 255, 0, 255, 100);
printf("%X\n", $c);
imagedestroy($im);
$im = imagecreate(5, 5);
$c = imagecolorresolvealpha($im, 255, 0, 255, 100);
print_r(imagecolorsforindex($im, $c));
imagedestroy($im);
$im = imagecreate(5, 5);
for ($i = 0; $i < 255; $i++) {
imagecolorresolvealpha($im, $i, 0, 0, 1);
}
$c = imagecolorresolvealpha($im, 255, 0, 0, 1);
print_r(imagecolorsforindex($im, $c));
$im = imagecreate(5, 5);
for ($i = 0; $i < 256; $i++) {
if ($i == 246) {
imagecolorresolvealpha($im, $i, 10, 10, 1);
} else {
imagecolorresolvealpha($im, $i, 0, 0, 100);
}
}
$c = imagecolorresolvealpha($im, 255, 10, 10, 0);
print_r(imagecolorsforindex($im, $c));
示例14: generate
//.........这里部分代码省略.........
$sys[4] = $row2['sys_id'];
$sys[5] = $row2['sys_name'];
$sys[6] = $row2['sys_sec'];
$fp = fopen($regioncache . ".txt", "r");
// getting offset data from file
$maxx = fgets($fp);
$minx = fgets($fp);
$maxz = fgets($fp);
$minz = fgets($fp);
fclose($fp);
$dx = abs($maxx - $minx);
$dz = abs($maxz - $minz);
$xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2));
$yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2));
$px = round($this->offset_ + ($sys[0] - $minx) * $xscale);
$py = round($this->offset_ + ($sys[1] - $minz) * $yscale);
if ($kills == 1) {
// If there is only one kill we use normal highlight color
$ratio = 1;
if (config::get('map_act_cl_hl')) {
$hscolor = explode(",", config::get('map_act_cl_hl'));
$color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]);
} else {
$color = imagecolorallocate($img, '255', '209', '57');
}
} else {
//more then one kill...
$ratio = $kills + 5;
// ...then we add a bit to the ratio
if (config::get('map_act_cl_hl2')) {
// Set the color to Highlight 2 and the sphere color with alpha
$hscolor = explode(",", config::get('map_act_cl_hl2'));
$color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]);
$color4 = imagecolorresolvealpha($img, $hscolor[0], $hscolor[1], $hscolor[2], '117');
} else {
$color = imagecolorallocate($img, '255', '0', '0');
$color4 = imagecolorresolvealpha($img, 255, 0, 0, 117);
}
}
if ($ratio > 100) {
//now we limit the max-size of the sphere so it doesnt grow to big
$ratio = 100;
}
imagefilledellipse($img, $px, $py, $ratio, $ratio, $color4);
//paint the sphere -- can not use AA function cause it doesnt work with alpha
imagefilledellipseaa($img, $px, $py, 6, 6, $color);
// use AA function to paint the system dot
if ($ratio > 10) {
// extend the sphere
$ratio2 = $ratio - 10;
imagefilledellipse($img, $px, $py, $ratio2, $ratio2, $color4);
}
if ($ratio > 20) {
// add another inner layer to the sphere, if it gets big enough
$ratio3 = $ratio - 20;
imagefilledellipse($img, $px, $py, $ratio3, $ratio3, $color4);
}
if ($paint_name == 1) {
$tlen = 5 * strlen($sys[5]);
if ($px + $tlen > $this->imgwidth_ - 20) {
$sx = $px - $tlen;
} else {
$sx = $px + 5;
}
if ($py + 5 > $this->imgheight_ - 20) {
$sy = $py - 5;
示例15: resolve
public function resolve(string $rgb) : int
{
$rgb = explode('|', $rgb);
$red = isset($rgb[0]) ? $rgb[0] : 0;
$green = isset($rgb[1]) ? $rgb[1] : 0;
$blue = isset($rgb[2]) ? $rgb[2] : 0;
$alpha = isset($rgb[3]) ? $rgb[3] : 0;
return imagecolorresolvealpha($this->canvas, $red, $green, $blue, $alpha);
}