本文整理汇总了PHP中imagesetpixel函数的典型用法代码示例。如果您正苦于以下问题:PHP imagesetpixel函数的具体用法?PHP imagesetpixel怎么用?PHP imagesetpixel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagesetpixel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_captcha
/**
* +----------------------------------------------------------
* 图片上传的处理函数
* +----------------------------------------------------------
*/
function create_captcha()
{
$word = $this->create_word();
// 把验证码字符串写入session
$_SESSION['captcha'] = md5($word . DOU_SHELL);
// 绘制基本框架
$im = imagecreatetruecolor($this->captcha_width, $this->captcha_height);
$bg_color = imagecolorallocate($im, 235, 236, 237);
imagefilledrectangle($im, 0, 0, $this->captcha_width, $this->captcha_height, $bg_color);
$border_color = imagecolorallocate($im, 118, 151, 199);
imagerectangle($im, 0, 0, $this->captcha_width - 1, $this->captcha_height - 1, $border_color);
// 添加干扰
for ($i = 0; $i < 5; $i++) {
$rand_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagearc($im, mt_rand(-$this->captcha_width, $this->captcha_width), mt_rand(-$this->captcha_height, $this->captcha_height), mt_rand(30, $this->captcha_width * 2), mt_rand(20, $this->captcha_height * 2), mt_rand(0, 360), mt_rand(0, 360), $rand_color);
}
for ($i = 0; $i < 50; $i++) {
$rand_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($im, mt_rand(0, $this->captcha_width), mt_rand(0, $this->captcha_height), $rand_color);
}
// 生成验证码图片
$text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
imagestring($im, 6, 18, 5, $word, $text_color);
// header
header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
header("Content-type: image/png;charset=utf-8");
/* 绘图结束 */
imagepng($im);
imagedestroy($im);
return true;
}
示例2: create
public static function create()
{
$image = imagecreatetruecolor(100, 40) or die('cannot create canvas.<br>');
$red = imagecolorallocate($image, 255, 0, 0);
$green = imagecolorallocate($image, 0, 255, 0);
$blue = imagecolorallocate($image, 0, 0, 255);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $white);
imagerectangle($image, 1, 1, 99, 39, $black);
$color = [$red, $green, $blue];
for ($i = 1; $i <= 100; $i++) {
imagesetpixel($image, mt_rand(2, 98), mt_rand(2, 38), $color[mt_rand(0, 2)]);
}
$source = "abcdefghigklmnopqrstuvwxyz0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ";
$first = $source[mt_rand(0, 61)];
$second = $source[mt_rand(0, 61)];
$third = $source[mt_rand(0, 61)];
$fourth = $source[mt_rand(0, 61)];
$_SESSION['captcha'] = $first . $second . $third . $fourth;
$font = dirname(dirname(__DIR__)) . '/../public/assets/fonts/SpicyRice.ttf';
imagettftext($image, 20, mt_rand(-20, 20), 10, 30, $blue, $font, $first);
imagettftext($image, 20, mt_rand(-20, 20), 30, 30, $blue, $font, $second);
imagettftext($image, 20, mt_rand(-20, 20), 50, 30, $blue, $font, $third);
imagettftext($image, 20, mt_rand(-20, 20), 70, 30, $blue, $font, $fourth);
return imagejpeg($image);
}
示例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: 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);
}
示例5: ImageHue
public static function ImageHue(&$image, $hue, $saturation)
{
$width = imagesx($image);
$height = imagesy($image);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$rgb = imagecolorat($image, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$alpha = ($rgb & 0x7f000000) >> 24;
$hsl = ColorUtils::rgb2hsl(array('r' => $r, 'g' => $g, 'b' => $b));
$h = $hsl['h'] / 360;
$s = $hsl['s'] / 100;
$h += $hue / 360;
$s += $saturation / 100;
if ($h > 1) {
$h--;
}
if ($s > 1) {
$s--;
}
$hsl['h'] = $h * 360;
$hsl['s'] = $s * 100;
$rgb = ColorUtils::hsl2rgb($hsl);
imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $rgb['r'], $rgb['g'], $rgb['b'], $alpha));
}
}
}
示例6: execute
function execute()
{
$gdimage =& $this->image->getImage();
$w = $this->image->getWidth();
$h = $this->image->getHeight();
$src_x = ceil($w);
$src_y = ceil($h);
$dst_x = $src_x;
$dst_y = $src_y;
// http://php.about.com/od/gdlibrary/ss/grayscale_gd.htm
function yiq($r, $g, $b)
{
return $r * 0.299 + $g * 0.587 + $b * 0.114;
}
$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 = yiq($r, $g, $b);
imagesetpixel($dst_im, $x, $y, $palette[$gs]);
}
}
$gdimage = $dst_im;
}
示例7: SetDisturbColor
/**
*
* @brief 设置图片的干扰像素
*
*/
private function SetDisturbColor()
{
for ($i = 0; $i <= 128; $i++) {
$this->mDisturbColor = imagecolorallocate($this->mCheckImage, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($this->mCheckImage, rand(2, 128), rand(2, 38), $this->mDisturbColor);
}
}
示例8: getCaptcha
/**
* 生成验证码
* @param int $width 验证码图片宽度.默认130
* @param int $height 验证码图片高度.默认40
* @param int $fontSize 验证码字体大小.默认20
* @param int $length 验证码字符个数.默认4
* @return string 验证码中的字符串
*/
public static function getCaptcha($width = '130', $height = '40', $fontSize = '20', $length = '4')
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyz';
$randStr = substr(str_shuffle($chars), 0, $length);
$image = imagecreatetruecolor($width, $height);
// 定义背景色
$bgColor = imagecolorallocate($image, 0xff, 0xff, 0xff);
// 定义文字及边框颜色
$blackColor = imagecolorallocate($image, 0x0, 0x0, 0x0);
//生成矩形边框
imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
// 循环生成雪花点
for ($i = 0; $i < 200; $i++) {
$grayColor = imagecolorallocate($image, 128 + rand(0, 128), 128 + rand(0, 128), 128 + rand(0, 128));
imagesetpixel($image, rand(1, $width - 2), rand(4, $height - 2), $grayColor);
}
$font = ROOT_PATH . 'resources/fonts/acidic.ttf';
// 把随机字符串输入图片
$i = -1;
while (isset($randStr[++$i])) {
$fontColor = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
if (!function_exists('imagettftext')) {
imagechar($image, $fontSize, 15 + $i * 30, rand(5, 20), $randStr[$i], $fontColor);
} else {
imagettftext($image, $fontSize, 0, 10 + $i * 30, rand(25, 35), $fontColor, $font, $randStr[$i]);
}
}
imagepng($image);
$image = $bgColor = $blackColor = $grayColor = $fontColor = null;
return $randStr;
}
示例9: 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;
}
示例10: 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;
if (function_exists('imagefilter') === TRUE) {
@imagefilter($this->EE->channel_images->image, IMG_FILTER_GRAYSCALE);
} else {
$img_width = imageSX($this->EE->channel_images->image);
$img_height = imageSY($this->EE->channel_images->image);
// convert to grayscale
$palette = array();
for ($c = 0; $c < 256; $c++) {
$palette[$c] = imagecolorallocate($this->EE->channel_images->image, $c, $c, $c);
}
for ($y = 0; $y < $img_height; $y++) {
for ($x = 0; $x < $img_width; $x++) {
$rgb = imagecolorat($this->EE->channel_images->image, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
imagesetpixel($this->EE->channel_images->image, $x, $y, $palette[$gs]);
}
}
}
$this->save_image($file);
return TRUE;
}
示例11: applyFilter
/**
* Applies filter effects to the given image
*
* @param Image\Image $image The image to filter.
*
* @return Image\Image The filtered image.
*
* @throws FilterException if the image filter algorithm fails.
*/
public function applyFilter(Image\Image $image)
{
if ($this->level <= 0) {
$gd = $image->getCore();
$width = imagesx($gd);
$height = imagesy($gd);
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$rgba = imagecolorsforindex($gd, imagecolorat($gd, $x, $y));
$r = $rgba['red'];
$g = $rgba['green'];
$b = $rgba['blue'];
$a = $rgba['alpha'];
$level = $this->level * -1;
$max = max($r, $g, $b);
$avg = ($r + $g + $b) / 3;
$amt = abs($max - $avg) * 2 / 255 * $level / 100;
if ($r !== $max) {
$r += ($max - $r) * $amt;
}
if ($g !== $max) {
$g += ($max - $g) * $amt;
}
if ($b !== $max) {
$b += ($max - $b) * $amt;
}
imagesetpixel($gd, $x, $y, imagecolorallocatealpha($gd, $r, $g, $b, $a));
}
}
$image->setCore($gd);
} else {
$image->filter(new SaturateFilter($this->level));
}
return $image;
}
示例12: draw
/**
* draw point on map
*
* @param Map $map
*/
public function draw(Map $map)
{
$image = $map->getImage();
$color = $this->_getDrawColor($image);
$pointInPixels = $map->getPixelPointFromCoordinates($this->_coordinates['lon'], $this->_coordinates['lat']);
imagesetpixel($image, $pointInPixels['x'], $pointInPixels['y'], $color);
}
示例13: getVerify
public function getVerify()
{
//创建画布
$img = imagecreatetruecolor($this->config['width'], $this->config['height']);
//设置背景颜色
$bgColor = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $bgColor);
$_x = ceil(($this->config['width'] - 20) / $this->config['lenght']);
$code = '';
//写入验证码
for ($i = 0; $i < $this->config['lenght']; $i++) {
$str = random();
$code .= $str;
$x = 10 + $i * $_x;
$fontSize = mt_rand($this->config['fontsize'] - 10, $this->config['fontsize']);
$fontH = imagefontheight($this->config['fontsize']);
$y = mt_rand($fontH + 10, $this->config['height'] - 5);
$fontColor = imagecolorallocate($img, mt_rand(0, 200), mt_rand(0, 200), mt_rand(0, 200));
imagettftext($img, $fontSize, 0, $x, $y, $fontColor, $this->config['fontfile'], $str);
}
//增加干扰点
for ($i = 0; $i < $this->config['point']; $i++) {
$pointColor = imagecolorallocate($img, rand(150, 200), rand(150, 200), rand(100, 200));
imagesetpixel($img, mt_rand(1, $this->config['width']), mt_rand(1, $this->config['height']), $pointColor);
}
//增加线干扰
for ($i = 0; $i < $this->config['line']; $i++) {
$linColor = imagecolorallocate($img, rand(0, 200), rand(0, 200), rand(0, 200));
imageline($img, rand(0, $this->config['width']), rand(0, $this->config['height']), rand(0, $this->config['width']), rand(0, $this->config['height']), $linColor);
}
$_SESSION['Verify'] = md5(strtoupper($code));
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
}
示例14: getCode
function getCode($w, $h)
{
$im = imagecreate($w, $h);
//imagecolorallocate($im, 14, 114, 180); // background color
$red = imagecolorallocate($im, 255, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$num1 = rand(1, 20);
$num2 = rand(1, 20);
$_SESSION['helloweba_math'] = $num1 + $num2;
$gray = imagecolorallocate($im, 118, 151, 199);
$black = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//画背景
imagefilledrectangle($im, 0, 0, 100, 24, $black);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $gray);
}
imagestring($im, 5, 5, 4, $num1, $red);
imagestring($im, 5, 30, 3, "+", $red);
imagestring($im, 5, 45, 4, $num2, $red);
imagestring($im, 5, 70, 3, "=", $red);
imagestring($im, 5, 80, 2, "?", $white);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
示例15: 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);
}
}
}