本文整理汇总了PHP中WideImage_Image::getColorAt方法的典型用法代码示例。如果您正苦于以下问题:PHP WideImage_Image::getColorAt方法的具体用法?PHP WideImage_Image::getColorAt怎么用?PHP WideImage_Image::getColorAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WideImage_Image
的用法示例。
在下文中一共展示了WideImage_Image::getColorAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Returns a mask
*
* @param WideImage_Image $image
* @return WideImage_Image
*/
function execute($image)
{
$width = $image->getWidth();
$height = $image->getHeight();
$mask = WideImage_TrueColorImage::create($width, $height);
$mask->setTransparentColor(-1);
$mask->alphaBlending(false);
$mask->saveAlpha(false);
for ($i = 0; $i <= 255; $i++) {
$greyscale[$i] = ImageColorAllocate($mask->getHandle(), $i, $i, $i);
}
imagefilledrectangle($mask->getHandle(), 0, 0, $width, $height, $greyscale[255]);
$transparentColor = $image->getTransparentColor();
$alphaToGreyRatio = 255 / 127;
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color = $image->getColorAt($x, $y);
if ($color == $transparentColor) {
$rgba['alpha'] = 127;
} else {
$rgba = $image->getColorRGB($color);
}
imagesetpixel($mask->getHandle(), $x, $y, $greyscale[255 - round($rgba['alpha'] * $alphaToGreyRatio)]);
}
}
return $mask;
}
示例2: execute
/**
* Applies a mask on the copy of source image
*
* @param WideImage_Image $image
* @param WideImage_Image $mask
* @param smart_coordinate $left
* @param smart_coordinate $top
* @return WideImage_Image
*/
function execute($image, $mask, $left = 0, $top = 0)
{
$left = WideImage_Coordinate::fix($left, $image->getWidth(), $mask->getWidth());
$top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight());
$width = $image->getWidth();
$mask_width = $mask->getWidth();
$height = $image->getHeight();
$mask_height = $mask->getHeight();
$result = $image->asTrueColor();
$result->alphaBlending(false);
$result->saveAlpha(true);
$srcTransparentColor = $result->getTransparentColor();
if ($srcTransparentColor >= 0) {
# this was here. works without.
#$trgb = $image->getColorRGB($srcTransparentColor);
#$trgb['alpha'] = 127;
#$destTransparentColor = $result->allocateColorAlpha($trgb);
#$result->setTransparentColor($destTransparentColor);
$destTransparentColor = $srcTransparentColor;
} else {
$destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
}
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$mx = $x - $left;
$my = $y - $top;
if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) {
$srcColor = $image->getColorAt($x, $y);
if ($srcColor == $srcTransparentColor) {
$destColor = $destTransparentColor;
} else {
$maskRGB = $mask->getRGBAt($mx, $my);
if ($maskRGB['red'] == 0) {
$destColor = $destTransparentColor;
} elseif ($srcColor >= 0) {
$imageRGB = $image->getRGBAt($x, $y);
$level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
$imageRGB['alpha'] = 127 - round($level * 127);
if ($imageRGB['alpha'] == 127) {
$destColor = $destTransparentColor;
} else {
$destColor = $result->allocateColorAlpha($imageRGB);
}
} else {
$destColor = $destTransparentColor;
}
}
$result->setColorAt($x, $y, $destColor);
}
}
}
return $result;
}
示例3: execute
/**
* Applies a mask on the copy of source image
*
* @param WideImage_Image $image
* @param WideImage_Image $mask
* @param smart_coordinate $left
* @param smart_coordinate $top
* @return WideImage_Image
*/
function execute($image, $mask, $left = 0, $top = 0)
{
$left = WideImage_Coordinate::fix($image->getWidth(), $left);
$top = WideImage_Coordinate::fix($image->getHeight(), $top);
$width = $image->getWidth();
if ($width > $mask->getWidth()) {
$width = $mask->getWidth();
}
$height = $image->getHeight();
if ($height > $mask->getHeight()) {
$height = $mask->getHeight();
}
$result = $image->asTrueColor();
$result->alphaBlending(false);
$result->saveAlpha(true);
$srcTransparentColor = $image->getTransparentColor();
if ($srcTransparentColor >= 0) {
$trgb = $image->getColorRGB($srcTransparentColor);
$trgb['alpha'] = 127;
$destTransparentColor = $result->allocateColorAlpha($trgb);
$result->setTransparentColor($destTransparentColor);
} else {
$destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
}
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
if ($left + $x < $image->getWidth() && $top + $y < $image->getHeight()) {
$srcColor = $image->getColorAt($left + $x, $top + $y);
if ($srcColor == $srcTransparentColor) {
$destColor = $destTransparentColor;
} else {
$maskRGB = $mask->getRGBAt($x, $y);
if ($maskRGB['red'] == 0) {
$destColor = $destTransparentColor;
} elseif ($srcColor >= 0) {
$imageRGB = $image->getRGBAt($left + $x, $top + $y);
$level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
$imageRGB['alpha'] = 127 - round($level * 127);
if ($imageRGB['alpha'] == 127) {
$destColor = $destTransparentColor;
} else {
$destColor = $result->allocateColorAlpha($imageRGB);
}
} else {
$destColor = $destTransparentColor;
}
}
$result->setColorAt($left + $x, $top + $y, $destColor);
}
}
}
return $result;
}