当前位置: 首页>>代码示例>>PHP>>正文


PHP imageSetPixel函数代码示例

本文整理汇总了PHP中imageSetPixel函数的典型用法代码示例。如果您正苦于以下问题:PHP imageSetPixel函数的具体用法?PHP imageSetPixel怎么用?PHP imageSetPixel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了imageSetPixel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setnoise

function setnoise($image, $width, $height, $back, $noisenum)
{
    for ($i = 0; $i < $noisenum; $i++) {
        $randColor = imageColorAllocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
        imageSetPixel($image, rand(0, $width), rand(0, $height), $randColor);
    }
}
开发者ID:caidongyun,项目名称:CS,代码行数:7,代码来源:verify.php

示例2: __grayscale

	/**
	* Make the image greyscale
	*
	* @param Asido_TMP &$tmp
	* @return boolean
	* @access protected
	*/
	function __grayscale(&$tmp) {

		// the longer path: do it pixel by pixel
		// 
		if (parent::__grayscale(&$tmp)) {
			return true;
			}

		// create 256 color palette
		//
		$palette = array();
		for ($c=0; $c<256; $c++) {
			$palette[$c] = imageColorAllocate($tmp->target, $c, $c, $c);
			}

		// read origonal colors pixel by pixel
		//
		for ($y=0; $y<$tmp->image_height; $y++) {
			for ($x=0; $x<$tmp->image_width; $x++) {

				$rgb = imageColorAt($tmp->target, $x, $y);

				$r = ($rgb >> 16) & 0xFF;
				$g = ($rgb >> 8) & 0xFF;
				$b = $rgb & 0xFF;

				$gs = (($r*0.299)+($g*0.587)+($b*0.114));
				imageSetPixel($tmp->target, $x, $y, $palette[$gs]);
				}
			}

		return true;
		}
开发者ID:rkern21,项目名称:videoeditor,代码行数:40,代码来源:class.driver.gd_hack.php

示例3: setNoisePix

 function setNoisePix()
 {
     for ($i = 0; $i < $this->noiseNumPix; $i++) {
         $randColor = imageColorAllocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
         imageSetPixel($this->image, rand(0, $this->width), rand(0, $this->height), $randColor);
     }
 }
开发者ID:beyondye,项目名称:ENPHP,代码行数:7,代码来源:Authcode.php

示例4: king_def

function king_def()
{
    global $king;
    header("Cache-Control: no-cache, must-revalidate");
    // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // 过去的时间
    header("Content-type: image/png");
    $salt = kc_get('salt', 1, 1);
    $width = $king->config('verifywidth');
    //图片长度
    $height = $king->config('verifyheight');
    //图片高度
    $size = $king->config('verifysize');
    //文字大小
    $num = $king->config('verifynum');
    //文字数量
    $content = $king->config('verifycontent');
    //随机字符
    $array_content = explode('|', $content);
    $array_content = array_diff($array_content, array(null));
    $array_font = kc_f_getdir('system/verify_font', 'ttf|ttc');
    $str = '';
    $img = imageCreate($width, $height);
    //创建一个空白图像
    imageFilledRectangle($img, 0, 0, $width, $height, imagecolorallocate($img, 255, 255, 255));
    //写字
    for ($i = 0; $i < $num; $i++) {
        $code = $array_content[array_rand($array_content)];
        $str .= $code;
        //验证码字符
        $color = imageColorAllocate($img, rand(0, 128), rand(0, 128), rand(0, 128));
        $font = 'verify_font/' . $array_font[array_rand($array_font)];
        //随机读取一个字体
        $left = rand(round($size * 0.2), round($size * 0.4)) + $i * $size;
        imagettftext($img, rand(round($size * 0.7), $size), rand(-20, 20), $left, rand(round($size * 1.2), $size * 1.4), $color, $font, $code);
    }
    //画星号
    $max = $width * $height / 400;
    for ($i = 0; $i < $max; $i++) {
        imagestring($img, 15, rand(0, $width), rand(0, $height), '*', rand(192, 250));
    }
    //画点
    $max = $width * $height / 40;
    for ($i = 0; $i < $max; $i++) {
        imageSetPixel($img, rand(0, $width), rand(0, $height), rand(1, 200));
    }
    //画线
    $max = $width * $height / 800;
    for ($i = 0; $i < $max; $i++) {
        imageline($img, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), rand(0, 255));
    }
    //写验证码到verify中
    $verify = new KC_Verify_class();
    $verify->Put($salt, $str);
    imagePng($img);
    imageDestroy($img);
    $verify->Clear();
}
开发者ID:jonycookie,项目名称:projectm2,代码行数:59,代码来源:verify.php

示例5: imagesmoothcircle

/**
 * Credits goes to an anonymous at http://usphp.com/manual/ro/function.imageantialias.php
 */
function imagesmoothcircle(&$img, $cx, $cy, $cr, $color)
{
    $ir = $cr;
    $ix = 0;
    $iy = $ir;
    $ig = 2 * $ir - 3;
    $idgr = -6;
    $idgd = 4 * $ir - 10;
    $fill = imageColorExactAlpha($img, $color['R'], $color['G'], $color['B'], 0);
    imageLine($img, $cx + $cr - 1, $cy, $cx, $cy, $fill);
    imageLine($img, $cx - $cr + 1, $cy, $cx - 1, $cy, $fill);
    imageLine($img, $cx, $cy + $cr - 1, $cx, $cy + 1, $fill);
    imageLine($img, $cx, $cy - $cr + 1, $cx, $cy - 1, $fill);
    $draw = imageColorExactAlpha($img, $color['R'], $color['G'], $color['B'], 42);
    imageSetPixel($img, $cx + $cr, $cy, $draw);
    imageSetPixel($img, $cx - $cr, $cy, $draw);
    imageSetPixel($img, $cx, $cy + $cr, $draw);
    imageSetPixel($img, $cx, $cy - $cr, $draw);
    while ($ix <= $iy - 2) {
        if ($ig < 0) {
            $ig += $idgd;
            $idgd -= 8;
            $iy--;
        } else {
            $ig += $idgr;
            $idgd -= 4;
        }
        $idgr -= 4;
        $ix++;
        imageLine($img, $cx + $ix, $cy + $iy - 1, $cx + $ix, $cy + $ix, $fill);
        imageLine($img, $cx + $ix, $cy - $iy + 1, $cx + $ix, $cy - $ix, $fill);
        imageLine($img, $cx - $ix, $cy + $iy - 1, $cx - $ix, $cy + $ix, $fill);
        imageLine($img, $cx - $ix, $cy - $iy + 1, $cx - $ix, $cy - $ix, $fill);
        imageLine($img, $cx + $iy - 1, $cy + $ix, $cx + $ix, $cy + $ix, $fill);
        imageLine($img, $cx + $iy - 1, $cy - $ix, $cx + $ix, $cy - $ix, $fill);
        imageLine($img, $cx - $iy + 1, $cy + $ix, $cx - $ix, $cy + $ix, $fill);
        imageLine($img, $cx - $iy + 1, $cy - $ix, $cx - $ix, $cy - $ix, $fill);
        $filled = 0;
        for ($xx = $ix - 0.45; $xx < $ix + 0.5; $xx += 0.2) {
            for ($yy = $iy - 0.45; $yy < $iy + 0.5; $yy += 0.2) {
                if (sqrt(pow($xx, 2) + pow($yy, 2)) < $cr) {
                    $filled += 4;
                }
            }
        }
        $draw = imageColorExactAlpha($img, $color['R'], $color['G'], $color['B'], 100 - $filled);
        imageSetPixel($img, $cx + $ix, $cy + $iy, $draw);
        imageSetPixel($img, $cx + $ix, $cy - $iy, $draw);
        imageSetPixel($img, $cx - $ix, $cy + $iy, $draw);
        imageSetPixel($img, $cx - $ix, $cy - $iy, $draw);
        imageSetPixel($img, $cx + $iy, $cy + $ix, $draw);
        imageSetPixel($img, $cx + $iy, $cy - $ix, $draw);
        imageSetPixel($img, $cx - $iy, $cy + $ix, $draw);
        imageSetPixel($img, $cx - $iy, $cy - $ix, $draw);
    }
}
开发者ID:bishopm,项目名称:circuit,代码行数:59,代码来源:gdext.inc.php

示例6: imageSmoothArcDrawSegment

function imageSmoothArcDrawSegment(&$img, $cx, $cy, $a, $b, $color, $start, $stop, $seg)
{
    // Originally written from scratch by Ulrich Mierendorff, 06/2006
    // Rewritten and improved, 04/2007, 07/2007
    // Optimized circle version: 03/2008
    // Please do not use THIS function directly. Scroll down to imageSmoothArc(...).
    $fillColor = imageColorExactAlpha($img, $color[0], $color[1], $color[2], $color[3]);
    switch ($seg) {
        case 0:
            $xp = +1;
            $yp = -1;
            $xa = 1;
            $ya = -1;
            break;
        case 1:
            $xp = -1;
            $yp = -1;
            $xa = 0;
            $ya = -1;
            break;
        case 2:
            $xp = -1;
            $yp = +1;
            $xa = 0;
            $ya = 0;
            break;
        case 3:
            $xp = +1;
            $yp = +1;
            $xa = 1;
            $ya = 0;
            break;
    }
    for ($x = 0; $x <= $a; $x += 1) {
        $y = $b * sqrt(1 - $x * $x / ($a * $a));
        $error = $y - (int) $y;
        $y = (int) $y;
        $diffColor = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error);
        imageSetPixel($img, $cx + $xp * $x + $xa, $cy + $yp * ($y + 1) + $ya, $diffColor);
        imageLine($img, $cx + $xp * $x + $xa, $cy + $yp * $y + $ya, $cx + $xp * $x + $xa, $cy + $ya, $fillColor);
    }
    for ($y = 0; $y < $b; $y += 1) {
        $x = $a * sqrt(1 - $y * $y / ($b * $b));
        $error = $x - (int) $x;
        $x = (int) $x;
        $diffColor = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error);
        imageSetPixel($img, $cx + $xp * ($x + 1) + $xa, $cy + $yp * $y + $ya, $diffColor);
    }
}
开发者ID:rainbow-studio,项目名称:cmsms,代码行数:49,代码来源:imageSmoothArc_optimized.php

示例7: renderFrame

 public function renderFrame(float $t, int $width, int $height)
 {
     $image = \imageCreate($width, $height);
     $palette = [];
     foreach (self::PICO_8_PALETTE as list($red, $green, $blue)) {
         $palette[] = \imageColorAllocate($image, $red, $green, $blue);
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $value = ($this->function)($x - $width / 2, $y - $height / 2, $t);
             \imageSetPixel($image, $x, $y, $palette[self::mod(abs(floor($value)), count($palette))]);
         }
     }
     return $image;
 }
开发者ID:TazeTSchnitzel,项目名称:pico8bot.php,代码行数:15,代码来源:Renderer.php

示例8: make_img

function make_img($content)
{
    $timage = array(strlen($content) * 20 + 10, 28);
    // array(largeur, hauteur) de l'image; ici la largeur est fonction du nombre de lettre du contenu, on peut bien sur mettre une largeur fixe.
    $content = preg_replace('/(\\w)/', '\\1 ', $content);
    // laisse plus d'espace entre les lettres
    $image = imagecreatetruecolor($timage[0], $timage[1]);
    // création de l'image
    // definition des couleurs
    $fond = imageColorAllocate($image, 240, 255, 240);
    $grey = imageColorAllocate($image, 210, 210, 210);
    $text_color = imageColorAllocate($image, rand(0, 100), rand(0, 50), rand(0, 60));
    imageFill($image, 0, 0, $fond);
    // on remplit l'image de blanc
    //On remplit l'image avec des polygones
    for ($i = 0, $imax = mt_rand(3, 5); $i < $imax; $i++) {
        $x = mt_rand(3, 10);
        $poly = array();
        for ($j = 0; $j < $x; $j++) {
            $poly[] = mt_rand(0, $timage[0]);
            $poly[] = mt_rand(0, $timage[1]);
        }
        imageFilledPolygon($image, $poly, $x, imageColorAllocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255)));
    }
    // Création des pixels gris
    for ($i = 0; $i < $timage[0] * $timage[1] / rand(15, 18); $i++) {
        imageSetPixel($image, rand(0, $timage[0]), rand(0, $timage[1]), $grey);
    }
    // affichage du texte demandé; on le centre en hauteur et largeur (à peu près ^^")
    //imageString($image, 5, ceil($timage[0]-strlen($content)*8)/2, ceil($timage[1]/2)-9, $content, $text_color);
    $longueur_chaine = strlen($content);
    for ($ch = 0; $ch < $longueur_chaine; $ch++) {
        imagettftext($image, 18, mt_rand(-30, 30), 10 * ($ch + 1), mt_rand(18, 20), $text_color, 'res/georgia.ttf', $content[$ch]);
    }
    $type = function_exists('imageJpeg') ? 'jpeg' : 'png';
    @header('Content-Type: image/' . $type);
    @header('Cache-control: no-cache, no-store');
    $type == 'png' ? imagePng($image) : imageJpeg($image);
    ImageDestroy($image);
    exit;
}
开发者ID:shiooooooookun,项目名称:Nouweo_PHP,代码行数:41,代码来源:captcha.php

示例9: DoNoise

 function DoNoise($image, $G0, $C0)
 {
     $W = imageSX($image);
     $H = imageSY($image);
     for ($i = 0; $i < 768; $i++) {
         $arrLUT[$i] = $i < 512 ? $i < 255 ? 0 : $i - 256 : 255;
     }
     $G1 = $G0 / 2;
     $C1 = $C0 / 2;
     for ($y = 0; $y < $H; $y++) {
         for ($x = 0; $x < $W; $x++) {
             $P = imageColorAt($image, $x, $y);
             $R = $P >> 16 & 0xff;
             $G = $P >> 8 & 0xff;
             $B = $P >> 0 & 0xff;
             $N = rand(0, $G0) - $G1;
             $R += 255 + $N + mt_rand(0, $C0) - $C1;
             $G += 255 + $N + mt_rand(0, $C0) - $C1;
             $B += 255 + $N + mt_rand(0, $C0) - $C1;
             imageSetPixel($image, $x, $y, $arrLUT[$R] << 16 | $arrLUT[$G] << 8 | $arrLUT[$B]);
         }
     }
 }
开发者ID:joly,项目名称:web2project,代码行数:23,代码来源:Captcha.class.php

示例10: Cartoonfy

 function Cartoonfy($p_image, $p_triplevel, $p_diffspace)
 {
     $this->triplevel = (int) (2000.0 + 5000.0 * $p_triplevel);
     $this->diffspace = (int) ($p_diffspace * 32.0);
     $this->i0 = imageCreateFromString(file_get_contents($p_image));
     if ($this->i0) {
         $this->i1 = imageCreateTrueColor(imageSx($this->i0), imageSy($this->i0));
         for ($x = (int) $this->diffspace; $x < imageSx($this->i0) - (1 + (int) $this->diffspace); $x++) {
             for ($y = (int) $this->diffspace; $y < imageSy($this->i0) - (1 + (int) $this->diffspace); $y++) {
                 $t = Cartoonfy::GetMaxContrast($x, $y);
                 if ($t > $this->triplevel) {
                     imageSetPixel($this->i1, $x, $y, 0);
                 } else {
                     imageSetPixel($this->i1, $x, $y, Cartoonfy::FlattenColor(imageColorAt($this->i0, $x, $y)));
                 }
             }
             //usleep(1000);
         }
         imageDestroy($this->i0);
     } else {
         print "<b>" . $p_image . "</b> is not supported image format!";
         exit;
     }
 }
开发者ID:BGCX067,项目名称:facebookpiccartoonizer-svn-to-git,代码行数:24,代码来源:Cartoonfy.class.php

示例11: valiCode

/**
 * 生成验证码图片
 *
 * @param String $word 验证码在session中的变量名称
 */
function valiCode($word = 'randcode')
{
    Header("Content-type: image/png");
    $border = 1;
    //是否要边框 1要:0不要
    $how = 4;
    //验证码位数
    $w = $how * 15;
    //图片宽度
    $h = 25;
    //图片高度
    $fontsize = 32;
    //字体大小
    $alpha = "abcdefghijkmnpqrstuvwxyz";
    //验证码内容1:字母
    $number = "23456789";
    //验证码内容2:数字
    $randcode = "";
    //验证码字符串初始化
    srand((double) microtime() * 1000000);
    //初始化随机数种子
    $im = imagecreate($w, $h);
    //创建验证图片
    /*
     * 绘制基本框架
     */
    $bgcolor = imagecolorallocate($im, 255, 255, 255);
    //设置背景颜色
    imageFill($im, 0, 0, $bgcolor);
    //填充背景色
    if ($border) {
        $black = imagecolorallocate($im, 9, 9, 9);
        //设置边框颜色
        imagerectangle($im, 0, 0, $w - 1, $h - 1, $black);
        //绘制边框
    }
    /*
     * 逐位产生随机字符
     */
    for ($i = 0; $i < $how; $i++) {
        $alpha_or_number = mt_rand(0, 1);
        //字母还是数字
        $str = $alpha_or_number ? $alpha : $number;
        $which = mt_rand(0, strlen($str) - 1);
        //取哪个字符
        $code = substr($str, $which, 1);
        //取字符
        $j = !$i ? 4 : $j + 15;
        //绘字符位置
        $color3 = imagecolorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
        //字符随即颜色
        imagechar($im, $fontsize, $j, 3, $code, $color3);
        //绘字符
        $randcode .= $code;
        //逐位加入验证码字符串
    }
    /*
     * 如果需要添加干扰就将注释去掉
     *
     * 以下for()循环为绘背景干扰线代码
     */
    /* + -------------------------------绘背景干扰线 开始-------------------------------------------- + */
    for ($i = 0; $i < 5; $i++) {
        $color1 = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        //干扰线颜色
        imagearc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
        //干扰线
    }
    /* + -------------------------------绘背景干扰线 结束-------------------------------------- + */
    /*
     * 如果需要添加干扰就将注释去掉
     *
     * 以下for()循环为绘背景干扰点代码
     */
    /* + --------------------------------绘背景干扰点 开始------------------------------------------ + */
    for ($i = 0; $i < $how * 40; $i++) {
        $color2 = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        //干扰点颜色
        imageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
        //干扰点
    }
    /* + --------------------------------绘背景干扰点 结束------------------------------------------ + */
    //把验证码字符串写入session  方便提交登录信息时检验验证码是否正确  例如:$_POST['randcode'] = $_SESSION['randcode']
    session_start();
    $_SESSION[$word] = $randcode;
    /*绘图结束*/
    imagepng($im);
    imagedestroy($im);
    /*绘图结束*/
}
开发者ID:syalr,项目名称:vitime-meeting,代码行数:95,代码来源:captcha.php

示例12: imageCopyMergeAlpha

 /**
  * Copy an image on another one and converse transparency
  *
  * @param resource $destImg
  * @param resource $srcImg
  * @param integer $destX
  * @param integer $destY
  * @param integer $srcX
  * @param integer $srcY
  * @param integer $srcW
  * @param integer $srcH
  * @param integer $pct
  */
 public static function imageCopyMergeAlpha(&$destImg, &$srcImg, $destX, $destY, $srcX, $srcY, $srcW, $srcH, $pct = 0)
 {
     $destX = (int) $destX;
     $destY = (int) $destY;
     $srcX = (int) $srcX;
     $srcY = (int) $srcY;
     $srcW = (int) $srcW;
     $srcH = (int) $srcH;
     $pct = (int) $pct;
     $destW = imageSX($destImg);
     $destH = imageSY($destImg);
     for ($y = 0; $y < $srcH + $srcY; $y++) {
         for ($x = 0; $x < $srcW + $srcX; $x++) {
             if ($x + $destX >= 0 && $x + $destX < $destW && $x + $srcX >= 0 && $x + $srcX < $srcW && $y + $destY >= 0 && $y + $destY < $destH && $y + $srcY >= 0 && $y + $srcY < $srcH) {
                 $destPixel = imageColorsForIndex($destImg, imageColorat($destImg, $x + $destX, $y + $destY));
                 $srcImgColorat = imageColorat($srcImg, $x + $srcX, $y + $srcY);
                 if ($srcImgColorat > 0) {
                     $srcPixel = imageColorsForIndex($srcImg, $srcImgColorat);
                     $srcAlpha = 1 - $srcPixel['alpha'] / 127;
                     $destAlpha = 1 - $destPixel['alpha'] / 127;
                     $opacity = $srcAlpha * $pct / 100;
                     if ($destAlpha >= $opacity) {
                         $alpha = $destAlpha;
                     }
                     if ($destAlpha < $opacity) {
                         $alpha = $opacity;
                     }
                     if ($alpha > 1) {
                         $alpha = 1;
                     }
                     if ($opacity > 0) {
                         $destRed = round($destPixel['red'] * $destAlpha * (1 - $opacity));
                         $destGreen = round($destPixel['green'] * $destAlpha * (1 - $opacity));
                         $destBlue = round($destPixel['blue'] * $destAlpha * (1 - $opacity));
                         $srcRed = round($srcPixel['red'] * $opacity);
                         $srcGreen = round($srcPixel['green'] * $opacity);
                         $srcBlue = round($srcPixel['blue'] * $opacity);
                         $red = round(($destRed + $srcRed) / ($destAlpha * (1 - $opacity) + $opacity));
                         $green = round(($destGreen + $srcGreen) / ($destAlpha * (1 - $opacity) + $opacity));
                         $blue = round(($destBlue + $srcBlue) / ($destAlpha * (1 - $opacity) + $opacity));
                         if ($red > 255) {
                             $red = 255;
                         }
                         if ($green > 255) {
                             $green = 255;
                         }
                         if ($blue > 255) {
                             $blue = 255;
                         }
                         $alpha = round((1 - $alpha) * 127);
                         $color = imageColorAllocateAlpha($destImg, $red, $green, $blue, $alpha);
                         imageSetPixel($destImg, $x + $destX, $y + $destY, $color);
                     }
                 }
             }
         }
     }
 }
开发者ID:TahsinGokalp,项目名称:L3-Eticaret,代码行数:71,代码来源:ImageWorkshopLib.php

示例13: setnoise

 protected function setnoise()
 {
     for ($i = 0; $i < $this->noisenum; $i++) {
         $randColor = imageColorAllocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
         imageSetPixel($this->image, rand(0, $this->width), rand(0, $this->height), $randColor);
     }
 }
开发者ID:eon-hong,项目名称:anypay,代码行数:7,代码来源:spVerifyCode.php

示例14: imageSmoothArcDrawSegment

function imageSmoothArcDrawSegment(&$img, $cx, $cy, $a, $b, $aaAngleX, $aaAngleY, $color, $start, $stop, $seg)
{
    // Originally written from scratch by Ulrich Mierendorff, 06/2006
    // Rewritten and improved, 04/2007, 07/2007
    // Please do not use THIS function directly. Scroll down to imageSmoothArc(...).
    $fillColor = imageColorExactAlpha($img, $color[0], $color[1], $color[2], $color[3]);
    $xStart = abs($a * cos($start));
    $yStart = abs($b * sin($start));
    $xStop = abs($a * cos($stop));
    $yStop = abs($b * sin($stop));
    $dxStart = 0;
    $dyStart = 0;
    $dxStop = 0;
    $dyStop = 0;
    if ($xStart != 0) {
        $dyStart = $yStart / $xStart;
    }
    if ($xStop != 0) {
        $dyStop = $yStop / $xStop;
    }
    if ($yStart != 0) {
        $dxStart = $xStart / $yStart;
    }
    if ($yStop != 0) {
        $dxStop = $xStop / $yStop;
    }
    if (abs($xStart) >= abs($yStart)) {
        $aaStartX = true;
    } else {
        $aaStartX = false;
    }
    if ($xStop >= $yStop) {
        $aaStopX = true;
    } else {
        $aaStopX = false;
    }
    //$xp = +1; $yp = -1; $xa = +1; $ya = 0;
    for ($x = 0; $x < $a; $x += 1) {
        /*$y = $b * sqrt( 1 - ($x*$x)/($a*$a) );
          
          $error = $y - (int)($y);
          $y = (int)($y);
          
          $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 127-(127-$color[3])*$error );*/
        $_y1 = $dyStop * $x;
        $_y2 = $dyStart * $x;
        if ($xStart > $xStop) {
            $error1 = $_y1 - (int) $_y1;
            $error2 = 1 - $_y2 + (int) $_y2;
            $_y1 = $_y1 - $error1;
            $_y2 = $_y2 + $error2;
        } else {
            $error1 = 1 - $_y1 + (int) $_y1;
            $error2 = $_y2 - (int) $_y2;
            $_y1 = $_y1 + $error1;
            $_y2 = $_y2 - $error2;
        }
        /*
        if ($aaStopX)
            $diffColor1 = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 127-(127-$color[3])*$error1 );
        if ($aaStartX)
            $diffColor2 = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 127-(127-$color[3])*$error2 );
        */
        if ($seg == 0 || $seg == 2) {
            $i = $seg;
            if (!($start > $i * M_PI / 2 && $x > $xStart)) {
                if ($i == 0) {
                    $xp = +1;
                    $yp = -1;
                    $xa = +1;
                    $ya = 0;
                } else {
                    $xp = -1;
                    $yp = +1;
                    $xa = 0;
                    $ya = +1;
                }
                if ($stop < ($i + 1) * (M_PI / 2) && $x <= $xStop) {
                    $diffColor1 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error1);
                    $y1 = $_y1;
                    if ($aaStopX) {
                        imageSetPixel($img, $cx + $xp * $x + $xa, $cy + $yp * ($y1 + 1) + $ya, $diffColor1);
                    }
                } else {
                    $y = $b * sqrt(1 - $x * $x / ($a * $a));
                    $error = $y - (int) $y;
                    $y = (int) $y;
                    $diffColor = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error);
                    $y1 = $y;
                    if ($x < $aaAngleX) {
                        imageSetPixel($img, $cx + $xp * $x + $xa, $cy + $yp * ($y1 + 1) + $ya, $diffColor);
                    }
                }
                if ($start > $i * M_PI / 2 && $x <= $xStart) {
                    $diffColor2 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error2);
                    $y2 = $_y2;
                    if ($aaStartX) {
                        imageSetPixel($img, $cx + $xp * $x + $xa, $cy + $yp * ($y2 - 1) + $ya, $diffColor2);
                    }
                } else {
//.........这里部分代码省略.........
开发者ID:gdbhosale,项目名称:fancy-qr-code-generator,代码行数:101,代码来源:imageSmoothArc.php

示例15: osc_gd_resize

function osc_gd_resize($original_image, $dest_image, $dest_width, $dest_height, $force_size = '0')
{
    $img_type = false;
    switch (strtolower(substr(basename($original_image), strrpos(basename($original_image), '.') + 1))) {
        case 'jpg':
        case 'jpeg':
            if (imagetypes() & IMG_JPG) {
                $img_type = 'jpg';
            }
            break;
        case 'gif':
            if (imagetypes() & IMG_GIF) {
                $img_type = 'gif';
            }
            break;
        case 'png':
            if (imagetypes() & IMG_PNG) {
                $img_type = 'png';
            }
            break;
    }
    if ($img_type !== false) {
        list($orig_width, $orig_height) = getimagesize($original_image);
        $width = $dest_width;
        $height = $dest_height;
        $factor = max($orig_width / $width, $orig_height / $height);
        if ($force_size == '1') {
            $width = $dest_width;
        } else {
            $width = round($orig_width / $factor);
            $height = round($orig_height / $factor);
        }
        $im_p = imageCreateTrueColor($dest_width, $dest_height);
        imageAntiAlias($im_p, true);
        imagealphablending($im_p, false);
        imagesavealpha($im_p, true);
        $transparent = imagecolorallocatealpha($im_p, 255, 255, 255, 127);
        for ($x = 0; $x < $dest_width; $x++) {
            for ($y = 0; $y < $dest_height; $y++) {
                imageSetPixel($im_p, $x, $y, $transparent);
            }
        }
        $x = 0;
        $y = 0;
        if ($force_size == '1') {
            $width = round($orig_width * $dest_height / $orig_height);
            if ($width < $dest_width) {
                $x = floor(($dest_width - $width) / 2);
            }
        } else {
            $x = floor(($dest_width - $width) / 2);
            $y = floor(($dest_height - $height) / 2);
        }
        switch ($img_type) {
            case 'jpg':
                $im = imagecreatefromjpeg($original_image);
                break;
            case 'gif':
                $im = imagecreatefromgif($original_image);
                break;
            case 'png':
                $im = imagecreatefrompng($original_image);
                break;
        }
        imagecopyresampled($im_p, $im, $x, $y, 0, 0, $width, $height, $orig_width, $orig_height);
        switch ($img_type) {
            case 'jpg':
                imagejpeg($im_p, $dest_image);
                break;
            case 'gif':
                imagegif($im_p, $dest_image);
                break;
            case 'png':
                imagepng($im_p, $dest_image);
                break;
        }
        imagedestroy($im_p);
        imagedestroy($im);
        @chmod($dest_image, 0777);
    } else {
        return false;
    }
}
开发者ID:Doluci,项目名称:tomatocart,代码行数:83,代码来源:general.php


注:本文中的imageSetPixel函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。