本文整理汇总了PHP中imagecolorclosestalpha函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorclosestalpha函数的具体用法?PHP imagecolorclosestalpha怎么用?PHP imagecolorclosestalpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorclosestalpha函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Method to apply a filter to an image resource.
*
* @param array $options An array of options for the filter.
*
* @return void
*
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function execute(array $options = array())
{
// Verify that image filter support for PHP is available.
if (!function_exists('imagefilter')) {
throw new RuntimeException('The imagefilter function for PHP is not available.');
}
if (empty($options)) {
throw new InvalidArgumentException('No valid amount was given. Expected float.');
}
$value = (int) array_shift($options);
if ($value == 0) {
$value = 128;
}
$width = imagesx($this->handle);
$height = imagesy($this->handle);
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$index = imagecolorat($this->handle, $x, $y);
$rgb = imagecolorsforindex($this->handle, $index);
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
$a = $rgb['alpha'];
$v = round(($r + $g + $b) / 3) >= $value ? 255 : 0;
$color = imagecolorallocatealpha($this->handle, $v, $v, $v, $a);
if ($color === false) {
$color = imagecolorclosestalpha($this->handle, $v, $v, $v, $a);
}
imagesetpixel($this->handle, $x, $y, $color);
}
}
}
开发者ID:knigherrant,项目名称:decopatio,代码行数:42,代码来源:threshold.php
示例2: getClosestColorAlpha
function getClosestColorAlpha($R, $G = null, $B = null, $A = null)
{
if (is_array($R)) {
return imagecolorclosestalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']);
} else {
return imagecolorclosestalpha($this->handle, $R, $G, $B, $A);
}
}
开发者ID:BackupTheBerlios,项目名称:haxoo-svn,代码行数:8,代码来源:TrueColorImage.class.php
示例3: execute
/**
* Method to apply a filter to an image resource.
*
* @param array $options An array of options for the filter.
*
* @return void
*
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function execute(array $options = array())
{
// Verify that image filter support for PHP is available.
if (!function_exists('imagefilter')) {
throw new RuntimeException('The imagefilter function for PHP is not available.');
}
if (empty($options)) {
throw new InvalidArgumentException('No valid amount was given. Expected float.');
}
// percent value
$value = (int) array_shift($options);
if ($value == 0) {
return true;
}
$value = $value / 100;
// set max / min
$value = max(-1, min(1, $value));
// get width / height
$width = imagesx($this->handle);
$height = imagesy($this->handle);
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$index = imagecolorat($this->handle, $x, $y);
$rgb = imagecolorsforindex($this->handle, $index);
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
$a = $rgb['alpha'];
$average = ($r + $g + $b) / 3;
$r += round(($r - $average) * $value);
$g += round(($g - $average) * $value);
$b += round(($b - $average) * $value);
// clamp
$r = min(255, max(0, $r));
$g = min(255, max(0, $g));
$b = min(255, max(0, $b));
$color = imagecolorallocatealpha($this->handle, $r, $g, $b, $a);
if ($color === false) {
$color = imagecolorclosestalpha($this->handle, $r, $g, $b, $a);
}
imagesetpixel($this->handle, $x, $y, $color);
}
}
}
开发者ID:adjaika,项目名称:J3Base,代码行数:54,代码来源:saturate.php
示例4: execute
/**
* Method to apply a filter to an image resource.
*
* @param array $options An array of options for the filter.
*
* @return void
*
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function execute(array $options = array())
{
// Verify that image filter support for PHP is available.
if (!function_exists('imagefilter')) {
throw new RuntimeException('The imagefilter function for PHP is not available.');
}
if (empty($options)) {
throw new InvalidArgumentException('No valid amount was given. Expected float.');
}
$amount = (int) array_shift($options);
// 39, 14, -36
/*if (imagefilter($this->handle, IMG_FILTER_GRAYSCALE)) {
imagefilter($this->handle, IMG_FILTER_COLORIZE, 39, 14, -36);
}*/
// Microsoft Sepia
$width = imagesx($this->handle);
$height = imagesy($this->handle);
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$index = imagecolorat($this->handle, $x, $y);
$rgb = imagecolorsforindex($this->handle, $index);
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
$a = $rgb['alpha'];
$v1 = $r * 0.393 + $g * 0.769 + $b * 0.189;
$v2 = $r * 0.349 + $g * 0.6860000000000001 + $b * 0.168;
$v3 = $r * 0.272 + $g * 0.534 + $b * 0.131;
// clamp
$v1 = min(255, max(0, $v1));
$v2 = min(255, max(0, $v2));
$v3 = min(255, max(0, $v3));
$color = imagecolorallocatealpha($this->handle, $v1, $v2, $v3, $a);
if ($color === false) {
$color = imagecolorclosestalpha($this->handle, $v1, $v2, $v3, $a);
}
imagesetpixel($this->handle, $x, $y, $color);
}
}
}
开发者ID:knigherrant,项目名称:decopatio,代码行数:50,代码来源:sepia.php
示例5: imageconvolution
/**
* imageconvolution() does not appear in PHP with non-bundled GD libraries.
* Because this is written in PHP, it is much slower than the bundled version.
*
* @param resource $image an image resource
* @param array $matrix a 3x3 matrix: an array of three arrays of three floats
* @param float $div the divisor of the result of the convolution, used for normalization
* @param float $offset color offset
* @return bool true on success or false on failure
* @access private
*/
private function imageconvolution($image, $matrix, $div, $offset)
{
if ($image == null) {
return 0;
}
$srcW = imagesx($image);
$srcH = imagesy($image);
$pxl = array(1, 1);
$tmp = imagecreatetruecolor($srcW, $srcH);
imagealphablending($tmp, false);
imagealphablending($image, false);
imagecopy($tmp, $image, 0, 0, 0, 0, $srcW, $srcH);
if ($tmp == null) {
return 0;
}
for ($y = 0; $y < $srcH; ++$y) {
for ($x = 0; $x < $srcW; ++$x) {
$newR = $newG = $newB = 0;
$alpha = imagecolorat($tmp, @$pxl[0], @$pxl[1]);
$newA = $alpha >> 24;
for ($j = 0; $j < 3; ++$j) {
$yv = min(max($y - 1 + $j, 0), $srcH - 1);
for ($i = 0; $i < 3; ++$i) {
$pxl = array(min(max($x - 1 + $i, 0), $srcW - 1), $yv);
$rgb = imagecolorat($tmp, $pxl[0], $pxl[1]);
$newR += ($rgb >> 16 & 0xff) * $matrix[$j][$i];
$newG += ($rgb >> 8 & 0xff) * $matrix[$j][$i];
$newB += ($rgb & 0xff) * $matrix[$j][$i];
$newA += ((0x7f000000 & $rgb) >> 24) * $matrix[$j][$i];
}
}
$newR = $newR / $div + $offset;
$newG = $newG / $div + $offset;
$newB = $newB / $div + $offset;
$newA = $newA / $div + $offset;
$newR = $newR > 255 ? 255 : ($newR < 0 ? 0 : $newR);
$newG = $newG > 255 ? 255 : ($newG < 0 ? 0 : $newG);
$newB = $newB > 255 ? 255 : ($newB < 0 ? 0 : $newB);
$newA = $newA > 127 ? 127 : ($newA < 0 ? 0 : $newA);
$newCol = imagecolorallocatealpha($image, (int) $newR, (int) $newG, (int) $newB, (int) $newA);
if ($newCol == -1) {
$newCol = imagecolorclosestalpha($image, (int) $newR, (int) $newG, (int) $newB, (int) $newA);
}
if ($y >= 0 && $y < $srcH) {
imagesetpixel($image, $x, $y, $newCol);
}
}
}
imagedestroy($tmp);
return 1;
}
开发者ID:janisto,项目名称:ImageUtil,代码行数:62,代码来源:ImageUtil.php
示例6: imageconvolution
function imageconvolution($src, $filter, $filter_div, $offset)
{
if ($src == NULL) {
return false;
}
$sx = imagesx($src);
$sy = imagesy($src);
$srcback = imagecreatetruecolor($sx, $sy);
imagecopy($srcback, $src, 0, 0, 0, 0, $sx, $sy);
if ($srcback == NULL) {
return 0;
}
for ($y = 0; $y < $sy; ++$y) {
for ($x = 0; $x < $sx; ++$x) {
$new_r = $new_g = $new_b = 0;
$alpha = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_a = $alpha >> 24;
for ($j = 0; $j < 3; ++$j) {
$yv = min(max($y - 1 + $j, 0), $sy - 1);
for ($i = 0; $i < 3; ++$i) {
$pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv);
$rgb = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_r += ($rgb >> 16 & 0xff) * $filter[$j][$i];
$new_g += ($rgb >> 8 & 0xff) * $filter[$j][$i];
$new_b += ($rgb & 0xff) * $filter[$j][$i];
}
}
$new_r = $new_r / $filter_div + $offset;
$new_g = $new_g / $filter_div + $offset;
$new_b = $new_b / $filter_div + $offset;
$new_r = $new_r > 255 ? 255 : ($new_r < 0 ? 0 : $new_r);
$new_g = $new_g > 255 ? 255 : ($new_g < 0 ? 0 : $new_g);
$new_b = $new_b > 255 ? 255 : ($new_b < 0 ? 0 : $new_b);
$new_pxl = imagecolorallocatealpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
if ($new_pxl == -1) {
$new_pxl = imagecolorclosestalpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
}
if ($y >= 0 && $y < $sy) {
imagesetpixel($src, $x, $y, $new_pxl);
}
}
}
imagedestroy($srcback);
return true;
}
开发者ID:raffpaquin,项目名称:Gregory,代码行数:45,代码来源:ImageResizer.php
示例7: imageconvolution
function imageconvolution($src, $filter, $filter_div, $offset)
{
if ($src == NULL) {
return 0;
}
$sx = imagesx($src);
$sy = imagesy($src);
$srcback = imagecreatetruecolor($sx, $sy);
imagecopy($srcback, $src, 0, 0, 0, 0, $sx, $sy);
if ($srcback == NULL) {
return 0;
}
// Fix here
// $pxl array was the problem so simply set it with very low values
$pxl = array(1, 1);
// this little fix worked for me as the undefined array threw out errors
for ($y = 0; $y < $sy; ++$y) {
for ($x = 0; $x < $sx; ++$x) {
$new_r = $new_g = $new_b = 0;
$alpha = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_a = $alpha >> 24;
for ($j = 0; $j < 3; ++$j) {
$yv = min(max($y - 1 + $j, 0), $sy - 1);
for ($i = 0; $i < 3; ++$i) {
$pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv);
$rgb = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_r += ($rgb >> 16 & 0xff) * $filter[$j][$i];
$new_g += ($rgb >> 8 & 0xff) * $filter[$j][$i];
$new_b += ($rgb & 0xff) * $filter[$j][$i];
}
}
$new_r = $new_r / $filter_div + $offset;
$new_g = $new_g / $filter_div + $offset;
$new_b = $new_b / $filter_div + $offset;
$new_r = $new_r > 255 ? 255 : ($new_r < 0 ? 0 : $new_r);
$new_g = $new_g > 255 ? 255 : ($new_g < 0 ? 0 : $new_g);
$new_b = $new_b > 255 ? 255 : ($new_b < 0 ? 0 : $new_b);
$new_pxl = imagecolorallocatealpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
if ($new_pxl == -1) {
$new_pxl = imagecolorclosestalpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
}
if ($y >= 0 && $y < $sy) {
imagesetpixel($src, $x, $y, $new_pxl);
}
}
}
imagedestroy($srcback);
return 1;
}
开发者ID:Andreyjktl,项目名称:Cotonti,代码行数:49,代码来源:functions.php
示例8: getColorIndex
public function getColorIndex($img, $color)
{
// Now set the destination pixel.
$colorIndex = imagecolorallocatealpha($img, $color['red'], $color['green'], $color['blue'], $color['alpha']);
// If we failed to allocate the color, try to find the already allocated color
// that is closest to what we want.
if ($colorIndex === false) {
$colorIndex = imagecolorclosestalpha($img, $color['red'], $color['green'], $color['blue'], $color['alpha']);
}
return $colorIndex;
}
开发者ID:manticorp,项目名称:BlendableImage,代码行数:11,代码来源:Blender.php
示例9: imagefilter
function imagefilter($source, $var, $arg1 = null, $arg2 = null, $arg3 = null)
{
#define('IMAGE_FILTER_NEGATE',0);
#define('IMAGE_FILTER_GRAYSCALE',0);
#define('IMAGE_FILTER_BRIGHTNESS',2);
#define('IMAGE_FILTER_CONTRAST',3);
#define('IMAGE_FILTER_COLORIZE',4);
#define('IMAGE_FILTER_EDGEDETECT',5);
#define('IMAGE_FILTER_EMBOSS',6);
#define('IMAGE_FILTER_GAUSSIAN_BLUR',7);
#define('IMAGE_FILTER_SELECTIVE_BLUR',8);
#define('IMAGE_FILTER_MEAN_REMOVAL',9);
#define('IMAGE_FILTER_SMOOTH',10);
$max_y = imagesy($source);
$max_x = imagesx($source);
switch ($var) {
case 0:
$y = 0;
while ($y < $max_y) {
$x = 0;
while ($x < $max_x) {
$rgb = imagecolorat($source, $x, $y);
$r = 255 - ($rgb >> 16 & 0xff);
$g = 255 - ($rgb >> 8 & 0xff);
$b = 255 - ($rgb & 0xff);
$a = $rgb >> 24;
$new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
if ($new_pxl == false) {
$new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
}
imagesetpixel($source, $x, $y, $new_pxl);
++$x;
}
++$y;
}
return true;
break;
case 1:
$y = 0;
while ($y < $max_y) {
$x = 0;
while ($x < $max_x) {
$rgb = imagecolorat($source, $x, $y);
$a = $rgb >> 24;
$r = ($rgb >> 16 & 0xff) * 0.299 + ($rgb >> 8 & 0xff) * 0.587 + ($rgb & 0xff) * 0.114;
$new_pxl = imagecolorallocatealpha($source, $r, $r, $r, $a);
if ($new_pxl == false) {
$new_pxl = imagecolorclosestalpha($source, $r, $r, $r, $a);
}
imagesetpixel($source, $x, $y, $new_pxl);
++$x;
}
++$y;
}
return true;
break;
case 2:
$y = 0;
while ($y < $max_y) {
$x = 0;
while ($x < $max_x) {
$rgb = imagecolorat($source, $x, $y);
$r = ($rgb >> 16 & 0xff) + $arg1;
$g = ($rgb >> 8 & 0xff) + $arg1;
$b = ($rgb & 0xff) + $arg1;
$a = $rgb >> 24;
$r = $r > 255 ? 255 : ($r < 0 ? 0 : $r);
$g = $g > 255 ? 255 : ($g < 0 ? 0 : $g);
$b = $b > 255 ? 255 : ($b < 0 ? 0 : $b);
$new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
if ($new_pxl == false) {
$new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
}
imagesetpixel($source, $x, $y, $new_pxl);
++$x;
}
++$y;
}
return true;
break;
case 3:
$contrast = pow((100 - $arg1) / 100, 2);
$y = 0;
while ($y < $max_y) {
$x = 0;
while ($x < $max_x) {
$rgb = imagecolorat($source, $x, $y);
$a = $rgb >> 24;
$r = ((($rgb >> 16 & 0xff) / 255 - 0.5) * $contrast + 0.5) * 255;
$g = ((($rgb >> 8 & 0xff) / 255 - 0.5) * $contrast + 0.5) * 255;
$b = ((($rgb & 0xff) / 255 - 0.5) * $contrast + 0.5) * 255;
$r = $r > 255 ? 255 : ($r < 0 ? 0 : $r);
$g = $g > 255 ? 255 : ($g < 0 ? 0 : $g);
$b = $b > 255 ? 255 : ($b < 0 ? 0 : $b);
$new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
if ($new_pxl == false) {
$new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
}
imagesetpixel($source, $x, $y, $new_pxl);
++$x;
//.........这里部分代码省略.........
开发者ID:BGCX067,项目名称:falados-secondlife-svn-to-git,代码行数:101,代码来源:gdbundle.inc.php
示例10: closest
public function closest(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 imagecolorclosestalpha($this->canvas, $red, $green, $blue, $alpha);
}
开发者ID:znframework,项目名称:znframework,代码行数:9,代码来源:InternalGD.php
示例11: array
$AF_colorize_RGB = array(base_convert(substr($colorize, 0, 2), 16, 10), base_convert(substr($colorize, 2, 2), 16, 10), base_convert(substr($colorize, 4, 2), 16, 10));
$x = 0;
while ($x < $src_w) {
$y = 0;
while ($y < $src_h) {
$rgb = imagecolorat($src_img, $x, $y);
$r = ($rgb >> 16 & 0xff) + $AF_colorize_RGB[0];
$g = ($rgb >> 8 & 0xff) + $AF_colorize_RGB[1];
$b = ($rgb & 0xff) + $AF_colorize_RGB[2];
$a = $rgb >> 24;
$r = $r > 255 ? 255 : ($r < 0 ? 0 : $r);
$g = $g > 255 ? 255 : ($g < 0 ? 0 : $g);
$b = $b > 255 ? 255 : ($b < 0 ? 0 : $b);
$new_pxl = imagecolorallocatealpha($src_img, $r, $g, $b, $a);
if ($new_pxl == false) {
$new_pxl = imagecolorclosestalpha($src_img, $r, $g, $b, $a);
}
imagesetpixel($src_img, $x, $y, $new_pxl);
++$y;
}
++$x;
}
}
$dst_img = imagecreatetruecolor($dst_w, $dst_h);
$AF_bgcolor_RGB = array(base_convert(substr($bgcolor, 0, 2), 16, 10), base_convert(substr($bgcolor, 2, 2), 16, 10), base_convert(substr($bgcolor, 4, 2), 16, 10));
$AF_BGCOLOR = imagecolorallocatealpha($dst_img, $AF_bgcolor_RGB[0], $AF_bgcolor_RGB[1], $AF_bgcolor_RGB[2], 127);
imagefill($dst_img, 0, 0, $AF_BGCOLOR);
imagecopyresampled($dst_img, $src_img, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
header('Content-type: image/png');
imagesavealpha($dst_img, true);
imagepng($dst_img, NULL, 0);
开发者ID:magev88,项目名称:admirorgallery,代码行数:31,代码来源:AF_gd_stream.php
示例12: text_watermark
//.........这里部分代码省略.........
switch ($this->wm_hor_alignment) {
case "L":
break;
case "R":
//if ($this->wm_use_drop_shadow)
//$x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text));
//$x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text));
//AG_EDIT
if ($this->wm_use_drop_shadow) {
$x_shad += $this->orig_width - $fontwidth * mb_strlen($this->wm_text);
}
$x_axis += $this->orig_width - $fontwidth * mb_strlen($this->wm_text);
break;
case "C":
//if ($this->wm_use_drop_shadow)
//$x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
//$x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2);
//AG_EDIT
if ($this->wm_use_drop_shadow) {
$x_shad += floor(($this->orig_width - $fontwidth * mb_strlen($this->wm_text)) / 2);
}
$x_axis += floor(($this->orig_width - $fontwidth * mb_strlen($this->wm_text)) / 2);
break;
}
}
// Add the text to the source image
if ($this->wm_use_truetype) {
//Ширина прямоугольника с текстом
$XY = imageftbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text);
$Textwidth = $XY[2] - $XY[0];
//Проверка или прямоугольник не больше изображения с отступом от краем
if ($Textwidth + $this->wm_shadow_distance > $this->orig_width - $x_axis - $this->orig_width / 20) {
//Вычисляем максимально возможный размер шрифта через пропорцию
$this->wm_font_size = floor(($this->orig_width - $x_axis - $this->orig_width / 20) * $this->wm_font_size / ($Textwidth + $this->wm_shadow_distance));
//Узнаем ширину прямоугольника с текстом
$XY = imageftbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text);
$Textwidth = $XY[2] - $XY[0];
}
//Ширина создаваемого изображения с водяным знаком учитывая тень
$TW = $Textwidth + $this->wm_shadow_distance;
//Высота создаваемого изображения с водяным знаком + 50% от величины шрифта + учитывание тени
$TH = floor($this->wm_font_size + $this->wm_font_size / 2 + $this->wm_shadow_distance);
//Отступ от верхнего угла для imagettftext навно размеру шрифта + 20% - отступ тени
$TY = floor($this->wm_font_size + $this->wm_font_size / 7 - $this->wm_shadow_distance);
//После этих манипуляций текст не должен вылазить на пределы создаваемого изображения водяного знака
$TIMG = imagecreatetruecolor($TW, $TH);
imagealphablending($TIMG, TRUE);
imagesavealpha($TIMG, true);
//Цвет текста без прозрачности и цвет тени с прозрачность <> 40%
$txt_color = imagecolorallocatealpha($TIMG, $R1, $G1, $B1, 0);
$drp_color = imagecolorallocatealpha($TIMG, $R2, $G2, $B2, 50);
$BGcolor = imagecolorclosestalpha($TIMG, 255, 255, 255, 127);
imagefill($TIMG, 0, 0, $BGcolor);
imagealphablending($TIMG, TRUE);
//Наложение текстов на изображение
imagettftext($TIMG, $this->wm_font_size, 0, $this->wm_shadow_distance, $TY + $this->wm_shadow_distance, $drp_color, $this->wm_font_path, $this->wm_text);
imagettftext($TIMG, $this->wm_font_size, 0, 0, $TY, $txt_color, $this->wm_font_path, $this->wm_text);
//Проверка выравнивания водяного знака по оси Y
switch ($this->wm_vrt_alignment) {
case "T":
break;
case "M":
$y_axis += floor($this->orig_height / 2 - $TH / 2);
break;
case "B":
$y_axis += $this->orig_height - $TH;
break;
}
//Проверка выравнивания водяного знака по оси X
switch ($this->wm_hor_alignment) {
case "L":
$x_axis += $this->orig_width / 40;
break;
case "R":
$x_axis += floor($this->orig_width - $TW - $this->orig_width / 40);
break;
case "C":
$x_axis += floor(($this->orig_width - $TW) / 2);
break;
}
if ($this->wm_opacity > 0 && $this->wm_opacity < 100) {
$this->filter_opacity($TIMG, $this->wm_opacity);
}
imagecopy($src_img, $TIMG, $x_axis, $y_axis, 0, 0, $TW, $TH);
imagedestroy($TIMG);
} else {
if ($this->wm_use_drop_shadow) {
imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
}
imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
}
// Output the final image
if ($this->dynamic_output == TRUE) {
$this->image_display_gd($src_img);
} else {
$this->image_save_gd($src_img);
}
imagedestroy($src_img);
return TRUE;
}
开发者ID:vitalik199415,项目名称:ozar,代码行数:101,代码来源:Image_lib.php
示例13: image_copy_merge_with_alpha
/**
* An Old but Needed function for the Actual Days of PhP
* @source http://forums.devnetwork.net/viewtopic.php?f=1&t=103330#p553333
* @author RedMonkey
* @editor Claudio Santoro
*
* "@observation Sorry of this function need to be big. Is because the simpliest approaches found in internet"
* "doesn't work as well that these approach.."
* "i know oop need small functions, but sorry"
*
* @param resource $dst Destination Allocated Image
* @param resource $src Source Allocated Image
* @param int $dst_x Destination Position X
* @param int $dst_y Destination Position Y
* @param int $src_x Source Position X
* @param int $src_y Source Position Y
* @param int $w Width
* @param int $h Height
* @param int $pct Alpha Percent
* @return null
*/
private function image_copy_merge_with_alpha($dst, $src, $dst_x = 0, $dst_y = 0, $src_x = 0, $src_y = 0, $w = 0, $h = 0, $pct = 100)
{
/* yes divide */
$pct /= 100;
/* make sure opacity level is within range before going any further */
$pct = max(min(1, $pct), 0);
/* work out if we need to bother correcting for opacity */
if ($pct < 1) {
/* we need a copy of the original to work from, only copy the cropped */
/* area of src */
$src_copy = imagecreatetruecolor($w, $h);
/* attempt to maintain alpha levels, alpha blending must be *off* */
imagealphablending($src_copy, false);
imagesavealpha($src_copy, true);
imagecopy($src_copy, $src, 0, 0, $src_x, $src_y, $w, $h);
/* we need to know the max transparency of the image */
$max_t = 0;
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
$src_c = imagecolorat($src_copy, $x, $y);
$src_a = $src_c >> 24 & 0xff;
$max_t = $src_a > $max_t ? $src_a : $max_t;
}
}
/* src has no transparency? set it to use full alpha range */
$max_t = $max_t == 0 ? 127 : $max_t;
/* $max_t is now being reused as the correction factor to apply based */
/* on the original transparency range of src */
$max_t /= 127;
/* go back through the image adjusting alpha channel as required */
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
$src_c = imagecolorat($src, $src_x + $x, $src_y + $y);
$src_a = $src_c >> 24 & 0xff;
$src_r = $src_c >> 16 & 0xff;
$src_g = $src_c >> 8 & 0xff;
$src_b = $src_c & 0xff;
/* alpha channel compensation */
$src_a = ($src_a + 127 - 127 * $pct) * $max_t;
$src_a = $src_a > 127 ? 127 : (int) $src_a;
/* get and set this pixel's adjusted RGBA colour index */
$rgba = imagecolorallocatealpha($src_copy, $src_r, $src_g, $src_b, $src_a);
/* @method /imagecolorclosestalpha returns -1 for PHP versions prior */
/* to 5.1.3 when allocation failed */
if ($rgba === false || $rgba == -1) {
$rgba = imagecolorclosestalpha($src_copy, $src_r, $src_g, $src_b, $src_a);
}
imagesetpixel($src_copy, $x, $y, $rgba);
}
}
/* call image copy passing our alpha adjusted image as src */
imagecopy($dst, $src_copy, $dst_x, $dst_y, 0, 0, $w, $h);
/* cleanup, free memory */
imagedestroy($src_copy);
return null;
}
/* still here? no opacity adjustment required so pass straight through to */
/* @method /imagecopy rather than @method /imagecopymerge to retain alpha channels */
imagecopy($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $h);
return null;
}
开发者ID:scottstamp,项目名称:habbo-camera-server,代码行数:82,代码来源:ServerCamera.php
示例14: chinese_yzimg
function chinese_yzimg($str)
{
$fnt = ROOT_PATH . "inc/font.ttf";
if (WEB_LANG == 'gb2312') {
$str = gbk2utf8($str);
}
$c = 'red';
$x = 0;
$y = 0;
$size = 11;
$image = ROOT_PATH . 'images/default/chinese_yzimg.jpg';
if (!is_file($image)) {
die('背景图片不存在');
}
$img_array = getimagesize($image);
$font_array = ImageTTFBBox($size, 0, $fnt, $str);
$font_wight = intval($font_array[2] - $font_array[0]);
$font_height = intval($font_array[3] - $font_array[5]);
$x || ($x = intval(($img_array[0] - $font_wight) / 2));
$y || ($y = intval($img_array[1] / 2 + $font_height / 2));
$im = imagecreatefromjpeg($image);
if ($c == 'blue') {
$color = imagecolorclosestalpha($im, 00, 00, 255, 20);
$color2 = imagecolorclosestalpha($im, 00, 00, 00, 98);
imagettftext($im, $size, 0, $x + 2, $y + 2, $color2, $fnt, $str);
} elseif ($c == 'white') {
$color = imagecolorclosestalpha($im, 255, 255, 255, 20);
$color2 = imagecolorclosestalpha($im, 00, 00, 00, 99);
imagettftext($im, $size, 0, $x + 2, $y + 2, $color2, $fnt, $str);
} elseif ($c == 'red') {
$color = imagecolorclosestalpha($im, 255, 00, 00, 20);
$color2 = imagecolorclosestalpha($im, 255, 255, 255, 20);
imagettftext($im, $size, 0, $x + 2, $y + 2, $color2, $fnt, $str);
} else {
$color = imagecolorclosestalpha($im, 00, 00, 00, 20);
$color2 = imagecolorclosestalpha($im, 255, 255, 255, 40);
imagettftext($im, $size, 0, $x + 2, $y + 2, $color2, $fnt, $str);
}
imagettftext($im, $size, 0, $x, $y, $color, $fnt, $str);
ImageJPEG($im);
ImageDestroy($im);
}
开发者ID:GHubgenius,项目名称:qbbj,代码行数:42,代码来源:waterimage.php
示例15: closest
public function closest($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 imagecolorclosestalpha($this->canvas, $red, $green, $blue, $alpha);
}
开发者ID:Allopa,项目名称:ZN-Framework-Starter,代码行数:13,代码来源:GD.php
示例16: WatermarkImage
function WatermarkImage(&$obj, $Params = array())
{
$file = $Params['file'];
if (!$obj || empty($file) || !file_exists($file) || !is_file($file) || !function_exists("gd_info")) {
return false;
}
$arFile = array("ext" => GetFileExtension($file));
$Params["width"] = intval(@imagesx($obj));
$Params["height"] = intval(@imagesy($obj));
$Params["coefficient"] = floatval($Params["coefficient"]);
if (!isset($Params["alpha_level"])) {
$Params["alpha_level"] = 100;
}
$Params["alpha_level"] = intval($Params["alpha_level"]) / 100;
$wmWidth = round($Params["width"] * $Params["coefficient"]);
$wmHeight = round($Params["height"] * $Params["coefficient"]);
$arFileSizeTmp = CFile::GetImageSize($file);
if (!in_array($arFileSizeTmp[2], array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_BMP))) {
return false;
}
if ($Params["fill"] == 'resize') {
$file_obj_1 = CFile::CreateImage($file, $arFileSizeTmp[2]);
$arFile["width"] = intval(imagesx($file_obj_1));
$arFile["height"] = intval(imagesy($file_obj_1));
if ($arFile["width"] > $wmWidth || $arFile["height"] > $wmHeight) {
$file_1 = $file . '_new.tmp';
CFile::ResizeImageFile($file, $file_1, array('width' => $wmWidth, 'height' => $wmHeight));
$file_obj = CFile::CreateImage($file_1, $arFileSizeTmp[2]);
@imagedestroy($file_obj_1);
} else {
$file_obj = $file_obj_1;
}
} else {
$file_obj = CFile::CreateImage($file, $arFileSizeTmp[2]);
if ($Params["fill"] == 'repeat') {
$Params["position"] = array('x' => 'top', 'y' => 'left');
}
}
if (!$file_obj) {
return false;
}
$arFile["width"] = intval(@imagesx($file_obj));
$arFile["height"] = intval(@imagesy($file_obj));
$wm_pos = array("x" => 2, "y" => 2, "width" => $arFile["width"], "height" => $arFile["height"]);
if ($Params["position"]['y'] == 'center') {
$wm_pos["y"] = intval(($Params["height"] - $wm_pos["height"]) / 2);
} elseif ($Params["position"]['y'] == 'bottom') {
$wm_pos["y"] = intval($Params["height"] - $wm_pos["height"]);
}
if ($Params["position"]['x'] == 'center') {
$wm_pos["x"] = intval(($Params["width"] - $wm_pos["width"]) / 2);
} elseif ($Params["position"]['x'] == 'right') {
$wm_pos["x"] = intval($Params["width"] - $wm_pos["width"]);
}
if ($wm_pos["y"] < 2) {
$wm_pos["y"] = 2;
}
if ($wm_pos["x"] < 2) {
$wm_pos["x"] = 2;
}
for ($y = 0; $y < $arFile["height"]; $y++) {
for ($x = 0; $x < $arFile["width"]; $x++) {
$watermark_y = $wm_pos["y"] + $y;
while (true) {
$watermark_x = $wm_pos["x"] + $x;
while (true) {
$return_color = NULL;
$watermark_alpha = $Params["alpha_level"];
$main_rgb = imagecolorsforindex($obj, imagecolorat($obj, $watermark_x, $watermark_y));
$watermark_rbg = imagecolorsforindex($file_obj, imagecolorat($file_obj, $x, $y));
if ($watermark_rbg['alpha']) {
$watermark_alpha = round((127 - $watermark_rbg['alpha']) / 127, 2);
$watermark_alpha = $watermark_alpha * $Params["alpha_level"];
}
$res = array();
foreach (array('red', 'green', 'blue', 'alpha') as $k) {
$res[$k] = round($main_rgb[$k] * (1 - $watermark_alpha) + $watermark_rbg[$k] * $watermark_alpha);
}
$return_color = imagecolorexactalpha($obj, $res["red"], $res["green"], $res["blue"], $res["alpha"]);
if ($return_color == -1) {
$return_color = imagecolorallocatealpha($obj, $res["red"], $res["green"], $res["blue"], $res["alpha"]);
if ($return_color == -1) {
$return_color = imagecolorclosestalpha($obj, $res["red"], $res["green"], $res["blue"], $res["alpha"]);
}
}
imagesetpixel($obj, $watermark_x, $watermark_y, $return_color);
$watermark_x += $arFile["width"];
if ($Params["fill"] != 'repeat' || $watermark_x > $Params["width"]) {
break;
}
}
$watermark_y += $arFile["height"];
if ($Params["fill"] != 'repeat' || $watermark_y > $Params["height"]) {
break;
}
}
}
}
@imagedestroy($file_obj);
return true;
//.........这里部分代码省略.........
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:101,代码来源:file.php
示例17: blend
//.........这里部分代码省略.........
$destColor = array('red' => intval($baseColor['red'] > 127.5 ? $topColor['red'] * ((255.0 - $baseColor['red']) / 127.5) + ($baseColor['red'] - (255.0 - $baseColor['red'])) : $topColor['red'] * ($baseColor['red'] / 127.5)), 'green' => intval($baseColor['green'] > 127.5 ? $topColor['green'] * ((255.0 - $baseColor['green']) / 127.5) + ($baseColor['green'] - (255.0 - $baseColor['green'])) : $topColor['green'] * ($baseColor['green'] / 127.5)), 'blue' => intval($baseColor['blue'] > 127.5 ? $topColor['blue'] * ((255.0 - $baseColor['blue']) / 127.5) + ($baseColor['blue'] - (255.0 - $baseColor['blue'])) : $topColor['blue'] * ($baseColor['blue'] / 127.5)), 'alpha' => intval($topColor['alpha']));
break;
case 'softLight':
$destColor = array('red' => intval(round($topColor['red'] / 255.0 < 0.5 ? (2 * ($baseColor['red'] / 255.0) * ($topColor['red'] / 255.0) + $baseColor['red'] / 255.0 * ($baseColor['red'] / 255.0) * (1 - 2 * ($topColor['red'] / 255.0))) * 255.0 : (2 * ($baseColor['red'] / 255.0) * (1 - $topColor['red'] / 255.0) + sqrt($baseColor['red'] / 255.0) * (2 * ($topColor['red'] / 255.0) - 1)) * 255.0)), 'green' => intval(round($topColor['green'] / 255.0 < 0.5 ? (2 * ($baseColor['green'] / 255.0) * ($topColor['green'] / 255.0) + $baseColor['green'] / 255.0 * ($baseColor['green'] / 255.0) * (1 - 2 * ($topColor['green'] / 255.0))) * 255.0 : (2 * ($baseColor['green'] / 255.0) * (1 - $topColor['green'] / 255.0) + sqrt($baseColor['green'] / 255.0) * (2 * ($topColor['green'] / 255.0) - 1)) * 255.0)), 'blue' => intval(round($topColor['blue'] / 255.0 < 0.5 ? (2 * ($baseColor['blue'] / 255.0) * ($topColor['blue'] / 255.0) + $baseColor['blue'] / 255.0 * ($baseColor['blue'] / 255.0) * (1 - 2 * ($topColor['blue'] / 255.0))) * 255.0 : (2 * ($baseColor['blue'] / 255.0) * (1 - $topColor['blue'] / 255.0) + sqrt($baseColor['blue'] / 255.0) * (2 * ($topColor['blue'] / 255.0) - 1)) * 255.0)), 'alpha' => intval($topColor['alpha']));
break;
case 'hardLight':
$destColor = array('red' => intval(round($topColor['red'] > 127.5 ? $baseColor['red'] * ((255 - $topColor['red']) / 127.5) + ($topColor['red'] - (255 - $topColor['red'])) : $baseColor['red'] * ($topColor['red'] / 127.5))), 'green' => intval(round($topColor['green'] > 127.5 ? $baseColor['green'] * ((255 - $topColor['green']) / 127.5) + ($topColor['green'] - (255 - $topColor['green'])) : $baseColor['green'] * ($topColor['green'] / 127.5))), 'blue' => intval(round($topColor['blue'] > 127.5 ? $baseColor['blue'] * ((255 - $topColor['blue']) / 127.5) + ($topColor['blue'] - (255 - $topColor['blue'])) : $baseColor['blue'] * ($topColor['blue'] / 127.5))), 'alpha' => intval($topColor['alpha']));
break;
case 'vividLight':
// hotfix for division by zero bug
foreach ($baseColor as $baseKey => $base) {
if ($baseKey != 'alpha') {
if ($base <= 0) {
$baseColor[$baseKey] = 1.0;
|
请发表评论