本文整理汇总了PHP中imagecolorat函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorat函数的具体用法?PHP imagecolorat怎么用?PHP imagecolorat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imagehex
/**
* Get image hash
* @param array $image
* @return array
*/
private function imagehex($image)
{
$size = getimagesize($image['path']);
$func = 'imagecreatefrom'.$image['type'];
$imageres = $func($image['path']);
$zone = imagecreate(20, 20);
imagecopyresized($zone, $imageres, 0, 0, 0, 0, 20, 20, $size[0], $size[1]);
$colormap = array();
$average = 0;
$result = array();
for($x=0; $x < 20; $x++)
{
for($y=0; $y < 20; $y++)
{
$color = imagecolorat($zone, $x, $y);
$color = imagecolorsforindex($zone, $color);
$colormap[$x][$y]= 0.212671 * $color['red'] + 0.715160 * $color['green'] + 0.072169 * $color['blue'];
$average += $colormap[$x][$y];
}
}
$average /= 400;
for($x=0; $x < 20; $x++)
{
for($y=0; $y < 20; $y++)
{
$result[]=($x < 10 ? $x : chr($x+97)) . ($y < 10 ? $y : chr($y+97)) . ($colormap[$x][$y]==0 ? '0' : round(2*($colormap[$x][$y] > $average ? $colormap[$x][$y]/$average:-1*$average/$colormap[$x][$y])));
}
}
return $result;
}
示例2: colorImageBottom
/**
* Retourne la couleur du pixel en bas a gauche de l'image
**/
function colorImageBottom($imageName)
{
// recuperer le type et la taille de l'image
// Pb sur certains JPG qui retourne ''
list($imgW, $imgH, $imgTyp) = getimagesize($imageName);
switch ($imgTyp) {
case 1:
$im = imagecreatefromgif($imageName);
break;
case 2:
case ' ':
$im = imagecreatefromjpeg($imageName);
break;
case 3:
$im = imagecreatefrompng($imageName);
break;
default:
$app = JFactory::getApplication();
$app->enqueueMessage(JTEXT::_('IMGNAME_ERROR') . '[name=' . $imageName . '] [ type=' . $imgTyp . '] [ format= ' . $imgW . 'x' . $imgH, 'error');
var_dump(gd_info());
return "";
}
$rgb = imagecolorat($im, 2, $imgH - 2);
$hex = sprintf("%06X", $rgb);
return $hex;
}
示例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.');
}
$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);
}
}
}
示例4: getAverageColor
protected function getAverageColor()
{
$im = $this->image;
//Begin getting average
$width = imagesx($im);
$height = imagesy($im);
$total = $r = $g = $b = $a = 0;
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
//get rgba array at index
$index = imagecolorat($im, $x, $y);
$rgba = imagecolorsforindex($im, $index);
//add total for each color
$r += $rgba['red'];
$g += $rgba['green'];
$b += $rgba['blue'];
$a += $rgba['alpha'];
$total++;
unset($index);
unset($rgba);
}
// end for $y
}
// end for $x
unset($im);
$avg = array('red' => round($r / $total), 'green' => round($g / $total), 'blue' => round($b / $total), 'alpha' => round($a / $total));
$rgb = new Rgba($avg['red'], $avg['green'], $avg['blue'], $avg['alpha'], $this->url);
unset($r);
unset($g);
unset($b);
unset($a);
$this->rgba = $rgb;
return $this;
}
示例5: GetPartialImage
function GetPartialImage($url)
{
$W = 150;
$H = 130;
$F = 80;
$STEP = 1.0 / $F;
$im = imagecreatefromjpeg($url);
$dest = imagecreatetruecolor($W, $H);
imagecopy($dest, $im, 0, 0, 35, 40, $W, $H);
$a = 1;
for( $y = $H - $F; $y < $H; $y++ )
{
for ( $x = 0; $x < $W; $x++ )
{
$i = imagecolorat($dest, $x, $y);
$c = imagecolorsforindex($dest, $i);
$c = imagecolorallocate($dest,
a($c['red'], $a),
a($c['green'], $a),
a($c['blue'], $a)
);
imagesetpixel($dest, $x, $y, $c);
}
$a -= $STEP;
}
header('Content-type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($im);
}
示例6: applyFilter
/**
* Applies the sepia filter to an image resource
*
* @param ImageResource $aResource
*/
public function applyFilter(ImageResource $aResource)
{
if ($this->offset === 0) {
return;
}
$resource = $aResource->getResource();
$imagex = imagesx($resource);
$imagey = imagesy($resource);
for ($x = 0; $x < $imagex; ++$x) {
for ($y = 0; $y < $imagey; ++$y) {
$distx = rand($this->offset * -1, $this->offset);
$disty = rand($this->offset * -1, $this->offset);
if ($x + $distx >= $imagex) {
continue;
}
if ($x + $distx < 0) {
continue;
}
if ($y + $disty >= $imagey) {
continue;
}
if ($y + $disty < 0) {
continue;
}
$oldcol = imagecolorat($resource, $x, $y);
$newcol = imagecolorat($resource, $x + $distx, $y + $disty);
imagesetpixel($resource, $x, $y, $newcol);
imagesetpixel($resource, $x + $distx, $y + $disty, $oldcol);
}
}
}
示例7: extractPalette
/**
* Extracts the colour palette of the set image
*
* @return array
* @throws Exception
*/
public function extractPalette()
{
if (is_null($this->image)) {
throw new Exception('An image must be set before its palette can be extracted.');
}
if (($size = getimagesize($this->image)) === false) {
throw new Exception("Unable to get image size data");
}
if (($img = imagecreatefromstring(file_get_contents($this->image))) === false) {
throw new Exception("Unable to open image file");
}
$colors = array();
for ($x = 0; $x < $size[0]; $x += $this->granularity) {
for ($y = 0; $y < $size[1]; $y += $this->granularity) {
$rgb = imagecolorsforindex($img, imagecolorat($img, $x, $y));
$red = round(round($rgb['red'] / 0x33) * 0x33);
$green = round(round($rgb['green'] / 0x33) * 0x33);
$blue = round(round($rgb['blue'] / 0x33) * 0x33);
$thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue);
if (array_key_exists($thisRGB, $colors)) {
$colors[$thisRGB]++;
} else {
$colors[$thisRGB] = 1;
}
}
}
arsort($colors);
return array_slice(array_keys($colors), 0, $this->totalColors);
}
示例8: getHec
public function getHec()
{
$res = imagecreatefromjpeg($this->ImagePath);
$size = getimagesize($this->ImagePath);
$data = array();
for ($i = 0; $i < $size[1]; ++$i) {
for ($j = 0; $j < $size[0]; ++$j) {
$rgb = imagecolorat($res, $j, $i);
$rgbarray = imagecolorsforindex($res, $rgb);
// =========================================================
// 任何验证码的数字和字母部分为了和验证码图片背景有所区别
// 都必须对文字和背景图片的RGB进行区分,下面的值是我根据
// 验证码的图片进行区分的,您可以分析您的图片,找到如下规律
// =========================================================
if ($rgbarray['red'] < 125 || $rgbarray['green'] < 125 || $rgbarray['blue'] < 125) {
$data[$i][$j] = 1;
} else {
$data[$i][$j] = 0;
}
}
}
// 首列1
for ($j = 0; $j < $size[1]; ++$j) {
$data[$j][0] = 0;
}
$this->DataArray = $data;
$this->ImageSize = $size;
}
示例9: process_pixels
function process_pixels()
{
$this->min = 255;
$this->max = 0;
for ($x = 0; $x < $this->resize_width; $x++) {
for ($y = 0; $y < $this->resize_height; $y++) {
$rgb = imagecolorat($this->resized, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$this->pixels[$x][$y] = array($r, $g, $b);
$grey = round(($r + $g + $b) / 3);
if ($grey > $this->max) {
$this->max = $grey;
}
if ($grey < $this->min) {
$this->min = $grey;
}
$this->pixels_processed_grey[$x][$y] = $grey;
}
}
$this->normalize_pixels();
//$this->median_pixels();
$this->further_process();
}
示例10: imagecopybicubic
/**
* Copies a rectangular portion of the source image to another rectangle in the destination image
*
* This function calls imagecopyresampled() if it is available and GD version is 2 at least.
* Otherwise it reimplements the same behaviour. See the PHP manual page for more info.
*
* @link http://php.net/manual/en/function.imagecopyresampled.php
* @param resource $dst_img the destination GD image resource
* @param resource $src_img the source GD image resource
* @param int $dst_x vthe X coordinate of the upper left corner in the destination image
* @param int $dst_y the Y coordinate of the upper left corner in the destination image
* @param int $src_x the X coordinate of the upper left corner in the source image
* @param int $src_y the Y coordinate of the upper left corner in the source image
* @param int $dst_w the width of the destination rectangle
* @param int $dst_h the height of the destination rectangle
* @param int $src_w the width of the source rectangle
* @param int $src_h the height of the source rectangle
* @return bool tru on success, false otherwise
*/
function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
global $CFG;
if (function_exists('imagecopyresampled') and $CFG->gdversion >= 2) {
return imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
}
$totalcolors = imagecolorstotal($src_img);
for ($i = 0; $i < $totalcolors; $i++) {
if ($colors = imagecolorsforindex($src_img, $i)) {
imagecolorallocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
}
$scalex = ($src_w - 1) / $dst_w;
$scaley = ($src_h - 1) / $dst_h;
$scalex2 = $scalex / 2.0;
$scaley2 = $scaley / 2.0;
for ($j = 0; $j < $dst_h; $j++) {
$sy = $j * $scaley;
for ($i = 0; $i < $dst_w; $i++) {
$sx = $i * $scalex;
$c1 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx, (int) $sy + $scaley2));
$c2 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx, (int) $sy));
$c3 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx + $scalex2, (int) $sy + $scaley2));
$c4 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx + $scalex2, (int) $sy));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = imagecolorclosest($dst_img, $red, $green, $blue);
imagesetpixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}
示例11: execute
public function execute()
{
$this->media->asImage();
$gdimage = $this->media->getImage();
$w = $this->media->getWidth();
$h = $this->media->getHeight();
$src_x = ceil($w);
$src_y = ceil($h);
$dst_x = $src_x;
$dst_y = $src_y;
$dst_im = imagecreatetruecolor($dst_x, $dst_y);
imagecopyresampled($dst_im, $gdimage, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
for ($c = 0; $c < 256; ++$c) {
$palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
}
for ($y = 0; $y < $src_y; ++$y) {
for ($x = 0; $x < $src_x; ++$x) {
$rgb = imagecolorat($dst_im, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
imagesetpixel($dst_im, $x, $y, $palette[$gs]);
}
}
$this->media->setImage($dst_im);
}
示例12: imagecharx
function imagecharx($img, $char, $x0, $y0, $ylist)
{
global $bk_color, $fg_color;
$da = @imagecreate(10, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($da, $bk_color[0], $bk_color[1], $bk_color[2]);
$text_color = imagecolorallocate($da, $fg_color[0], $fg_color[1], $fg_color[2]);
$color = imagecolorallocate($img, $fg_color[0], $fg_color[1], $fg_color[2]);
$arg = rand(0, 18) / 100.0 * pi();
imagestring($da, 18, 0, 0, $char, $text_color);
for ($i = 0; $i < 200; $i++) {
$y = @floor($i / 10);
$x = $i % 10;
$point_color = imagecolorat($da, $x, $y);
if ($point_color == $text_color) {
for ($j = 0; $j < 12; $j++) {
$dx = 0;
$dy = 0;
$p = 6;
for ($s = 0; $s < $p; $s++) {
$dx += rand(0, 1000 / $p) / 100;
$dy += rand(0, 1000 / $p) / 100;
}
$xx = $x * 5 + $dx - 25;
$yy = $y * 5 + $dy - 50;
$x1 = cos($arg) * $xx - sin($arg) * $yy + 25;
$y1 = sin($arg) * $xx + cos($arg) * $yy + 50;
imagesetpixel($img, $x0 + $x1, $y0 + $y1, $color);
}
}
}
imagedestroy($da);
}
示例13: hash
/**
* {@inheritDoc}
*/
public function hash($resource)
{
// Resize the image.
$resized = imagecreatetruecolor(static::SIZE, static::SIZE);
imagecopyresampled($resized, $resource, 0, 0, 0, 0, static::SIZE, static::SIZE, imagesx($resource), imagesy($resource));
// Create an array of greyscale pixel values.
$pixels = [];
for ($y = 0; $y < static::SIZE; $y++) {
for ($x = 0; $x < static::SIZE; $x++) {
$rgb = imagecolorsforindex($resized, imagecolorat($resized, $x, $y));
$pixels[] = floor(($rgb['red'] + $rgb['green'] + $rgb['blue']) / 3);
}
}
// Free up memory.
imagedestroy($resized);
// Get the average pixel value.
$average = floor(array_sum($pixels) / count($pixels));
// Each hash bit is set based on whether the current pixels value is above or below the average.
$hash = 0;
$one = 1;
foreach ($pixels as $pixel) {
if ($pixel > $average) {
$hash |= $one;
}
$one = $one << 1;
}
return $hash;
}
示例14: execute
function execute()
{
$gdimage =& $this->image->getImage();
$w = $this->image->getWidth();
$h = $this->image->getHeight();
$im = $gdimage;
$width = imagesx($im);
$height = imagesy($im);
$output_image_resource = imagecreatetruecolor($width, $height);
// --------------- Flip X
if ($this->params['flip'] == "X") {
$y = 0;
$x = 1;
while ($x <= $width) {
for ($i = 0; $i < $height; $i++) {
imagesetpixel($output_image_resource, $x, $i, imagecolorat($im, $width - $x, $i));
}
$x++;
}
$gdimage = $output_image_resource;
}
// --------------- Flip Y
if ($this->params['flip'] == "Y") {
$y = 1;
$x = 0;
while ($y < $height) {
for ($i = 0; $i < $width; $i++) {
imagesetpixel($output_image_resource, $i, $y, imagecolorat($im, $i, $height - $y));
}
$y++;
}
$gdimage = $output_image_resource;
}
}
示例15: check_box
function check_box($r, $g, $b, $error = 0)
{
$cwd = dirname(__FILE__);
$im2 = imagecreatefromgif($cwd . '/test_gif.gif');
$c = imagecolorsforindex($im2, imagecolorat($im2, 8, 8));
if ($error > 0) {
$r_min = $r - $error;
$r_max = $r + $error;
$g_min = $g - $error;
$g_max = $g + $error;
$b_min = $b - $error;
$b_max = $b + $error;
if (($c['red'] >= $r_min || $c['red'] <= $r_max) && ($c['green'] >= $g_min || $c['green'] <= $g_max) && ($c['blue'] >= $b_min || $c['blue'] <= $b_max)) {
return true;
} else {
return false;
}
} else {
if ($c['red'] == $r && $c['green'] == $g && $c['blue'] == $b) {
return true;
} else {
return false;
}
}
}