本文整理汇总了PHP中imagecolorclosest函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorclosest函数的具体用法?PHP imagecolorclosest怎么用?PHP imagecolorclosest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorclosest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
}
示例2: generate
public function generate()
{
$findColor = Image_Image::hexColorToArrayColor($this->find);
$replaceColor = Image_Image::hexColorToArrayColor($this->replace);
$index = imagecolorclosest($this->_owner->image, $findColor['red'], $findColor['green'], $findColor['blue']);
//find
imagecolorset($this->_owner->image, $index, $replaceColor['red'], $replaceColor['green'], $replaceColor['blue']);
//replace
unset($index);
return true;
}
示例3: compare
public static function compare($max_colors, $filename)
{
$tally = array();
// size image to something managable (256 x 256)
$image_data = getimagesize($filename);
// if small image then use its current size
if ($image_data[0] < self::$resize_dim && $image_data[1] < self::$resize_dim) {
$image = self::createImage($filename, $image_data[2]);
$width = $image_data[0];
$height = $image_data[1];
} else {
$res = self::createResizedImage($filename, $image_data[0], $image_data[1], $image_data[2]);
if ($res == false) {
print "[failed on resize]";
return false;
} else {
$image = $res[0];
$width = $res[1];
$height = $res[2];
}
}
// create the comparison palette
self::createComparisonPalette();
// loop through x axis
for ($x = 0; $x < $width; $x++) {
// loop through y axis
for ($y = 0; $y < $height; $y++) {
// compare to find colest match and tally
list($red, $green, $blue) = self::getRGBFromPixel($image, $x, $y);
$index = imagecolorclosest(self::$comp_palette, $red, $green, $blue);
@($tally[$index] = @$tally[$index] + 1);
}
}
// sort the tally results
arsort($tally);
$ret_array = array();
$i = 0;
$threshold = $width * $height * (self::$threshold_filter / 100);
// build the return array of the top results
foreach ($tally as $index => $count) {
// make sure the count is high enough to be considered significant
if ($count >= $threshold) {
$ret_array[self::$swatch_index[$index]] = $count;
$i++;
} else {
break;
}
if ($i >= $max_colors) {
break;
}
}
return $ret_array;
}
示例4: toPngColor
public function toPngColor($img)
{
$color = imagecolorexact($img, $this->red, $this->green, $this->blue);
if ($color == -1) {
if (imagecolorstotal($img) >= 255) {
$color = imagecolorclosest($img, $this->red, $this->green, $this->blue);
} else {
$color = imagecolorallocate($img, $this->red, $this->green, $this->blue);
}
}
return $color;
}
示例5: _get_image_color
function _get_image_color($im, $r, $g, $b)
{
$c = imagecolorexact($im, $r, $g, $b);
if ($c != -1) {
return $c;
}
$c = imagecolorallocate($im, $r, $g, $b);
if ($c != -1) {
return $c;
}
return imagecolorclosest($im, $r, $g, $b);
}
示例6: applyFilter
/**
* Applies the filter to the resource
*
* @param ImageResource $aResource
*/
public function applyFilter(ImageResource $aResource)
{
$dest = $aResource->getResource();
if (imageistruecolor($dest)) {
imagetruecolortopalette($dest, false, 256);
}
foreach ($this->search as $search) {
$searchRgb = new Color($search);
$index = imagecolorclosest($aResource->getResource(), $searchRgb->getRed(), $searchRgb->getGreen(), $searchRgb->getBlue());
// get White COlor
imagecolorset($aResource->getResource(), $index, $this->replace->getRed(), $this->replace->getGreen(), $this->replace->getBlue());
// SET NEW COLOR
}
$aResource->setResource($dest);
}
示例7: createcolor
/**
* Insert a color to the palet or return the color if the color exist
*
* @param image $pic the picture where we work on it
* @param int $c1 red part of the color
* @param int $c2 green part of the color
* @param int $c3 blue part of the color
* @return color the color that we want
*/
public static function createcolor($pic, $c1, $c2, $c3)
{
//get color from palette
$color = imagecolorexact($pic, $c1, $c2, $c3);
if ($color == -1) {
//color does not exist...
//test if we have used up palette
if (imagecolorstotal($pic) >= 255) {
//palette used up; pick closest assigned color
$color = imagecolorclosest($pic, $c1, $c2, $c3);
} else {
//palette NOT used up; assign new color
$color = imagecolorallocate($pic, $c1, $c2, $c3);
}
}
return $color;
}
示例8: typo3_distortString
function typo3_distortString($img, $text, $tcolor, $bcolor, $angle, $diffx, $diffy, $xpos, $ypos, $letterSpacing, $bold, $fontSize, $fontFile, $useTTF = 0)
{
// When no TTF get's used.
$charx = 20;
$chary = 20;
$osx = 5;
$osy = 0;
$fg = imagecolorallocate($img, $tcolor[0], $tcolor[1], $tcolor[2]);
$bg = imagecolorallocate($img, $bcolor[0], $bcolor[1], $bcolor[2]);
for ($x = 0; $x < strlen($text); $x++) {
$c = substr($text, $x, 1);
$da = rand(0, $angle * 2) - $angle;
$dx = intval(rand(0, $diffx * 2) - $diffx);
$dy = intval(rand(0, $diffy * 2) - $diffy);
if ($useTTF) {
$ret = imagettftext($img, $fontSize, $da, $xpos + $dx, $ypos + $dy + $fontSize, $fg, $fontFile, $c);
if ($bold) {
$ret = imagettftext($img, $fontSize, $da, $xpos + $dx + 1, $ypos + $dy + $fontSize, $fg, $fontFile, $c);
$ret = imagettftext($img, $fontSize, $da, $xpos + $dx + 1, $ypos + $dy + $fontSize + 1, $fg, $fontFile, $c);
$ret = imagettftext($img, $fontSize, $da, $xpos + $dx, $ypos + $dy + $fontSize + 1, $fg, $fontFile, $c);
}
$xpos += $ret[2] - $ret[0];
} else {
$tmpi = imagecreate($charx, $chary);
$back = imagecolorallocate($tmpi, $bcolor[0], $bcolor[1], $bcolor[2]);
$fcol = imagecolorallocate($tmpi, $tcolor[0], $tcolor[1], $tcolor[2]);
imagefill($tmpi, 0, 0, $back);
imagestring($tmpi, 5, $osx, $osy, $c, $fcol);
$rot = imagerotate($tmpi, $da, $back);
$rback = imagecolorclosest($rot, $bcolor[0], $bcolor[1], $bcolor[2]);
imagecolortransparent($rot, $rback);
imagecopymerge($img, $rot, $xpos + $dx, $ypos + $dy, 0, 0, 20, 20, 100);
}
$xpos += $letterSpacing;
}
}
示例9: _a_set_pixel
function _a_set_pixel($im, $x, $y, $filled, $fgcolors)
{
$rgb = imagecolorat($im, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$red = round($r + ($fgcolors['red'] - $r) * $filled);
$green = round($g + ($fgcolors['green'] - $g) * $filled);
$blue = round($b + ($fgcolors['blue'] - $b) * $filled);
imagesetpixel($im, $x, $y, imagecolorclosest($im, $red, $green, $blue));
}
示例10: makeThumbWatermark
function makeThumbWatermark($width = 128, $height = 128)
{
$this->fileCheck();
$image_info = $this->getInfo($this->src_image_name);
if (!$image_info) {
return false;
}
$src_image_type = $image_info["type"];
$img = $this->createImage($src_image_type, $this->src_image_name);
if (!$img) {
return false;
}
$width = $width == 0 ? $image_info["width"] : $width;
$height = $height == 0 ? $image_info["height"] : $height;
$width = $width > $image_info["width"] ? $image_info["width"] : $width;
$height = $height > $image_info["height"] ? $image_info["height"] : $height;
$srcW = $image_info["width"];
$srcH = $image_info["height"];
if ($srcH * $width > $srcW * $height) {
$width = round($srcW * $height / $srcH);
} else {
$height = round($srcH * $width / $srcW);
}
//*
$src_image = @imagecreatetruecolor($width, $height);
$white = @imagecolorallocate($src_image, 0xff, 0xff, 0xff);
@imagecolortransparent($src_image, $white);
@imagefilltoborder($src_image, 0, 0, $white, $white);
if ($src_image) {
ImageCopyResampled($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
} else {
$src_image = imagecreate($width, $height);
ImageCopyResized($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
}
$src_image_w = ImageSX($src_image);
$src_image_h = ImageSY($src_image);
if ($this->wm_image_name) {
$wm_image_info = $this->getInfo($this->wm_image_name);
if (!$wm_image_info) {
return false;
}
$wm_image_type = $wm_image_info["type"];
$wm_image = $this->createImage($wm_image_type, $this->wm_image_name);
$wm_image_w = ImageSX($wm_image);
$wm_image_h = ImageSY($wm_image);
$temp_wm_image = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos, $wm_image);
if ($this->emboss && function_exists("imagefilter")) {
imagefilter($wm_image, IMG_FILTER_EMBOSS);
$bgcolor = imagecolorclosest($wm_image, 0x7f, 0x7f, 0x7f);
imagecolortransparent($wm_image, $bgcolor);
}
if (function_exists("ImageAlphaBlending") && IMAGETYPE_PNG == $wm_image_info['type']) {
ImageAlphaBlending($src_image, true);
}
$wm_image_x = $temp_wm_image["dest_x"];
$wm_image_y = $temp_wm_image["dest_y"];
if (IMAGETYPE_PNG == $wm_image_info['type']) {
imageCopy($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h);
} else {
imageCopyMerge($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h, $this->wm_image_transition);
}
}
if ($this->wm_text) {
$this->wm_text = $this->wm_text;
$temp_wm_text = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos);
$wm_text_x = $temp_wm_text["dest_x"];
$wm_text_y = $temp_wm_text["dest_y"];
if (preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)) {
$red = hexdec($color[1]);
$green = hexdec($color[2]);
$blue = hexdec($color[3]);
$wm_text_color = imagecolorallocate($src_image, $red, $green, $blue);
} else {
$wm_text_color = imagecolorallocate($src_image, 255, 255, 255);
}
imagettftext($src_image, $this->wm_text_size, $this->wm_angle, $wm_text_x, $wm_text_y, $wm_text_color, $this->wm_text_font, $this->wm_text);
}
if ($this->save_file) {
switch ($src_image_type) {
case 1:
if ($this->gif_enable) {
$src_img = ImageGIF($src_image, $this->save_file);
} else {
$src_img = ImagePNG($src_image, $this->save_file);
}
break;
case 2:
$src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
break;
case 3:
$src_img = ImagePNG($src_image, $this->save_file);
break;
default:
$src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
break;
}
} else {
switch ($src_image_type) {
case 1:
if ($this->gif_enable) {
//.........这里部分代码省略.........
示例11: imagecreatefrombmp
function imagecreatefrombmp($filename)
{
global $gd2;
$fp = fopen($filename, 'rb');
$errors = error_reporting(0);
$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
if ($header['type'] != 0x4d42) {
false;
}
if ($gd2) {
$dst_img = imagecreatetruecolor($info['width'], $info['height']);
} else {
$dst_img = imagecreate($info['width'], $info['height']);
}
$palette_size = $header['offset'] - 54;
$info['ncolor'] = $palette_size / 4;
$palette = array();
$palettedata = fread($fp, $palette_size);
$n = 0;
for ($j = 0; $j < $palette_size; $j++) {
$b = ord($palettedata[$j++]);
$g = ord($palettedata[$j++]);
$r = ord($palettedata[$j++]);
$palette[$n++] = imagecolorallocate($dst_img, $r, $g, $b);
}
$scan_line_size = $info['bits'] * $info['width'] + 7 >> 3;
$scan_line_align = $scan_line_size & 3 ? 4 - ($scan_line_size & 3) : 0;
for ($y = 0, $l = $info['height'] - 1; $y < $info['height']; $y++, $l--) {
fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
$scan_line = fread($fp, $scan_line_size);
if (strlen($scan_line) < $scan_line_size) {
continue;
}
if ($info['bits'] == 32) {
$x = 0;
for ($j = 0; $j < $scan_line_size; $x++) {
$b = ord($scan_line[$j++]);
$g = ord($scan_line[$j++]);
$r = ord($scan_line[$j++]);
$j++;
$color = imagecolorexact($dst_img, $r, $g, $b);
if ($color == -1) {
$color = imagecolorallocate($dst_img, $r, $g, $b);
// Gah! Out of colors? Stupid GD 1... try anyhow.
if ($color == -1) {
$color = imagecolorclosest($dst_img, $r, $g, $b);
}
}
imagesetpixel($dst_img, $x, $y, $color);
}
} elseif ($info['bits'] == 24) {
$x = 0;
for ($j = 0; $j < $scan_line_size; $x++) {
$b = ord($scan_line[$j++]);
$g = ord($scan_line[$j++]);
$r = ord($scan_line[$j++]);
$color = imagecolorexact($dst_img, $r, $g, $b);
if ($color == -1) {
$color = imagecolorallocate($dst_img, $r, $g, $b);
// Gah! Out of colors? Stupid GD 1... try anyhow.
if ($color == -1) {
$color = imagecolorclosest($dst_img, $r, $g, $b);
}
}
imagesetpixel($dst_img, $x, $y, $color);
}
} elseif ($info['bits'] == 16) {
$x = 0;
for ($j = 0; $j < $scan_line_size; $x++) {
$b1 = ord($scan_line[$j++]);
$b2 = ord($scan_line[$j++]);
$word = $b2 * 256 + $b1;
$b = ($word & 31) * 255 / 31;
$g = ($word >> 5 & 31) * 255 / 31;
$r = ($word >> 10 & 31) * 255 / 31;
// Scale the image colors up properly.
$color = imagecolorexact($dst_img, $r, $g, $b);
if ($color == -1) {
$color = imagecolorallocate($dst_img, $r, $g, $b);
// Gah! Out of colors? Stupid GD 1... try anyhow.
if ($color == -1) {
$color = imagecolorclosest($dst_img, $r, $g, $b);
}
}
imagesetpixel($dst_img, $x, $y, $color);
}
} elseif ($info['bits'] == 8) {
$x = 0;
for ($j = 0; $j < $scan_line_size; $x++) {
imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line[$j++])]);
}
} elseif ($info['bits'] == 4) {
$x = 0;
for ($j = 0; $j < $scan_line_size; $x++) {
$byte = ord($scan_line[$j++]);
imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
if (++$x < $info['width']) {
imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
}
//.........这里部分代码省略.........
示例12: imgFolder
function imgFolder()
{
$a = array(18, 24, 38, 24, 43, 29, 76, 29, 76, 70, 18, 70);
if (function_exists('imagecreatetruecolor')) {
$img = imagecreatetruecolor(94, 94);
$black = imagecolorclosest($img, 0, 0, 0);
$yellow = imagecolorclosest($img, 250, 240, 0);
$white = imagecolorclosest($img, 255, 255, 255);
} else {
$img = imagecreate(94, 94);
$black = imagecolorallocate($img, 0, 0, 0);
$yellow = imagecolorallocate($img, 250, 240, 0);
$white = imagecolorallocate($img, 255, 255, 255);
}
imagefilledrectangle($img, 0, 0, 94, 94, $white);
if (function_exists('imagesetthickness')) {
imagesetthickness($img, 1);
}
imagefilledpolygon($img, $a, 6, $yellow);
imagepolygon($img, $a, 6, $black);
imageline($img, 40, 32, 76, 32, $black);
imageline($img, 18, 34, 34, 34, $black);
imageline($img, 34, 34, 40, 32, $black);
return $img;
}
示例13: imagesetpixel
$height = $height > MAX_SCENE_HEIGHT ? MAX_SCENE_HEIGHT : $height;
$height = $height < MIN_SCENE_HEIGHT ? MIN_SCENE_HEIGHT : $height;
$feature_z = MAX_DEPTH - $height * (MAX_DEPTH - MIN_DEPTH) / 256;
$sep = (int) ((double) (EYE_SEP * $feature_z) / ($feature_z + OBS_DIST));
$left_px = (int) $x - $sep / 2;
$right_px = (int) $x + $sep / 2;
if ($left_px >= 0 && $right_px < $img_width) {
if (!isset($buffer[$left_px][$y])) {
$buffer[$left_px][$y] = $colors[rand(1, 255)];
}
$buffer[$right_px][$y] = $buffer[$left_px][$y];
}
}
for ($x = 0; $x < $img_width; $x++) {
if (!isset($buffer[$x][$y])) {
$buffer[$x][$y] = $colors[rand(1, 255)];
}
}
}
/* Output PNG File */
for ($y = 0; $y < $img_height; $y++) {
for ($x = 0; $x < $img_width; $x++) {
imagesetpixel($stereo_img, $x, $y, $buffer[$x][$y]);
}
}
header("Content-type: image/png");
$black = imagecolorclosest($stereo_img, 0, 0, 0);
$white = imagecolorclosest($stereo_img, 0xff, 0xff, 0xff);
imagefilledrectangle($stereo_img, 0, $img_height - 20, $img_width, $img_height, $black);
imagestring($stereo_img, 1, 5, $img_height - 10, "Made at http://www.coggeshall.org/stereogram.php", $white);
imagepng($stereo_img);
示例14: ellipse
public function ellipse($bg_colour = "FFFFFF")
{
$this->bgc = $bg_colour;
$this->br = $this->hex2rgb(substr($this->bgc, 0, 2));
$this->bg = $this->hex2rgb(substr($this->bgc, 2, 2));
$this->bb = $this->hex2rgb(substr($this->bgc, 4, 2));
$this->dot = imagecreate(6, 6);
$this->dot_base = imagecolorallocate($this->dot, $this->br, $this->bg, $this->bb);
$this->zenitha = imagecolorclosest($this->t, $this->br, $this->bg, $this->bb);
for ($this->rad = 0; $this->rad < 6.3; $this->rad += 0.005) {
$this->xpos = floor($this->q + sin($this->rad) * $this->q) / 2;
$this->ypos = floor($this->r + cos($this->rad) * $this->r) / 2;
$this->xto = 0;
if ($this->xpos >= $this->q / 2) {
$this->xto = $this->q;
}
imagecopymerge($this->t, $this->dot, $this->xpos - 3, $this->ypos - 3, 0, 0, 6, 6, 30);
imagecopymerge($this->t, $this->dot, $this->xpos - 2, $this->ypos - 2, 0, 0, 4, 4, 30);
imagecopymerge($this->t, $this->dot, $this->xpos - 1, $this->ypos - 1, 0, 0, 2, 2, 30);
imageline($this->t, $this->xpos, $this->ypos, $this->xto, $this->ypos, $this->zenitha);
}
imagedestroy($this->dot);
$this->efecto[] = "ellipse";
}
示例15: getClosestColor
/**
* Returns closest color index that matches the given RGB value. Uses
* PHP's imagecolorclosest()
*
* @param mixed $R Red or RGBA array
*/
function getClosestColor($R, $G = null, $B = null)
{
if (is_array($R)) {
return imagecolorclosest($this->handle, $R['red'], $R['green'], $R['blue']);
} else {
return imagecolorclosest($this->handle, $R, $G, $B);
}
}