本文整理汇总了PHP中imagecolorsforindex函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorsforindex函数的具体用法?PHP imagecolorsforindex怎么用?PHP imagecolorsforindex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorsforindex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: create_histogram
function create_histogram($filename)
{
$img = imagecreatefromfile($filename);
$size = getimagesize($filename);
$width = $size[0];
$height = $size[1];
$thumbnail_gd_image = imagecreatetruecolor(100, 100);
imagecopyresampled($thumbnail_gd_image, $img, 0, 0, 0, 0, 100, 100, $width, $height);
$img = $thumbnail_gd_image;
$histogram = array();
for ($x = 0; $x < 100; $x++) {
for ($y = 0; $y < 100; $y++) {
$rgb = imagecolorat($img, $x, $y);
$colors = imagecolorsforindex($img, $rgb);
$r = str_pad(dechex($colors['red']), 2, "0", STR_PAD_LEFT);
$g = str_pad(dechex($colors['green']), 2, "0", STR_PAD_LEFT);
$b = str_pad(dechex($colors['blue']), 2, "0", STR_PAD_LEFT);
$hex_color = $r . $g . $b . '';
if (!array_key_exists($hex_color, $histogram)) {
$histogram[$hex_color] = 0;
}
$histogram[$hex_color]++;
}
}
return $histogram;
}
开发者ID:ishawge,项目名称:No-CMS,代码行数:26,代码来源:image_helper.php
示例2: run
public function run($file)
{
$res = $this->open_image($file);
if ($res != TRUE) {
return FALSE;
}
$this->image_progressive = isset($this->settings['field_settings']['progressive_jpeg']) === TRUE && $this->settings['field_settings']['progressive_jpeg'] == 'yes' ? TRUE : FALSE;
$this->Ageimage = array(1, 0, 60);
imagetruecolortopalette($this->EE->channel_images->image, 1, 256);
for ($c = 0; $c < 256; $c++) {
$col = imagecolorsforindex($this->EE->channel_images->image, $c);
$new_col = floor($col['red'] * 0.2125 + $col['green'] * 0.7154 + $col['blue'] * 0.0721);
$noise = rand(-$this->Ageimage[1], $this->Ageimage[1]);
if ($this->Ageimage[2] > 0) {
$r = $new_col + $this->Ageimage[2] + $noise;
$g = floor($new_col + $this->Ageimage[2] / 1.86 + $noise);
$b = floor($new_col + $this->Ageimage[2] / -3.48 + $noise);
} else {
$r = $new_col + $noise;
$g = $new_col + $noise;
$b = $new_col + $noise;
}
imagecolorset($this->EE->channel_images->image, $c, max(0, min(255, $r)), max(0, min(255, $g)), max(0, min(255, $b)));
}
$this->save_image($file);
return TRUE;
}
开发者ID:ayuinc,项目名称:laboratoria-v2,代码行数:27,代码来源:action.sepia.php
示例3: createMask
protected function createMask(sfImage $image, $w, $h)
{
// Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
$mask = $image->getAdapter()->getTransparentImage($w, $h);
// Set the masking colours
if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
$mask_black = imagecolorallocate($mask, 0, 0, 0);
} else {
$mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
}
// Cannot use white as transparent mask if color is set to white
if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
$mask_transparent = imagecolorallocate($mask, 255, 0, 0);
} else {
$mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
$mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
}
imagecolortransparent($mask, $mask_transparent);
imagefill($mask, 0, 0, $mask_black);
// Draw the rounded rectangle for the mask
$this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
$mask_image = clone $image;
$mask_image->getAdapter()->setHolder($mask);
return $mask_image;
}
开发者ID:thefkboss,项目名称:ZenTracker,代码行数:25,代码来源:sfImageRoundedCornersGD.class.php
示例4: 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);
}
开发者ID:bensquire,项目名称:php-color-extractor,代码行数:35,代码来源:PHPColorExtractor.php
示例5: modify
/**
* Wrapper function for 'imagecopyresampled'
*
* @param Image $image
* @param integer $dst_x
* @param integer $dst_y
* @param integer $src_x
* @param integer $src_y
* @param integer $dst_w
* @param integer $dst_h
* @param integer $src_w
* @param integer $src_h
* @return boolean
*/
protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
foreach ($image as $frame) {
// create new image
$modified = imagecreatetruecolor($dst_w, $dst_h);
// get current image
$resource = $frame->getCore();
// preserve transparency
$transIndex = imagecolortransparent($resource);
if ($transIndex != -1) {
$rgba = imagecolorsforindex($modified, $transIndex);
$transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
imagefill($modified, 0, 0, $transColor);
imagecolortransparent($modified, $transColor);
} else {
imagealphablending($modified, false);
imagesavealpha($modified, true);
}
// copy content from resource
imagecopyresampled($modified, $resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// free memory of old core
imagedestroy($resource);
// set new content as recource
$frame->setCore($modified);
}
return true;
}
开发者ID:EdgarPost,项目名称:image,代码行数:41,代码来源:ResizeCommand.php
示例6: toBinary
/**
* 二值化
*/
function toBinary()
{
//$this->size = getimagesize($this->filename);
$this->size[0] = imagesx($this->img);
$this->size[1] = imagesy($this->img);
$white = imagecolorallocate($this->img, 255, 255, 255);
$black = imagecolorallocate($this->img, 0, 0, 0);
//一行一行地扫描
for ($i = 0; $i < $this->size[0]; ++$i) {
for ($j = 0; $j < $this->size[1]; ++$j) {
$rgb = imagecolorat($this->img, $i, $j);
$rgbarray = imagecolorsforindex($this->img, $rgb);
// =========================================================
// 任何验证码的数字和字母部分为了和验证码图片背景有所区别
// 都必须对文字和背景图片的RGB进行区分,下面的值是我根据
// 验证码的图片进行区分的,您可以分析您的图片,找到如下规律
// =========================================================
if ($rgbarray['red'] < 125 || $rgbarray['green'] < 125 || $rgbarray['blue'] < 125) {
$this->data[$i][$j] = 1;
defined('TRAINNING') && TRAINNING && imagesetpixel($this->img, $i, $j, $black);
} else {
$this->data[$i][$j] = 0;
defined('TRAINNING') && TRAINNING && imagesetpixel($this->img, $i, $j, $white);
}
}
}
}
开发者ID:j178,项目名称:crack-neu-php,代码行数:30,代码来源:Captcha.php
示例7: 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;
}
}
}
开发者ID:badlamer,项目名称:hhvm,代码行数:25,代码来源:gif.php
示例8: generateArray
private static function generateArray($image_path)
{
$image_info = self::getImageInfo($image_path);
$func = 'imagecreatefrom' . $image_info['type'];
if (function_exists($func)) {
$main_img = $func($image_path);
$tmp_img = imagecreatetruecolor(self::$matrix, self::$matrix);
imagecopyresampled($tmp_img, $main_img, 0, 0, 0, 0, self::$matrix, self::$matrix, $image_info['width'], $image_info['height']);
$pixelmap = array();
$average_pixel = 0;
for ($x = 0; $x < self::$matrix; $x++) {
for ($y = 0; $y < self::$matrix; $y++) {
$color = imagecolorat($tmp_img, $x, $y);
$color = imagecolorsforindex($tmp_img, $color);
$pixelmap[$x][$y] = 0.299 * $color['red'] + 0.587 * $color['green'] + 0.114 * $color['blue'];
$average_pixel += $pixelmap[$x][$y];
}
}
$average_pixel = $average_pixel / (self::$matrix * self::$matrix);
imagedestroy($main_img);
imagedestroy($tmp_img);
for ($x = 0; $x < self::$matrix; $x++) {
for ($y = 0; $y < self::$matrix; $y++) {
$row = $pixelmap[$x][$y] == 0 ? 0 : round(2 * ($pixelmap[$x][$y] > $average_pixel ? $pixelmap[$x][$y] / $average_pixel : $average_pixel / $pixelmap[$x][$y] * -1));
$row = $x + 10 . ($y + 10) . (255 + $row);
$result[] = intval($row);
}
}
return $result;
} else {
//raise exception
throw new Exception('File type not supported!');
}
}
开发者ID:pars5555,项目名称:pcstore,代码行数:34,代码来源:ImageDiff.class.php
示例9: 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);
}
}
}
开发者ID:numbas,项目名称:moodle,代码行数:51,代码来源:gdlib.php
示例10: execute
public function execute()
{
$this->media->asImage();
$img = $this->media->getImage();
if (!($t = imagecolorstotal($img))) {
$t = 256;
imagetruecolortopalette($img, true, $t);
}
$total = imagecolorstotal($img);
for ($i = 0; $i < $total; ++$i) {
$index = imagecolorsforindex($img, $i);
$red = $index['red'] * 0.393 + $index['green'] * 0.769 + $index['blue'] * 0.189;
$green = $index['red'] * 0.349 + $index['green'] * 0.6860000000000001 + $index['blue'] * 0.168;
$blue = $index['red'] * 0.272 + $index['green'] * 0.534 + $index['blue'] * 0.131;
if ($red > 255) {
$red = 255;
}
if ($green > 255) {
$green = 255;
}
if ($blue > 255) {
$blue = 255;
}
imagecolorset($img, $i, $red, $green, $blue);
}
$this->media->setImage($img);
}
开发者ID:staabm,项目名称:redaxo,代码行数:27,代码来源:effect_filter_sepia.php
示例11: colorize
public function colorize()
{
$image_name = "{$this->_id}.png";
$this->_extension = "png";
$cache = $this->_cache_dir;
if (!file_exists($cache . $image_name) or !$this->getResources()) {
try {
list($width, $height) = getimagesize($this->_path);
$img = imagecreatefromstring(file_get_contents($this->_path));
if ($this->_color) {
$rgb = $this->_toRgb($this->_color);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$colors = imagecolorat($img, $x, $y);
$current_rgb = imagecolorsforindex($img, $colors);
$color = imagecolorallocatealpha($img, $rgb['red'], $rgb['green'], $rgb['blue'], $current_rgb['alpha']);
imagesetpixel($img, $x, $y, $color);
}
}
}
imagesavealpha($img, true);
imagepng($img, $cache . $image_name);
$this->_resources = $img;
} catch (Exception $e) {
throw new $e();
}
}
return $this;
}
开发者ID:bklein01,项目名称:siberian_cms_2,代码行数:29,代码来源:Image.php
示例12: getHec
public function getHec()
{
//得到像素大小,RGB值
$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);
//计算灰度,并作出计算
$gray = $rgbarray['red']*0.3 + $rgbarray['green'] * 0.59 + $rgbarray['blue'] * 0.11;
if($gray < 129)
{
$data[$i][$j]=1;
}else{
$data[$i][$j]=0;
}
}
}
$this->DataArray = $data;
$this->ImageSize = $size;
//去除噪点
$this->filterInfo();
//返回二值化后数据
return $this->DataArray;
}
开发者ID:Bless-L,项目名称:backstage-project,代码行数:31,代码来源:vaild.php
示例13: build
public function build()
{
$im = imagecreatefrompng($this->image_file);
if ($im === false) {
throw new Exception($this->image_file . ' is not png file.');
}
$is_alpha = false;
$width = imagesx($im);
$height = imagesy($im);
$bitmap_data = array();
for ($y = 0; $y < $height; ++$y) {
for ($x = 0; $x < $width; ++$x) {
$rgb = imagecolorsforindex($im, imagecolorat($im, $x, $y));
if ($rgb['alpha'] > 0) {
$is_alpha = true;
}
$alpha = (127 - $rgb['alpha']) / 127 * 255;
if ($alpha == 255) {
$bitmap_data[] = array('Alpha' => 255, 'Red' => $rgb['red'], 'Green' => $rgb['green'], 'Blue' => $rgb['blue']);
} else {
$bitmap_data[] = array('Alpha' => round($alpha), 'Red' => round($rgb['red'] * $alpha / 255), 'Green' => round($rgb['green'] * $alpha / 255), 'Blue' => round($rgb['blue'] * $alpha / 255));
}
}
}
$bitmap = '';
if ($is_alpha) {
foreach ($bitmap_data as $rgb) {
if ($rgb['Alpha'] == 0) {
$bitmap .= chr(0);
$bitmap .= chr(0);
$bitmap .= chr(0);
$bitmap .= chr(0);
} else {
$bitmap .= chr($rgb['Alpha']);
$bitmap .= chr($rgb['Red']);
$bitmap .= chr($rgb['Green']);
$bitmap .= chr($rgb['Blue']);
}
}
} else {
foreach ($bitmap_data as $rgb) {
$bitmap .= chr(0);
$bitmap .= chr($rgb['Red']);
$bitmap .= chr($rgb['Green']);
$bitmap .= chr($rgb['Blue']);
}
}
$format = 5;
// palette format
$content = chr($format) . pack('v', $width) . pack('v', $height);
$content .= gzcompress($bitmap);
if ($is_alpha) {
$this->code = 36;
// DefineBitsLossless2
} else {
$this->code = 20;
// DefineBitsLossless
}
$this->content = $content;
}
开发者ID:nzw,项目名称:FlashForward,代码行数:60,代码来源:PNG.class.php
示例14: GenerateFromLocalImage
/**
* Returns the colors of the image in an array, ordered in descending order, where
* the keys are the colors, and the values are the count of the color.
* @param $filePath the path to the local image file
* @return an array keyed by hex color value, mapping to the frequency of use in the images
*/
public static function GenerateFromLocalImage(ImageFile $file)
{
$pImage = \PMVC\plug('image');
// resize the image for a reasonable amount of colors
$previewSize = new ImageSize(150, 150);
$srcSize = $file->getSize();
$scale = 1;
if ($srcSize->w > 0) {
$scale = min($previewSize->w / $srcSize->w, $previewSize->h / $srcSize->h);
}
if ($scale < 1) {
$destSize = new ImageSize(floor($scale * $srcSize->w), floor($scale * $srcSize->h));
} else {
$destSize = new ImageSize($srcSize->w, $srcSize->h);
}
$image_resized = $pImage->create($destSize);
$image_orig = $pImage->create($file);
//WE NEED NEAREST NEIGHBOR RESIZING, BECAUSE IT DOESN'T ALTER THE COLORS
imagecopyresampled($image_resized, $image_orig, 0, 0, 0, 0, $destSize->w, $destSize->h, $srcSize->w, $srcSize->h);
// walk the image counting colors
$hexarray = [];
$pImage->process($destSize, [$image_resized], function ($point, $im) use(&$hexarray) {
$index = imagecolorat($im, $point->x, $point->y);
$Colors = imagecolorsforindex($im, $index);
$hexarray[] = (new BaseColor($Colors['red'], $Colors['green'], $Colors['blue']))->toHex();
});
$hexarray = array_count_values($hexarray);
natsort($hexarray);
$hexarray = array_slice($hexarray, -10, 10);
$hexarray = array_reverse($hexarray, true);
return $hexarray;
}
开发者ID:pmvc-plugin,项目名称:color,代码行数:38,代码来源:ColorPalette.php
示例15: imagemergealpha
function imagemergealpha($i)
{
//create a new image
$s = imagecreatetruecolor(imagesx($i[0]), imagesy($i[1]));
$back_color = imagecolorallocate($s, 0xa9, 0xb1, 0xd3);
//merge all images
imagealphablending($s, true);
$z = $i;
while ($d = each($z)) {
imagecopy($s, $d[1], 0, 0, 0, 0, imagesx($d[1]), imagesy($d[1]));
}
//restore the transparency
imagealphablending($s, false);
$w = imagesx($s);
$h = imagesy($s);
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$c = imagecolorat($s, $x, $y);
$c = imagecolorsforindex($s, $c);
$z = $i;
$t = 0;
while ($d = each($z)) {
$ta = imagecolorat($d[1], $x, $y);
$ta = imagecolorsforindex($d[1], $ta);
$t += 127 - $ta['alpha'];
}
$t = $t > 127 ? 127 : $t;
$t = 127 - $t;
$c = imagecolorallocatealpha($s, $c['red'], $c['green'], $c['blue'], $t);
imagesetpixel($s, $x, $y, $c);
}
}
imagesavealpha($s, true);
return $s;
}
开发者ID:relaismago,项目名称:outils,代码行数:35,代码来源:wanted.php
示例16: readImageFromGdResource
/**
* Load actual image pixels from GD resource.
*
* @param resource $im GD resource to use
* @throws Exception Where the image can't be read.
*/
public function readImageFromGdResource($im)
{
if (!is_resource($im)) {
throw new Exception("Failed to load image.");
} elseif (!EscposImage::isGdLoaded()) {
throw new Exception(__FUNCTION__ . " requires 'gd' extension.");
}
/* Make a string of 1's and 0's */
$imgHeight = imagesy($im);
$imgWidth = imagesx($im);
$imgData = str_repeat("", $imgHeight * $imgWidth);
for ($y = 0; $y < $imgHeight; $y++) {
for ($x = 0; $x < $imgWidth; $x++) {
/* Faster to average channels, blend alpha and negate the image here than via filters (tested!) */
$cols = imagecolorsforindex($im, imagecolorat($im, $x, $y));
// 1 for white, 0 for black, ignoring transparency
$greyness = (int) (($cols['red'] + $cols['green'] + $cols['blue']) / 3) >> 7;
// 1 for black, 0 for white, taking into account transparency
$black = 1 - $greyness >> ($cols['alpha'] >> 6);
$imgData[$y * $imgWidth + $x] = $black;
}
}
$this->setImgWidth($imgWidth);
$this->setImgHeight($imgHeight);
$this->setImgData($imgData);
}
开发者ID:mike42,项目名称:escpos-php,代码行数:32,代码来源:GdEscposImage.php
示例17: getColorScheme
public function getColorScheme($number_of_colors = null)
{
$colors = array();
if ($image = @imagecreatefromjpeg($this->_tmp_file)) {
$imgage_width = $this->Image->Transform->new_x;
$imgage_height = $this->Image->Transform->new_y;
$inverted_colors = array();
for ($y = 0; $y < $imgage_height; $y++) {
for ($x = 0; $x < $imgage_width; $x++) {
$index = imagecolorat($image, $x, $y);
$image_colors = imagecolorsforindex($image, $index);
$hex = '';
foreach ($image_colors as $color => $value) {
$image_colors[$color] = intval(($image_colors[$color] + 15) / 32) * 32;
$image_colors[$color] = $image_colors[$color] >= 256 ? 240 : $image_colors[$color];
$hex .= substr('0' . dechex($image_colors[$color]), -2);
}
$hex = substr($hex, 0, 6);
if (strlen($hex) == 6) {
$colors[$hex] = empty($colors[$hex]) ? 1 : $colors[$hex] + 1;
$this->_addToFrequentColors($hex);
if ($this->calculate_negatives && $colors[$hex] > $this->minimum_hits_for_negative) {
$negative = $this->_getNegativeAsHex($image_colors['red'], $image_colors['green'], $image_colors['blue']);
$colors[$negative] = empty($colors[$negative]) ? 1 : $colors[$negative] + 1;
$this->_addToFrequentColors($negative);
}
}
}
}
}
return $this->_getColorsFromCounterColorArray($colors, $number_of_colors);
}
开发者ID:bermi,项目名称:akelos,代码行数:32,代码来源:color_scheme.php
示例18: isItWatter
function isItWatter($lat, $lng)
{
$GMAPStaticUrl = "https://maps.googleapis.com/maps/api/staticmap?center=" . $lat . "," . $lng . "&size=40x40&maptype=roadmap&sensor=false&zoom=12&key=AIzaSyAbYNYyPVWQ78bvZIHHR_djLt-FMEfy2wY";
//echo $GMAPStaticUrl;
$chuid = curl_init();
curl_setopt($chuid, CURLOPT_URL, $GMAPStaticUrl);
curl_setopt($chuid, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($chuid, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = trim(curl_exec($chuid));
curl_close($chuid);
$image = imagecreatefromstring($data);
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/png;base64," . base64_encode($contents) . "' />";
$hexaColor = imagecolorat($image, 0, 0);
$color_tran = imagecolorsforindex($image, $hexaColor);
$hexaColor2 = imagecolorat($image, 0, 1);
$color_tran2 = imagecolorsforindex($image, $hexaColor2);
$hexaColor3 = imagecolorat($image, 0, 2);
$color_tran3 = imagecolorsforindex($image, $hexaColor3);
$red = $color_tran['red'] + $color_tran2['red'] + $color_tran3['red'];
$green = $color_tran['green'] + $color_tran2['green'] + $color_tran3['green'];
$blue = $color_tran['blue'] + $color_tran2['blue'] + $color_tran3['blue'];
imagedestroy($image);
//var_dump($red,$green,$blue);
//int(492) int(570) int(660)
if ($red == 492 && $green == 570 && $blue == 660) {
return 1;
} else {
return 0;
}
}
开发者ID:rebe100x,项目名称:YAKREP,代码行数:34,代码来源:library.php
示例19: CreateImage
/**
* Use GD Library Create Image
* @author D.C
* version 1.0
* @return resource
*/
private function CreateImage()
{
$this->image = imagecreatetruecolor($this->width, $this->height);
$color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
$color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
$color1 = imagecolorsforindex($this->image, $color1);
$color2 = imagecolorsforindex($this->image, $color2);
$steps = $this->width;
$r1 = ($color1['red'] - $color2['red']) / $steps;
$g1 = ($color1['green'] - $color2['green']) / $steps;
$b1 = ($color1['blue'] - $color2['blue']) / $steps;
$x1 = 0;
$y1 =& $i;
$x2 = $this->width;
$y2 =& $i;
for ($i = 0; $i <= $steps; $i++) {
$r2 = $color1['red'] - floor($i * $r1);
$g2 = $color1['green'] - floor($i * $g1);
$b2 = $color1['blue'] - floor($i * $b1);
$color = imagecolorallocate($this->image, $r2, $g2, $b2);
imageline($this->image, $x1, $y1, $x2, $y2, $color);
}
for ($i = 0, $count = mt_rand(10, 20); $i < $count; $i++) {
$color = imagecolorallocatealpha($this->image, mt_rand(20, 255), mt_rand(20, 255), mt_rand(100, 255), mt_rand(80, 120));
imageline($this->image, mt_rand(0, $this->width), 0, mt_rand(0, $this->width), $this->height, $color);
}
return $this->image;
}
开发者ID:TeamOfMalaysia,项目名称:TOM-BLOG,代码行数:34,代码来源:Captcha.php
示例20: generateSVG
/**
* Generates svg from raster
*
* @param GDImageIdentifier $img Raster image to convert to svg
* @return string SVG xml
*/
function generateSVG($img)
{
$w = imagesx($img);
// image width
$h = imagesy($img);
// image height
$n = 1;
//number of consecutive pixels
$svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" shape-rendering=\"crispEdges\">";
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y = $y + $n) {
$col = imagecolorat($img, $x, $y);
$n = 1;
while ($y + $n < $h && $col == imagecolorat($img, $x, $y + $n)) {
$n++;
}
$rgb = imagecolorsforindex($img, $col);
$color = "rgb({$rgb['red']},{$rgb['green']},{$rgb['blue']})";
if ($rgb["alpha"] && $rgb["alpha"] < 128) {
$alpha = (128 - $rgb["alpha"]) / 128;
$color .= "\" fill-opacity=\"{$alpha}";
}
$svg .= "<rect width=\"1\" x=\"{$x}\" height=\"{$n}\" y=\"{$y}\" fill=\"{$color}\"/>\n";
}
}
$svg .= '</svg>';
return $svg;
}
开发者ID:alastairkitchen,项目名称:flaming-shame,代码行数:34,代码来源:converter.php
注:本文中的imagecolorsforindex函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论