Exemplo n.º 1
0
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);
    }
}
Exemplo n.º 2
0
	/**
	* 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;
		}
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
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();
}
Exemplo n.º 5
0
/**
 * 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);
    }
}
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);
    }
}
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
 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]);
         }
     }
 }
 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;
     }
 }
Exemplo n.º 11
0
/**
 * 生成验证码图片
 *
 * @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);
    /*绘图结束*/
}
Exemplo n.º 12
0
 /**
  * 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);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 13
0
 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);
     }
 }
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 {
                    $y2 = 0;
                }
                if ($y2 <= $y1) {
                    imageLine($img, $cx + $xp * $x + $xa, $cy + $yp * $y1 + $ya, $cx + $xp * $x + $xa, $cy + $yp * $y2 + $ya, $fillColor);
                }
            }
        }
        if ($seg == 1 || $seg == 3) {
            $i = $seg;
            if (!($stop < ($i + 1) * M_PI / 2 && $x > $xStop)) {
                if ($i == 1) {
                    $xp = -1;
                    $yp = -1;
                    $xa = 0;
                    $ya = 0;
                } else {
                    $xp = +1;
                    $yp = +1;
                    $xa = 1;
                    $ya = 1;
                }
                if ($start > $i * M_PI / 2 && $x < $xStart) {
                    $diffColor2 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error2);
                    $y1 = $_y2;
                    if ($aaStartX) {
                        imageSetPixel($img, $cx + $xp * $x + $xa, $cy + $yp * ($y1 + 1) + $ya, $diffColor2);
                    }
                } 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 ($stop < ($i + 1) * M_PI / 2 && $x <= $xStop) {
                    $diffColor1 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error1);
                    $y2 = $_y1;
                    if ($aaStopX) {
                        imageSetPixel($img, $cx + $xp * $x + $xa, $cy + $yp * ($y2 - 1) + $ya, $diffColor1);
                    }
                } else {
                    $y2 = 0;
                }
                if ($y2 <= $y1) {
                    imageLine($img, $cx + $xp * $x + $xa, $cy + $yp * $y1 + $ya, $cx + $xp * $x + $xa, $cy + $yp * $y2 + $ya, $fillColor);
                }
            }
        }
    }
    ///YYYYY
    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 );
          */
        $_x1 = $dxStop * $y;
        $_x2 = $dxStart * $y;
        if ($yStart > $yStop) {
            $error1 = $_x1 - (int) $_x1;
            $error2 = 1 - $_x2 + (int) $_x2;
            $_x1 = $_x1 - $error1;
            $_x2 = $_x2 + $error2;
        } else {
            $error1 = 1 - $_x1 + (int) $_x1;
            $error2 = $_x2 - (int) $_x2;
            $_x1 = $_x1 + $error1;
            $_x2 = $_x2 - $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 && $y > $yStop)) {
                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) && $y <= $yStop) {
                    $diffColor1 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error1);
                    $x1 = $_x1;
                    if (!$aaStopX) {
                        imageSetPixel($img, $cx + $xp * ($x1 - 1) + $xa, $cy + $yp * $y + $ya, $diffColor1);
                    }
                }
                if ($start > $i * M_PI / 2 && $y < $yStart) {
                    $diffColor2 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error2);
                    $x2 = $_x2;
                    if (!$aaStartX) {
                        imageSetPixel($img, $cx + $xp * ($x2 + 1) + $xa, $cy + $yp * $y + $ya, $diffColor2);
                    }
                } else {
                    $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);
                    $x1 = $x;
                    if ($y < $aaAngleY && $y <= $yStop) {
                        imageSetPixel($img, $cx + $xp * ($x1 + 1) + $xa, $cy + $yp * $y + $ya, $diffColor);
                    }
                }
            }
        }
        if ($seg == 1 || $seg == 3) {
            $i = $seg;
            if (!($stop < ($i + 1) * M_PI / 2 && $y > $yStart)) {
                if ($i == 1) {
                    $xp = -1;
                    $yp = -1;
                    $xa = 0;
                    $ya = 0;
                } else {
                    $xp = +1;
                    $yp = +1;
                    $xa = 1;
                    $ya = 1;
                }
                if ($start > $i * M_PI / 2 && $y < $yStart) {
                    $diffColor2 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error2);
                    $x1 = $_x2;
                    if (!$aaStartX) {
                        imageSetPixel($img, $cx + $xp * ($x1 - 1) + $xa, $cy + $yp * $y + $ya, $diffColor2);
                    }
                }
                if ($stop < ($i + 1) * M_PI / 2 && $y <= $yStop) {
                    $diffColor1 = imageColorExactAlpha($img, $color[0], $color[1], $color[2], 127 - (127 - $color[3]) * $error1);
                    $x2 = $_x1;
                    if (!$aaStopX) {
                        imageSetPixel($img, $cx + $xp * ($x2 + 1) + $xa, $cy + $yp * $y + $ya, $diffColor1);
                    }
                } else {
                    $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);
                    $x1 = $x;
                    if ($y < $aaAngleY && $y < $yStart) {
                        imageSetPixel($img, $cx + $xp * ($x1 + 1) + $xa, $cy + $yp * $y + $ya, $diffColor);
                    }
                }
            }
        }
    }
}
Exemplo n.º 15
0
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;
    }
}
Exemplo n.º 16
0
<?php

$im = imageCreateTrueColor(150, 50);
$color = imageColorAllocate($im, 128, 128, 128);
imageFill($im, 10, 10, $color);
$color = imageColorAllocate($im, 255, 255, 255);
for ($i = 0; $i < 800; $i++) {
    $randW = mt_rand(0, imageSX($im));
    $randH = mt_rand(0, imageSY($im));
    imageSetPixel($im, $randW, $randH, $color);
}
imageSetThickness($im, 2);
$color = imageColorAllocate($im, 100, 100, 100);
imageLine($im, 10, 30, 130, 20, $color);
$color = imageColorAllocate($im, 70, 70, 70);
$n1 = mt_rand(0, 9);
imageTtfText($im, 25, 10, mt_rand(2, 10), mt_rand(25, 45), $color, "times.ttf", $n1);
$color = imageColorAllocate($im, 255, 0, 50);
$str = "ABCDIFGHIJKLMNOPKASTUVWXYZ";
$nw = mt_rand(0, 15);
$n2 = $str[$nw];
imageTtftext($im, 22, -10, mt_rand(25, 35), mt_rand(25, 45), $color, "times.ttf", $n2);
$color = imageColorAllocate($im, 50, 50, 50);
$n3 = mt_rand(0, 9);
imageTtfText($im, 25, 15, mt_rand(60, 70), mt_rand(25, 45), $color, "times.ttf", $n3);
$color = imageColorAllocate($im, 250, 250, 250);
$nw2 = mt_rand(15, 25);
$n4 = $str[$nw2];
imageTtfText($im, 22, 30, mt_rand(90, 100), mt_rand(25, 45), $color, "times.ttf", $n4);
$color = imageColorAllocate($im, 255, 220, 70);
$n5 = mt_rand(0, 9);
//}
foreach ($matrice as $i => $ligne) {
    $max_ligne = max($ligne);
    foreach ($ligne as $j => $val) {
        $max_ligne == 0 ? $d = 0 : ($d = $val / $max_ligne);
        if ($d >= $discretisation_max) {
            $d = 1;
        } elseif ($d <= $discretisation_min) {
            $d = 0;
        }
        $color = dictionnaire_color($image, $dico_color, $d);
        for ($sc = $i * $zoom + $margin_left; $sc < ($i + 1) * $zoom + $margin_left; ++$sc) {
            for ($sl = $j * $zoom + $margin_top; $sl < ($j + 1) * $zoom + $margin_top; ++$sl) {
                imageSetPixel($image, $sc, $sl, $color);
            }
        }
    }
}
for ($i = 0; $i < 10; ++$i) {
    $x = ($height - $margin_top) / 10 * $i + $margin_top;
    $y = ($lengh - $margin_left) / 10 * $i + $margin_left;
    imagestring($image, 1, 0, $x + 2, "{$i}" . '0%', $dico_color['red']);
    for ($j = 0; $j < $margin_left; ++$j) {
        imageSetPixel($image, $j, $x, $dico_color['red']);
    }
    imagestring($image, 1, $y + 2, 0, "{$i}" . '0%', $dico_color['red']);
    for ($j = 0; $j < $margin_top; ++$j) {
        imageSetPixel($image, $y, $j, $dico_color['red']);
    }
}
imagepng($image, "out.png");
Exemplo n.º 18
0
require_once '../../../../../wp-load.php';
// Captcha image size
$imageWidth = 320;
$imageHeight = 50;
// Number of characters in captcha image - captcha length
$charsNumber = 6;
// Random characters array
$characters = array_merge(range(0, 9), range('a', 'z'));
shuffle($characters);
// Create captcha image
$captchaImage = imageCreateTrueColor($imageWidth, $imageHeight);
for ($pixelX = 0; $pixelX < $imageWidth; $pixelX++) {
    for ($pixelY = 0; $pixelY < $imageHeight; $pixelY++) {
        $randomPixelColor = imageColorAllocate($captchaImage, 255, 255, 255);
        imageSetPixel($captchaImage, $pixelX, $pixelY, $randomPixelColor);
    }
}
$captchaText = "";
// Full captcha text
$charImageStep = $imageWidth / ($charsNumber + 1);
$charWritePoint = $charImageStep;
// Write captcha characters to the image
for ($i = 0; $i < $charsNumber; $i++) {
    $nextChar = $characters[mt_rand(0, count($characters) - 1)];
    $captchaText .= $nextChar;
    // Font properties
    $randomFontSize = mt_rand(25, 30);
    // Random character size to spice things a little bit :)
    $randomFontAngle = mt_rand(-25, 25);
    // Twist the character a little bit
Exemplo n.º 19
0
 protected function create_images($text, $hash)
 {
     // Check parameters.
     if (trim($text) === '') {
         return array();
     }
     if (!mb_check_encoding($text, 'UTF-8')) {
         throw new IMGTextException('String is not valid UTF-8');
     }
     $font_filename = $this->font_dir . '/' . $this->font_name . '.' . $this->font_ext;
     if (!file_exists($font_filename)) {
         throw new IMGTextException('Font not found: ' . $font);
     }
     $font_size = (int) $this->font_size;
     if ($font_size <= 0) {
         throw new IMGTextException('Invalid font size: ' . $size);
     }
     if (!preg_match('/^#?(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/', $this->color)) {
         throw new IMGTextException('Invalid text color: ' . $this->color);
     }
     if ($this->background_color !== false && !preg_match('/^#?(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/', $this->background_color)) {
         throw new IMGTextException('Invalid background color: ' . $this->background_color);
     }
     if (!is_array($this->padding) || count($this->padding) != 4) {
         throw new IMGTextException('Invalid padding. Please use array with 4 members.');
     }
     if (!is_array($this->shadow_offset) || count($this->shadow_offset) != 2) {
         throw new IMGTextException('Invalid shadow offset. Please use array with 2 members.');
     }
     if ($this->shadow_opacity < 0 || $this->shadow_opacity > 127) {
         throw new IMGTextException('Invalid shadow opacity. Please use a value between 0 (opaque) and 127 (transparent).');
     }
     // Split the text into words.
     $words = preg_split('/\\s+/u', $text);
     // Parse the padding amount.
     $padding_top = intval($this->padding[0]);
     $padding_right = intval($this->padding[1]);
     $padding_bottom = intval($this->padding[2]);
     $padding_left = intval($this->padding[3]);
     // Get size information for each word. We do this first, in order to find out the maximum height.
     $fragments = array();
     $max_height = 0;
     $max_top = 0;
     foreach ($words as $w) {
         $w = trim($w);
         if ($w === '') {
             continue;
         }
         // Get the bounding box size.
         $bounds = imageTTFBBox($font_size, 0, $font_filename, $w);
         // Get more useful information from GD's return values.
         $width = $bounds[2] - $bounds[0];
         $height = $bounds[3] - $bounds[5];
         $left = -$bounds[6] - 1;
         $top = -$bounds[7] - 1;
         // Update the max height/top values if necessary.
         if ($height > $max_height) {
             $max_height = $height;
         }
         if ($top > $max_top) {
             $max_top = $top;
         }
         $fragments[] = array($w, $width, $height, $left, $top);
     }
     // Create images for each word.
     $count = 1;
     $return = array();
     foreach ($fragments as $f) {
         list($w, $width, $height, $left, $top) = $f;
         $img_width = $width + $padding_left + $padding_right;
         $img_height = $this->image_height ? $this->image_height : $max_height + $padding_top + $padding_bottom;
         $text_left = $left + $padding_left;
         $text_top = $max_top + $padding_top;
         // Adjust image size and text location if there's a shadow.
         if ($this->shadow) {
             if ($this->shadow_offset[0] < 0) {
                 $shadow_space_left = $this->shadow_blur - $this->shadow_offset[0];
                 $shadow_space_right = max(0, $this->shadow_blur + abs($this->shadow_offset[0]));
                 $shadow_left = $text_left + $shadow_space_left;
                 $text_left = $text_left + $shadow_space_left - $this->shadow_offset[0];
             } else {
                 $shadow_space_left = max(0, $this->shadow_blur - $this->shadow_offset[0]);
                 $shadow_space_right = $this->shadow_blur + $this->shadow_offset[0];
                 $shadow_left = $text_left + $shadow_space_left + $this->shadow_offset[0];
                 $text_left = $text_left + $shadow_space_left;
             }
             if ($this->shadow_offset[1] < 0) {
                 $shadow_space_top = $this->shadow_blur - $this->shadow_offset[1];
                 $shadow_space_bottom = max(0, $this->shadow_blur + abs($this->shadow_offset[1]));
                 $shadow_top = $text_top + $shadow_space_top;
                 $text_top = $text_top + $shadow_space_top - $this->shadow_offset[1];
             } else {
                 $shadow_space_top = max(0, $this->shadow_blur - $this->shadow_offset[1]);
                 $shadow_space_bottom = $this->shadow_blur + $this->shadow_offset[1];
                 $shadow_top = $text_top + $shadow_space_top + $this->shadow_offset[1];
                 $text_top = $text_top + $shadow_space_top;
             }
             $img_width += $shadow_space_left + $shadow_space_right;
             $img_height += $shadow_space_top + $shadow_space_bottom;
         }
         // Initialize the image and draw the background.
         $img = imageCreateTrueColor($img_width, $img_height);
         if ($this->background_color === false) {
             imageSaveAlpha($img, true);
             imageAlphaBlending($img, false);
             $img_background_color = imageColorAllocateAlpha($img, 255, 255, 255, 127);
             imageFilledRectangle($img, 0, 0, $img_width, $img_height, $img_background_color);
             imageAlphaBlending($img, true);
         } else {
             $img_background_colors = $this->hex2rgb($this->background_color);
             $img_background_color = imageColorAllocate($img, $img_background_colors[0], $img_background_colors[1], $img_background_colors[2]);
             imageFilledRectangle($img, 0, 0, $img_width, $img_height, $img_background_color);
         }
         // Draw the shadow.
         if ($this->shadow) {
             // Blurred shadow on a transparent background needs special treatment because of GD's limitations.
             if ($this->shadow_blur && $this->background_color === false) {
                 // Create a temporary image for the shadow.
                 $temp = imageCreateTrueColor($img_width, $img_height);
                 imageSaveAlpha($temp, true);
                 imageFilledRectangle($temp, 0, 0, $img_width, $img_height, imageColorAllocate($temp, 127, 127, 127));
                 // Draw the shadow text on the temporary image, and blur it.
                 $temp_text_color = imageColorAllocate($temp, $this->shadow_opacity, $this->shadow_opacity, $this->shadow_opacity);
                 imageTTFText($temp, $font_size, 0, $shadow_left, $shadow_top, $temp_text_color, $font_filename, $w);
                 for ($i = 0; $i < $this->shadow_blur; $i++) {
                     imageFilter($temp, IMG_FILTER_GAUSSIAN_BLUR);
                 }
                 // Use the blurred shadow as an alpha mask on the original image.
                 $shadow_colors = $this->hex2rgb($this->shadow_color);
                 for ($x = 0; $x < $img_width; $x++) {
                     for ($y = 0; $y < $img_height; $y++) {
                         $alpha = imageColorAt($temp, $x, $y) & 0xff;
                         imageSetPixel($img, $x, $y, imageColorAllocateAlpha($img, $shadow_colors[0], $shadow_colors[1], $shadow_colors[2], $alpha));
                     }
                 }
                 imageDestroy($temp);
             } else {
                 $shadow_colors = $this->hex2rgb($this->shadow_color);
                 $shadow_color = imageColorAllocateAlpha($img, $shadow_colors[0], $shadow_colors[1], $shadow_colors[2], $this->shadow_opacity);
                 imageTTFText($img, $font_size, 0, $shadow_left, $shadow_top, $shadow_color, $font_filename, $w);
                 for ($i = 0; $i < $this->shadow_blur; $i++) {
                     imageFilter($img, IMG_FILTER_GAUSSIAN_BLUR);
                 }
             }
         }
         // Draw the word.
         $text_colors = $this->hex2rgb($this->color);
         $text_color = imageColorAllocate($img, $text_colors[0], $text_colors[1], $text_colors[2]);
         imageTTFText($img, $font_size, 0, $text_left, $text_top, $text_color, $font_filename, $w);
         // Save to a PNG file.
         $filename = '/imgtext.' . $hash . '.word-' . str_pad($count, 3, '0', STR_PAD_LEFT) . '.png';
         imagePNG($img, $this->cache_local_dir . $filename);
         imageDestroy($img);
         // Add information about this word to the return array.
         $return[] = array('word' => $w, 'path' => $this->cache_url_prefix . $filename);
         $count++;
     }
     // Returns a list of dictionaries, each containing a word and the corresponding image URL.
     return $return;
 }
Exemplo n.º 20
0
 static function setnoise()
 {
     for ($i = 0; $i < self::$noisenum; $i++) {
         $randColor = imageColorAllocate(self::$_image, rand(0, 255), rand(0, 255), rand(0, 255));
         imageSetPixel(self::$_image, rand(0, self::$width), rand(0, self::$height), $randColor);
     }
 }
Exemplo n.º 21
0
$farbe2 = mt_rand("0", "100");
$farbe3 = mt_rand("0", "100");
// Verteile die Farben
$rahmen = imageColorAllocate($bild, 0, 0, 0);
// Rahmenfarbe
$farbe = imageColorAllocate($bild, $farbe1, $farbe2, $farbe3);
// Textfarbe
// Hole die Zahlen der Punkte zum Zeichnen
$alle_punkte = $size_x * $size_y / 15;
// Zeichne viele Punkte mit der selben Farbe des Textes
for ($zaehler = 0; $zaehler < $alle_punkte; $zaehler++) {
    // Erzeuge die Zufallspositionen der Punkte
    $pos_x = mt_rand("0", $size_x);
    $pos_y = mt_rand("0", $size_y);
    // Zeichne die Punkte
    imageSetPixel($bild, $pos_x, $pos_y, $farbe);
}
// Zeichne den Rahmen
imageRectangle($bild, 0, 0, $size_x - 1, $size_y - 1, $rahmen);
// Koordinaten der Position von der Zufallszahl
$pos_x = 50;
// links
$pos_y = 10;
// oben
// Zeichne die Zufallszahl
imageString($bild, 5, $pos_x, $pos_y, $zufallszahl, $farbe);
// Sende "browser header"
header("Content-Type: image/png");
// Sende das Bild zum Browser
echo imagePNG($bild);
// Lösche das Bild
Exemplo n.º 22
0
 public function drewPixel(&$im, $x, $y, $color)
 {
     imageSetPixel($im, $x, $y, $color);
 }
<?php

/* Создание изображения */
// $i = imageCreate(500, 300);
$i = imageCreateTrueColor(500, 300);
/* Подготовка к работе */
imageAntiAlias($i, true);
$red = imageColorAllocate($i, 255, 0, 0);
$white = imageColorAllocate($i, 0xff, 0xff, 0xff);
$black = imageColorAllocate($i, 0, 0, 0);
$green = imageColorAllocate($i, 0, 255, 0);
$blue = imageColorAllocate($i, 0, 0, 255);
$grey = imageColorAllocate($i, 192, 192, 192);
imageFill($i, 0, 0, $grey);
/* Рисуем примитивы */
imageSetPixel($i, 10, 10, $black);
imageLine($i, 20, 20, 280, 180, $red);
imageRectangle($i, 20, 20, 280, 180, $blue);
//array of dots
$points = [120, 120, 100, 200, 300, 200];
imagePolygon($i, $points, 3, $green);
imageEllipse($i, 200, 150, 300, 200, $red);
// imageArc($i, 210, 160, 300, 200, 0, 90, $black);
imageFilledArc($i, 200, 150, 300, 200, 0, 40, $red, IMG_ARC_PIE);
/* Рисуем текст */
imageString($i, 5, 150, 200, 'php7', $black);
imageCharUp($i, 3, 200, 200, 'PHP5', $blue);
imageTtfText($i, 30, 10, 300, 150, $green, 'arial.ttf', 'PHP7');
/* Отдаем изображение */
// header("Content-type: image/gif");
// imageGif($i);
Exemplo n.º 24
0
function _effect_distort($image, $factor = 40, $grad = 1, $method = 0)
{
    // from http://www.codeproject.com/aspnet/CaptchaNET_2.asp Farshid Hosseini
    $width = imagesx($image);
    $height = imagesy($image);
    $fact = $factor / 25;
    $disx = rand(4, 10) * (rand(0, 1) ? 1 : -1) * $fact;
    $disy = rand(4, 12) * (rand(0, 1) ? 1 : -1) * $fact;
    $yf = rand(30, 45) * $fact;
    $xf = rand(80, 95) * $fact;
    // from http://www.captcha.ru/captchas/multiwave/
    // KCAPTCHA randomize
    // periods
    $rand1 = mt_rand(750000, 1200000) / 10000000;
    $rand2 = mt_rand(750000, 1200000) / 10000000;
    $rand3 = mt_rand(750000, 1200000) / 10000000;
    $rand4 = mt_rand(750000, 1200000) / 10000000;
    // phases
    $rand5 = mt_rand(0, 31415926) / 10000000;
    $rand6 = mt_rand(0, 31415926) / 10000000;
    $rand7 = mt_rand(0, 31415926) / 10000000;
    $rand8 = mt_rand(0, 31415926) / 10000000;
    // amplitudes
    $rand9 = mt_rand(330, 420) / 110;
    $rand10 = mt_rand(330, 450) / 110;
    // make new canvas img
    $canvas = imagecreate($width, $height);
    $bgcolor = imagecolorsforindex($image, 0);
    $new = imagecolorallocate($canvas, $bgcolor['red'], $bgcolor['green'], $bgcolor['blue']);
    $fgcolor = imagecolorsforindex($image, 1);
    $new = imagecolorallocate($canvas, $fgcolor['red'], $fgcolor['green'], $fgcolor['blue']);
    imagepalettecopy($canvas, $image);
    for ($y = 0; $y < $height; $y++) {
        for ($x = 0; $x < $width; $x++) {
            if (empty($method)) {
                // Adds a simple wave
                $newX = $x + $disx * Sin(3.141592 * $y / $xf);
                $t = ($x - $width / 2) / $yf * 2.4;
                $t = $t * $t;
                $newY = $y + $disy * exp(-$t) * sin(3.141592 * $x / $yf);
            } else {
                // KCAPTCHA method
                $newX = $x + (sin($x * $rand1 + $rand5) + sin($y * $rand3 + $rand6)) * $rand9;
                $newY = $y + (sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8)) * $rand10;
            }
            if ($grad) {
                # with gradient effect based on above functions
                if ($newY > $height or $newY < 0) {
                    $newY = 0;
                }
                if ($newX < 0) {
                    $newX = 0;
                } else {
                    if ($newX > $width) {
                        $newX = $width;
                    }
                }
                $newcolor = _antialias_color($image, $x, $y, $newX, $newY);
                if ($newcolor === false) {
                    // this is background color
                    $newcolor = $bgcolor;
                }
                $r = $newcolor['red'];
                $g = $newcolor['green'];
                $b = $newcolor['blue'];
                $gratio = 120;
                $bratio = 100;
                $pratio = 125;
                $red = (int) $r;
                $green = (int) ($newX / $width * $gratio + $g / 255 * $pratio);
                $blue = (int) ($newY / $height * $bgatio + $b / 255 * $pratio);
                $new = imagecolorallocate($canvas, $red, $green, $blue);
                $new = imagecolorclosest($canvas, $red, $green, $blue);
                imageSetPixel($canvas, $x, $y, $new);
            } else {
                if ($newX < 0 || $newY < 0 || $newX >= $width - 1 || $newY >= $height - 1) {
                    continue;
                }
                $newcolor = _antialias_color($image, $x, $y, $newX, $newY);
                // ignore background
                if ($newcolor === false) {
                    continue;
                }
                $red = $newcolor['red'];
                $green = $newcolor['green'];
                $blue = $newcolor['blue'];
                $new = imagecolorallocate($canvas, $red, $green, $blue);
                $new = imagecolorclosest($canvas, $red, $green, $blue);
                imageSetPixel($canvas, $x, $y, $new);
            }
        }
    }
    imageCopy($image, $canvas, 0, 0, 0, 0, $width, $height);
}
Exemplo n.º 25
0
 private function setDisturbColor()
 {
     for ($i = 0; $i < 100; $i++) {
         $randColor = imageColorAllocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
         imageSetPixel($this->image, rand(1, $this->width - 2), rand(1, $this->height - 2), $randColor);
     }
 }
Exemplo n.º 26
0
 /** Saves a 2 pixel by two pixel dither of the two nearest web-safe colors
  *in the filename specified. If no filename is given, the filename defaults 
  *to 'xxxxxx_websafe.png'; in other words, white would be saved as 
  *'ffffff_websafe.png'.  Requires that PHP be compiled with GD and PNG support.
  *@param string filename The name of the file to save the dither pattern as.
  *@return string $filename The name of the file the background was saved as.
  *@access public
  */
 function renderWebSafeDither($filename = '')
 {
     if ($filename == '') {
         $filename = strtolower($this->hex) . '_websafe.png';
     }
     $safe = $this->getWebSafeDither();
     $im = imagecreate(2, 2);
     $col1 = imagecolorallocate($im, $safe[0]->r, $safe[0]->g, $safe[0]->b);
     $col2 = imagecolorallocate($im, $safe[1]->r, $safe[1]->g, $safe[1]->b);
     imageSetPixel($im, 0, 0, $col1);
     imageSetPixel($im, 1, 1, $col1);
     imageSetPixel($im, 0, 1, $col2);
     imageSetPixel($im, 1, 0, $col2);
     imagepng($im, $filename);
     return $filename;
 }
Exemplo n.º 27
0
<?php

include 'phprandom.php';
$img = imageCreateTrueColor(256, 256);
$colors = array();
for ($i = 0; $i < 256; $i++) {
    $colors[$i] = imageColorAllocate($img, $i, $i, $i);
}
for ($i = 0; $i < 256; $i++) {
    $random = PHPRandom::getBinary(256);
    for ($j = 0; $j < 256; $j++) {
        $value = ord(substr($random, $j, 1));
        imageSetPixel($img, $i, $j, $colors[$value]);
    }
}
header('Content-Type: image/png');
imagePNG($img);
imageDestroy($img);
Exemplo n.º 28
0
for ($a = 0; $a < 7; $a++) {
    $arcs[$a]["x"] = mt_rand(0, imageSX($image));
    $arcs[$a]["y"] = mt_rand(0, imageSY($image));
    $arcs[$a]["width"] = mt_rand(0, imageSX($image));
    $arcs[$a]["height"] = mt_rand(0, imageSY($image));
    $arcs[$a]["u1"] = mt_rand(0, 360);
    $arcs[$a]["u2"] = mt_rand(0, 360);
    $arcs[$a]["color"] = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    imageSetThickness($image, mt_rand(1, 3));
    imageArc($image, $arcs[$a]["x"], $arcs[$a]["y"], $arcs[$a]["width"], $arcs[$a]["height"], $arcs[$a]["u1"], $arcs[$a]["u2"], $arcs[$a]["color"]);
}
for ($p = 0; $p < 999; $p++) {
    $x = mt_rand(0, imageSX($image));
    $y = mt_rand(0, imageSY($image));
    $color = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    imageSetPixel($image, $x, $y, $color);
}
for ($s = 0; $s < 5; $s++) {
    $letters[$s]["size"] = mt_rand(25, 35);
    $letters[$s]["corner"] = mt_rand(-20, 20);
    if ($s === 0) {
        $letters[$s]["x"] = 10;
    } else {
        $letters[$s]["x"] = $s * 35;
    }
    $letters[$s]["color"] = imagecolorallocate($image, 255, 255, mt_rand(0, 255));
    $letters[$s]["sym"] = chr(mt_rand(97, 122));
    imagettftext($image, $letters[$s]["size"], $letters[$s]["corner"], $letters[$s]["x"], 40, $letters[$s]["color"], $dir . "verdana.ttf", $letters[$s]["sym"]);
    $string .= $letters[$s]["sym"];
}
$_SESSION["key"] = $string;
    }
    $ac = array_values($array_corres);
    $matrice[] = $ac;
}
$height = count($matrice) * $zoom;
$lengh = count(reset($matrice)) * $zoom;
$image = imagecreate($height, $lengh);
$dico_color = array();
dictionnaire_color($image, $dico_color, 0);
$max_matrice = 0;
foreach ($matrice as $ligne) {
    $max_matrice = max($max_matrice, max($ligne));
}
foreach ($matrice as $i => $ligne) {
    //  $max_ligne = max($ligne);
    foreach ($ligne as $j => $val) {
        $max_matrice == 0 ? $d = 0 : ($d = $val / $max_matrice);
        if ($d >= $discretisation_max) {
            $d = 1;
        } elseif ($d <= $discretisation_min) {
            $d = 0;
        }
        $color = dictionnaire_color($image, $dico_color, $d);
        for ($sc = $i * $zoom; $sc < ($i + 1) * $zoom; ++$sc) {
            for ($sl = $j * $zoom; $sl < ($j + 1) * $zoom; ++$sl) {
                imageSetPixel($image, $sc, $sl, $color);
            }
        }
    }
}
imagepng($image, "out.png");
Exemplo n.º 30
0
 /**
  * @param $resource
  * @param $color
  * @return bool
  */
 public function set_part_color(&$resource, $color)
 {
     $replace_color = $this->HEX2RGB($color);
     if (LITE_RECOLOR_FUNCTION) {
         imageFilter($resource, IMG_FILTER_COLORIZE, $replace_color[0] - 255, $replace_color[1] - 255, $replace_color[2] - 255);
     } else {
         $width = imageSX($resource);
         $height = imageSY($resource);
         for ($y = 0; $y < $height; $y++) {
             for ($x = 0; $x < $width; $x++) {
                 $rgb = imageColorsForIndex($resource, imageColorAt($resource, $x, $y));
                 $nr = max(round($rgb['red'] * $replace_color[0] / 255), 0);
                 $ng = max(round($rgb['green'] * $replace_color[1] / 255), 0);
                 $nb = max(round($rgb['blue'] * $replace_color[2] / 255), 0);
                 imageSetPixel($resource, $x, $y, imageColorAllocateAlpha($resource, $nr, $ng, $nb, $rgb['alpha']));
             }
         }
     }
     return true;
 }