Example #1
2
function MyImageBlur($im, $pct) {
	// w00t. my very own blur function
	// in GD2, there's a gaussian blur function. smarmy bastards. ;-)
	$width = imagesx($im);
	$height = imagesy($im);
	$temp_im = ImageCreate($width, $height);
	$bg = ImageColorAllocate($temp_im, 255, 255, 255);
	// preserves transparency if in orig image
	ImageColorTransparent($temp_im, $bg);
	// fill bg
	ImageFill($temp_im, 0, 0, $bg);
	$distance = 1;
	// emboss:
	ImageCopyMerge($temp_im, $im, 0, 0, $distance, $distance, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, -$distance, -$distance, 0, 0, $width, $height, $pct);
	ImageFill($temp_im, 0, 0, $bg);
	ImageCopyMerge($temp_im, $im, 0, $distance, $distance, 0, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, $distance, 0, 0, $distance, $width, $height, $pct);
	// blur:
	ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, $pct);
	ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height, $pct);
	ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width, $height, $pct);
	// remove temp image
	ImageDestroy($temp_im);
	return $im;
}
Example #2
0
function drawRating($rating, $max, $type)
{
    if ($type == 0) {
        $image = imagecreatetruecolor(102, 15);
        $back = ImageColorAllocate($image, 250, 250, 250);
        $border = ImageColorAllocate($image, 0, 0, 0);
        $fill = ImageColorAllocate($image, 0, 235, 0);
        ImageFilledRectangle($image, 0, 0, 101, 14, $back);
        ImageFilledRectangle($image, 1, 1, $rating / $max * 100, 14, $fill);
        ImageRectangle($image, 0, 0, 101, 14, $border);
        $textcolor = imagecolorallocate($image, 0, 0, 0);
        imagestring($image, 5, 35, 0, $rating / $max * 100 . '%', $textcolor);
    } else {
        if ($rating > $max) {
            $rating = $max;
        }
        $image = imagecreatetruecolor(10 * ($rating + 2) + 2, 15);
        $back = ImageColorAllocate($image, 250, 250, 250);
        $border = ImageColorAllocate($image, 0, 0, 0);
        $fill = ImageColorAllocate($image, 235, 0, 0);
        ImageFilledRectangle($image, 0, 0, 10 * ($rating + 2) + 1, 14, $back);
        ImageFilledRectangle($image, 1, 1, 10 * $rating, 14, $fill);
        ImageRectangle($image, 0, 0, 10 * $rating + 1, 14, $border);
        $textcolor = imagecolorallocate($image, 0, 0, 0);
        imagestring($image, 5, 10 * ($rating + 1), 0, $rating, $textcolor);
    }
    imagepng($image);
    imagedestroy($image);
}
 public function reflect()
 {
     $transparency_step = (100 - $this->transparency) / $this->gradient_height;
     $background = imagecreatetruecolor($this->imgWidth, $this->gradient_height + $this->imgHeight);
     $gdGradientColor = ImageColorAllocate($background, 255, 255, 255);
     $newImage = imagecreatetruecolor($this->imgWidth, $this->imgHeight);
     for ($x = 0; $x < $this->imgWidth; $x++) {
         for ($y = 0; $y < $this->imgHeight; $y++) {
             imagecopy($newImage, $this->img, $x, $this->imgHeight - $y - 1, $x, $y, 1, 1);
         }
     }
     imagecopymerge($background, $newImage, 0, $this->imgHeight, 0, 0, $this->imgWidth, $this->imgHeight, 100);
     imagecopymerge($background, $this->img, 0, 0, 0, 0, $this->imgWidth, $this->imgHeight, 100);
     $gradient_line = imagecreatetruecolor($this->imgWidth, 1);
     //voir si on garde ça et la suite
     // Next we draw a GD line into our gradient_line
     imageline($gradient_line, 0, 0, $this->imgWidth, 0, $gdGradientColor);
     for ($i = $this->imgHeight; $i < $this->gradient_height + $this->imgHeight; $i++) {
         imagecopymerge($background, $gradient_line, 0, $i, 0, 0, $this->imgWidth, 1, $this->transparency);
         if ($this->transparency != 100) {
             $this->transparency += $transparency_step;
         }
     }
     $this->img = $background;
 }
Example #4
0
function capcha($salt)
{
    srand(time());
    $md5_hash = md5(rand(0, 9999));
    $security_code = substr($md5_hash, 25, 5);
    $enc = md5($security_code . $salt);
    $_SESSION['count'] = $enc;
    $secure = $_SESSION['count'];
    // echo "--------------------------$secure<br>";
    $width = 50;
    $height = 24;
    $image = ImageCreate($width, $height);
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 100, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    ImageFill($image, 0, 0, $white);
    //Add randomly generated string in white to the image
    ImageString($image, 10, 4, 4, $security_code, $black);
    // ImageRectangle($image,0,16,$width-1,$height-1,$grey);
    imageline($image, 0, $height / 2, $width, $height / 2, $grey);
    imageline($image, $width / 2, 0, $width / 2, $height, $grey);
    header("Content-Type: image/jpeg");
    header("Cache-Control: no-cache, must-revalidate");
    ImageJpeg($image);
    ImageDestroy($image);
}
Example #5
0
function create_image()
{
    //Let's generate a totally random string using md5
    $md5_hash = md5(rand(0, 999));
    //We don't need a 32 character long string so we trim it down to 5
    $security_code = substr($md5_hash, 15, 5);
    //Set the session to store the security code
    $_SESSION["captchaCode"] = $security_code;
    //Set the image width and height
    $width = 100;
    $height = 20;
    //Create the image resource
    $image = ImageCreate($width, $height);
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    //Add randomly generated string in white to the image
    ImageString($image, 3, 30, 3, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2, $width, $height / 2, $grey);
    imageline($image, $width / 2, 0, $width / 2, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
Example #6
0
function drawRating()
{
    $width = $_GET['width'];
    $height = $_GET['height'];
    if ($width == 0) {
        $width = 200;
    }
    if ($height == 0) {
        $height = 7;
    }
    $rating = $_GET['rating'];
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 0, 255, 0);
    if ($rating > 49) {
        $fill = ImageColorAllocate($image, 255, 255, 0);
    }
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 255, 128, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 255, 0, 0);
    }
    $back = ImageColorAllocate($image, 205, 205, 205);
    $border = ImageColorAllocate($image, 0, 0, 0);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
Example #7
0
function create_captcha()
{
    session_start();
    //生成验证码图片
    Header("Content-type: image/PNG");
    $im = imagecreate(44, 18);
    // 画一张指定宽高的图片
    $back = ImageColorAllocate($im, 245, 245, 245);
    // 定义背景颜色
    imagefill($im, 0, 0, $back);
    //把背景颜色填充到刚刚画出来的图片中
    $vcodes = "";
    srand((double) microtime() * 1000000);
    //生成4位数字
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
        // 生成随机颜色
        $authnum = rand(1, 9);
        $vcodes .= $authnum;
        imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
    }
    $_SESSION['VCODE'] = $vcodes;
    for ($i = 0; $i < 100; $i++) {
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
        // 画像素点函数
    }
    ImagePNG($im);
    ImageDestroy($im);
}
Example #8
0
function create_captcha($width = 60, $height = 32)
{
    session_start();
    //生成验证码图片
    Header("Content-type: image/PNG");
    $im = imagecreate($width, $height);
    // width and height of image
    $back = ImageColorAllocate($im, 245, 245, 245);
    // specify background color
    imagefill($im, 0, 0, $back);
    // fill the background color into image
    $vcodes = "";
    srand((double) microtime() * 1000000);
    //生成4位数字
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
        // 生成随机颜色
        $authnum = rand(1, 9);
        $vcodes .= $authnum;
        imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
    }
    for ($i = 0; $i < 100; $i++) {
        // interuppting
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
        // 画像素点函数
    }
    ImagePNG($im);
    ImageDestroy($im);
    $_SESSION['captcha'] = $vcodes;
}
function captcha_create($text, $config)
{
    global $cfg;
    // anzahl der zeichen
    $count = strlen($text);
    // schriftarten festlegen
    $ttf = $config["ttf"];
    // schriftgroesse festlegen
    $ttf_size = $config["font"]["size"];
    // schriftabstand rechts
    $ttf_x = $config["font"]["x"];
    // schriftabstand oben
    $ttf_y = $config["font"]["y"];
    // hintergrund erstellen
    $ttf_img = ImageCreate($count * 2 * $ttf_size, 2 * $ttf_size);
    // bgfarbe festlegen
    $bg_color = ImageColorAllocate($ttf_img, $config["bg_color"][0], $config["bg_color"][1], $config["bg_color"][2]);
    // textfarbe festlegen
    $font_color = ImageColorAllocate($ttf_img, $config["font_color"][0], $config["font_color"][1], $config["font_color"][2]);
    // schrift in bild einfuegen
    foreach (str_split($text) as $key => $character) {
        // schriftwinkel festlegen
        $ttf_angle = rand(-25, 25);
        // schriftarten auswaehlen
        $ttf_font = $ttf[rand(0, count($ttf) - 1)];
        imagettftext($ttf_img, $ttf_size, $ttf_angle, $ttf_size * 2 * $key + $ttf_x, $ttf_y, $font_color, $ttf_font, $character);
    }
    // bild temporaer als datei ausgeben
    $captcha_crc = crc32($text . $config["randomize"]);
    $captcha_name = "captcha-" . $captcha_crc . ".png";
    $captcha_path = $cfg["file"]["base"]["maindir"] . $cfg["file"]["base"]["new"];
    imagepng($ttf_img, $captcha_path . $captcha_name);
    // bild loeschen
    imagedestroy($ttf_img);
}
Example #10
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xffffff, $fore_color = 0x0)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r1 = round(($fore_color & 0xff0000) >> 16, 5);
     $b1 = round(($fore_color & 0xff00) >> 8, 5);
     $g1 = round($fore_color & 0xff, 5);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r2 = round(($back_color & 0xff0000) >> 16, 5);
     $b2 = round(($back_color & 0xff00) >> 8, 5);
     $g2 = round($back_color & 0xff, 5);
     $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2);
     $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Example #11
0
function draw_captcha($security_code)
{
    //Set the image width and height
    $width = 100;
    $height = 25;
    //Create the image resource
    $image = ImageCreate($width, $height);
    if (function_exists('imageantialias')) {
        imageantialias($image, true);
    }
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 15, 50, 15);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    $ellipsec = ImageColorAllocate($image, 0, 100, 60);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
    //Add randomly generated string in white to the image
    ImageString($image, 5, 30, 4, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
    imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
Example #12
0
 /**
  * Generates the captcha image
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return	
  */
 public function generate()
 {
     $id = $this->input->get('id', '', 'int');
     // Load up the captcha object
     $captcha = EB::table('Captcha');
     // Clear outdated keys
     $captcha->clear();
     // load the captcha records.
     $captcha->load($id);
     if (!$captcha->id) {
         return false;
     }
     // @task: Generate a very random integer and take only 5 chars max.
     $hash = JString::substr(md5(rand(0, 9999)), 0, 5);
     $captcha->response = $hash;
     $captcha->store();
     // Captcha width and height
     $width = 100;
     $height = 20;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 204, 204, 204);
     ImageFill($image, 0, 0, $white);
     ImageString($image, 5, 30, 3, $hash, $black);
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
     imageline($image, 0, $height / 2, $width, $height / 2, $gray);
     imageline($image, $width / 2, 0, $width / 2, $height, $gray);
     header('Content-type: image/jpeg');
     ImageJpeg($image);
     ImageDestroy($image);
     exit;
 }
Example #13
0
 public function colorHex($img, $hexColorString)
 {
     $r = hexdec(substr($hexColorString, 0, 2));
     $g = hexdec(substr($hexColorString, 2, 2));
     $b = hexdec(substr($hexColorString, 4, 2));
     return ImageColorAllocate($img, $r, $g, $b);
 }
Example #14
0
function ReturnShowKeyColor($img)
{
    global $public_r;
    //背景色
    if ($public_r['keybgcolor']) {
        $bgcr = ToReturnRGB($public_r['keybgcolor']);
        $r['bgcolor'] = imagecolorallocate($img, $bgcr[0], $bgcr[1], $bgcr[2]);
    } else {
        $r['bgcolor'] = imagecolorallocate($img, 102, 102, 102);
    }
    //文字色
    if ($public_r['keyfontcolor']) {
        $fcr = ToReturnRGB($public_r['keyfontcolor']);
        $r['fontcolor'] = ImageColorAllocate($img, $fcr[0], $fcr[1], $fcr[2]);
    } else {
        $r['fontcolor'] = ImageColorAllocate($img, 255, 255, 255);
    }
    //干扰色
    if ($public_r['keydistcolor']) {
        $dcr = ToReturnRGB($public_r['keydistcolor']);
        $r['distcolor'] = ImageColorAllocate($img, $dcr[0], $dcr[1], $dcr[2]);
    } else {
        $r['distcolor'] = ImageColorAllocate($img, 71, 71, 71);
    }
    return $r;
}
Example #15
0
 /**
  * 图像二值化
  *
  * @param number $grey
  */
 public function change_grey($grey = 100)
 {
     for ($y = 0; $y < $this->ih; ++$y) {
         for ($x = 0; $x < $this->iw; ++$x) {
             $rgb = imagecolorat($this->image, $x, $y);
             if (($rgb >> 16 & 0xff) > $grey) {
                 $red = 255;
             } else {
                 $red = 0;
             }
             if (($rgb >> 8 & 0xff) > $grey) {
                 $green = 255;
             } else {
                 $green = 0;
             }
             if (($rgb & 0xff) > $grey) {
                 $blue = 255;
             } else {
                 $blue = 0;
             }
             imagesetpixel($this->image, $x, $y, ImageColorAllocate($this->image, $red, $green, $blue));
         }
     }
     $this->fingerprint();
     $this->filter_info();
     $this->dealwith_data();
 }
 function weldOverview2PNG($url_overview, $url_extent, $filename)
 {
     if (!$url_overview || $url_overview == "") {
         $e = new mb_exception("weldOverview2PNG: no maprequests delivered");
     }
     $url = $url_overview;
     $obj1 = new stripRequest($url);
     $width = $obj1->get("width");
     $height = $obj1->get("height");
     /*
     $e = new mb_exception("--------overview-----------------");
     $e = new mb_exception("-----width ".$width." / height: ".$height."--------------------");
     $e = new mb_exception("url_overview: ".$url_overview);
     $e = new mb_exception("url_extent: ".$url_extent);
     */
     $image = imagecreatetruecolor($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     ImageFilledRectangle($image, 0, 0, $width, $height, $white);
     //overview
     $obj = new stripRequest($url_overview);
     $xurl_overview = $obj->setPNG();
     $xurl_overview = $obj->encodeGET();
     $img = $this->loadpng($xurl_overview);
     if ($img != false) {
         imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
     } else {
         $e = new mb_exception("weldMaps2PNG: unable to load image: " . $url_overview);
     }
     // rectangle - position of the map in the overview
     $objx = new stripRequest($url_extent);
     $ex_width = $objx->get("width");
     $ex_height = $objx->get("height");
     $extent = explode(",", $objx->get("BBOX"));
     $lowerleft = $this->makeRealWorld2mapPos($url_overview, round($extent[0]), round($extent[1]));
     $upperright = $this->makeRealWorld2mapPos($url_overview, $extent[2], $extent[3]);
     /*
     $e = new mb_exception("ex_width: " .$ex_width);
     $e = new mb_exception("ex_height: " . $ex_height);
     $e = new mb_exception("bbox:".$extent[0]."--".$extent[1]."--".$extent[2]."--------".$extent[3]);
     $e = new mb_exception("ll: " . $lowerleft[0]." / ".$lowerleft[1]);
     $e = new mb_exception("ur: " . $upperright[0]." / ".$upperright[1]);
     */
     $lowerleft[0] = round($lowerleft[0]);
     $lowerleft[1] = round($lowerleft[1]);
     $upperright[0] = round($upperright[0]);
     $upperright[1] = round($upperright[1]);
     $red = ImageColorAllocate($image, 255, 0, 0);
     imageline($image, $lowerleft[0], $upperright[1], $upperright[0], $upperright[1], $red);
     imageline($image, $upperright[0], $upperright[1], $upperright[0], $lowerleft[1], $red);
     imageline($image, $upperright[0], $lowerleft[1], $lowerleft[0], $lowerleft[1], $red);
     imageline($image, $lowerleft[0], $lowerleft[1], $lowerleft[0], $upperright[1], $red);
     // black frame - size of the overview
     $black = ImageColorAllocate($image, 0, 0, 0);
     imageline($image, 0, 0, $width - 1, 0, $black);
     imageline($image, $width - 1, 0, $width - 1, $height - 1, $black);
     imageline($image, $width - 1, $height - 1, 0, $height - 1, $black);
     imageline($image, 0, $height - 1, 0, 0, $black);
     imagepng($image, $filename);
     imagedestroy($image);
 }
Example #17
0
 /**
  * Generates a random captcha image
  *
  **/
 function display($cachable = false, $urlparams = false)
 {
     // @TODO: Run some cleaning query here to clear the database.
     JTable::addIncludePath(DISCUSS_TABLES);
     $id = JRequest::getInt('captcha-id', '');
     $captcha = DiscussHelper::getTable('Captcha');
     // clearing the oudated keys.
     $captcha->clear();
     // load the captcha records.
     $captcha->load($id);
     if (!$captcha->id) {
         return false;
     }
     // @task: Generate a very random integer and take only 5 chars max.
     $hash = JString::substr(md5(rand(0, 9999)), 0, 5);
     $captcha->response = $hash;
     $captcha->store();
     // Captcha width and height
     $width = 100;
     $height = 20;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 204, 204, 204);
     ImageFill($image, 0, 0, $white);
     ImageString($image, 5, 30, 3, $hash, $black);
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
     imageline($image, 0, $height / 2, $width, $height / 2, $gray);
     imageline($image, $width / 2, 0, $width / 2, $height, $gray);
     header('Content-type: image/jpeg');
     ImageJpeg($image);
     ImageDestroy($image);
     exit;
 }
 /**
  * Returns a mask
  *
  * @param \WideImage\Image $image
  * @return \WideImage\Image
  */
 public function execute($image)
 {
     $width = $image->getWidth();
     $height = $image->getHeight();
     $mask = TrueColorImage::create($width, $height);
     $mask->setTransparentColor(-1);
     $mask->alphaBlending(false);
     $mask->saveAlpha(false);
     for ($i = 0; $i <= 255; $i++) {
         $greyscale[$i] = ImageColorAllocate($mask->getHandle(), $i, $i, $i);
     }
     imagefilledrectangle($mask->getHandle(), 0, 0, $width, $height, $greyscale[255]);
     $transparentColor = $image->getTransparentColor();
     $alphaToGreyRatio = 255 / 127;
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $color = $image->getColorAt($x, $y);
             if ($color == $transparentColor) {
                 $rgba['alpha'] = 127;
             } else {
                 $rgba = $image->getColorRGB($color);
             }
             imagesetpixel($mask->getHandle(), $x, $y, $greyscale[255 - round($rgba['alpha'] * $alphaToGreyRatio)]);
         }
     }
     return $mask;
 }
Example #19
0
function ConvertToImage($content)
{
    $imageFile = ".counter.png";
    $relativePath = ".counter.png";
    $noOfChars = strlen($content);
    $charHeight = ImageFontHeight(5);
    $charWidth = ImageFontWidth(5);
    $strWidth = $charWidth * $noOfChars;
    $strHeight = $charHeight;
    //15 padding
    $imgWidth = $strWidth + 15;
    $imgHeight = $strHeight + 15;
    $imgCenterX = $imgWidth / 2;
    $imgCenterY = $imgHeight / 2;
    $im = ImageCreate($imgWidth, $imgHeight);
    $script = ImageColorAllocate($im, 0, 255, 0);
    $outercolor = ImageColorAllocate($im, 99, 140, 214);
    $innercolor = ImageColorAllocate($im, 0, 0, 0);
    ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor);
    ImageFilledRectangle($im, 3, 3, $imgWidth - 4, $imgHeight - 4, $innercolor);
    //draw string
    $drawPosX = $imgCenterX - $strWidth / 2 + 1;
    $drawPosY = $imgCenterY - $strHeight / 2;
    ImageString($im, 5, $drawPosX, $drawPosY, $content, $script);
    //save image and return
    ImagePNG($im, $imageFile);
    return $relativePath;
}
Example #20
0
function getDataMatrix($code)
{
    $x = 70;
    // barcode center
    $y = 70;
    // barcode center
    $height = 140;
    // barcode height in 1D ; module size in 2D
    $width = 4;
    // barcode height in 1D ; not use in 2D
    $angle = 90;
    // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
    $type = 'datamatrix';
    $im = imagecreatetruecolor(140, 140);
    $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
    $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
    $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
    $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
    imagefilledrectangle($im, 0, 0, 140, 140, $white);
    $data = \BarcodeGEN::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width);
    /*for($i=1; $i<5; $i++){
          drawCross($im, $blue, $data['p'.$i]['x'], $data['p'.$i]['y']);
      }*/
    return $im;
}
 function guvenlik_resmi()
 {
     $sifre = substr(md5(rand(0, 999999999999)), -5);
     if ($sifre) {
         $this->session->set_userdata('koruma', $sifre);
         $yukseklik = 62;
         $genislik = 200;
         $resim = ImageCreate($genislik, $yukseklik);
         $siyah = ImageColorAllocate($resim, 0, 0, 0);
         $kirmizi = ImageColorAllocate($resim, 182, 16, 99);
         $beyaz = ImageColorAllocate($resim, 255, 255, 255);
         ImageFill($resim, 0, 0, $beyaz);
         $font = 'css/comic.ttf';
         $font_boyut = 24;
         $sM = 30;
         $uM = 45;
         //kullanımı
         //resim adı, font boyutu, yazının açısı, yazının soldan margini, üstten margin, renk, font adı, şifrenin hangi digitinin yazılacağı bellirtiliyor
         imagettftext($resim, $font_boyut, rand(-45, 45), $sMa = $sM, $uM, rand(0, 255), $font, $sifre[0]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[1]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[2]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[3]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[4]);
         //ImageRectangle($resim, 0, 0, $genislik-1, $yukseklik-1, $kirmizi);
         imageline($resim, 0, $yukseklik / 2, $genislik, $yukseklik / 2, $kirmizi);
         imageline($resim, $genislik / 2, 0, $genislik / 2, $yukseklik, $kirmizi);
         header("Content-Type: image/png");
         ImagePng($resim);
         ImageDestroy($resim);
     }
     exit;
 }
Example #22
0
function rand_create()
{
    //通知浏览器将要输出PNG图片
    Header("Content-type: image/PNG");
    //准备好随机数发生器种子
    srand((double) microtime() * 1000000);
    //准备图片的相关参数
    $im = imagecreate(62, 20);
    $black = ImageColorAllocate($im, 0, 0, 0);
    //RGB黑色标识符
    $white = ImageColorAllocate($im, 255, 255, 255);
    //RGB白色标识符
    $gray = ImageColorAllocate($im, 200, 200, 200);
    //RGB灰色标识符
    //开始作图
    imagefill($im, 0, 0, $gray);
    while (($randval = rand() % 100000) < 10000) {
    }
    $_SESSION["login_check_num"] = $randval;
    //将四位整数验证码绘入图片
    imagestring($im, 5, 10, 3, $randval, $black);
    //加入干扰象素
    for ($i = 0; $i < 200; $i++) {
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
    }
    //输出验证图片
    ImagePNG($im);
    //销毁图像标识符
    ImageDestroy($im);
}
Example #23
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreatetruecolor($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 0, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagecolortransparent($base_image, $col[0]);
     imagealphablending($base_image, true);
     imagesavealpha($base_image, true);
     //        imagefill($base_image, 0, 0, $col[0]);
     imagefill($base_image, 0, 0, 0x7fff0000);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Example #24
0
/**
 *
 * long description
 * @global object
 * @param object $dst_img
 * @param object $src_img
 * @param int $dst_x 
 * @param int $dst_y 
 * @param int $src_x 
 * @param int $src_y 
 * @param int $dst_w 
 * @param int $dst_h 
 * @param int $src_w 
 * @param int $src_h 
 * @return bool
 * @todo Finish documenting this function
 */
function ImageCopyBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
    global $CFG;
    if (function_exists('ImageCopyResampled') and $CFG->gdversion >= 2) {
        return ImageCopyResampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    $totalcolors = imagecolorstotal($src_img);
    for ($i = 0; $i < $totalcolors; $i++) {
        if ($colors = ImageColorsForIndex($src_img, $i)) {
            ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
        }
    }
    $scaleX = ($src_w - 1) / $dst_w;
    $scaleY = ($src_h - 1) / $dst_h;
    $scaleX2 = $scaleX / 2.0;
    $scaleY2 = $scaleY / 2.0;
    for ($j = 0; $j < $dst_h; $j++) {
        $sY = $j * $scaleY;
        for ($i = 0; $i < $dst_w; $i++) {
            $sX = $i * $scaleX;
            $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
            $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
            $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
            $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
            $color = ImageColorClosest($dst_img, $red, $green, $blue);
            ImageSetPixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
        }
    }
}
Example #25
0
function create_image()
{
    // *** Generate a passcode using md5
    //	(it will be all lowercase hex letters and numbers ***
    $md5 = md5(rand(0, 9999));
    $pass = substr($md5, 10, 5);
    // *** Set the session cookie so we know what the passcode is ***
    $_SESSION["pass"] = $pass;
    // *** Create the image resource ***
    $image = ImageCreatetruecolor(100, 20);
    // *** We are making two colors, white and black ***
    $clr_white = ImageColorAllocate($image, 255, 255, 255);
    $clr_black = ImageColorAllocate($image, 0, 0, 0);
    // *** Make the background black ***
    imagefill($image, 0, 0, $clr_black);
    // *** Set the image height and width ***
    imagefontheight(15);
    imagefontwidth(15);
    // *** Add the passcode in white to the image ***
    imagestring($image, 5, 30, 3, $pass, $clr_white);
    // *** Throw in some lines to trick those cheeky bots! ***
    imageline($image, 5, 1, 50, 20, $clr_white);
    imageline($image, 60, 1, 96, 20, $clr_white);
    // *** Return the newly created image in jpeg format ***
    return imagejpeg($image);
    // *** Just in case... ***
    imagedestroy($image);
}
Example #26
0
 function getAuthImage($text)
 {
     $this->setpin($text);
     $im_x = 160;
     $im_y = 40;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $tmpC0 = mt_rand(100, 255);
     $tmpC1 = mt_rand(100, 255);
     $tmpC2 = mt_rand(100, 255);
     $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
     imagefill($im, 16, 13, $buttum_c);
     $font = PATH_SYS_PUBLIC . 'font-awesome/fonts/verdana.ttf';
     for ($i = 0; $i < strlen($text); $i++) {
         $tmp = substr($text, $i, 1);
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //角度
         $size = 28;
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $buttum_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 160;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 30);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/JPEG");
     //以PNG格式将图像输出到浏览器或文件;
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
 }
Example #27
0
 function GraphNormalize($title, $options = NULL)
 {
     $this->options = $options;
     $this->interval = $this->options['interval'] ? $this->options['interval'] : 10;
     // TODO: Move these to friendly options
     $this->image_size = array(600, 400);
     $this->canvas_offset = array(25, 50, 25, 25);
     $this->canvas_size = array($this->image_size[0] - ($this->canvas_offset[0] + $this->canvas_offset[2]), $this->image_size[1] - ($this->canvas_offset[1] + $this->canvas_offset[3]));
     // Actual creation stuff
     $this->graph = ImageCreate($this->image_size[0], $this->image_size[1]);
     $this->color['background'] = ImageColorAllocate($this->graph, 0xff, 0xff, 0xff);
     $this->color['line'] = ImageColorAllocate($this->graph, 0x60, 0x60, 0x60);
     $this->color['border'] = ImageColorAllocate($this->graph, 0x0, 0x0, 0x0);
     $this->color['text'] = ImageColorAllocate($this->graph, 0x0, 0x0, 0x0);
     $this->color['grid'] = ImageColorAllocate($this->graph, 0xc0, 0xc0, 0xc0);
     $this->color['canvas'] = ImageColorAllocate($this->graph, 0xe0, 0xe0, 0xe0);
     $this->color['legendbox'] = ImageColorAllocate($this->graph, 0xd0, 0xd0, 0xf0);
     $this->color['titlebox'] = ImageColorAllocate($this->graph, 0xd0, 0xf0, 0xf0);
     $this->color['data'] = array(ImageColorAllocate($this->graph, 0xff, 0x0, 0x0), ImageColorAllocate($this->graph, 0x0, 0xcc, 0x0), ImageColorAllocate($this->graph, 0x0, 0x0, 0xff), ImageColorAllocate($this->graph, 0xff, 0xff, 0x0), ImageColorAllocate($this->graph, 0x0, 0xff, 0xff), ImageColorAllocate($this->graph, 0xff, 0x0, 0xff));
     $this->font = 'lib/template/default/Vera.ttf';
     $this->title = $title;
     $this->set_count = 0;
     // Define canvas, so we don't go crazy
     $this->ca = array($this->canvas_offset[0], $this->canvas_offset[1], $this->canvas_size[0] - $this->canvas_offset[2] - 1, $this->canvas_size[1] - $this->canvas_offset[3] - 1);
 }
Example #28
0
function JPGText($str, $fontname, $fontsize, $backcol, $txtcol)
{
    global $layout;
    Header("Last-Modified: " . gmDate("D, d M Y H:i:s", Time()) . " GMT");
    Header("Expires: " . gmDate("D, d M Y H:i:s", Time() - 3601) . " GMT");
    Header("Pragma: no-cache");
    Header("Cache-control: no-cache");
    Header("Content-Type: image/jpeg");
    $a = ImageTTFBBox($fontsize, 0, $fontname, $str);
    $width = $a[2] + 4;
    $bla = get_maximum_height($fontname, $fontsize);
    $height = $bla[0] + 3;
    $bl = $bla[1];
    $im = ImageCreate($width, $height);
    $bgcol = ImageColorAllocate($im, $backcol['red'], $backcol['green'], $backcol['blue']);
    $fgcol = ImageColorAllocate($im, $txtcol['red'], $txtcol['green'], $txtcol['blue']);
    if (!function_exists(imagegif)) {
        imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str);
        imagejpeg($im, "", 80);
    } else {
        ImageColorTransparent($im, $bgcol);
        imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str);
        imagegif($im);
    }
    ImageDestroy($im);
}
Example #29
-1
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     //$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     //ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     //Get Desired size of image.
     //Insert the following code to generate desired size QR Code
     //Example:----- (Note: this should be written in the file where we are going to generate the QR Code)
     //------define('IMAGE_WIDTH',160);
     //------define('IMAGE_HEIGHT',160);
     //------QRcode::png();
     $targetW = defined('IMAGE_WIDTH') ? IMAGE_WIDTH : $imgW * $pixelPerPoint;
     $targetH = defined('IMAGE_HEIGHT') ? IMAGE_HEIGHT : $imgH * $pixelPerPoint;
     $target_image = ImageCreate($targetW, $targetH);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $targetW, $targetH, $imgW, $imgH);
     //Transparent Background QR code
     ImageColorTransparent($target_image, $col[0]);
     ImageDestroy($base_image);
     return $target_image;
 }
Example #30
-1
 function mkimage($data)
 {
     $data_array = explode("\n", $data);
     $c = count($data_array) - 1;
     $image_size = $c;
     $output_size = ($c + $this->quiet_zone * 2) * $this->module_size;
     $img = ImageCreate($image_size, $image_size);
     $white = ImageColorAllocate($img, 255, 255, 255);
     $black = ImageColorAllocate($img, 0, 0, 0);
     $im = ImageCreate($output_size, $output_size);
     $white2 = ImageColorAllocate($im, 255, 255, 255);
     ImageFill($im, 0, 0, $white2);
     $y = 0;
     foreach ($data_array as $row) {
         $x = 0;
         while ($x < $image_size) {
             if (substr($row, $x, 1) == "1") {
                 ImageSetPixel($img, $x, $y, $black);
             }
             $x++;
         }
         $y++;
     }
     $quiet_zone_offset = $this->quiet_zone * $this->module_size;
     $image_width = $image_size * $this->module_size;
     ImageCopyResized($im, $img, $quiet_zone_offset, $quiet_zone_offset, 0, 0, $image_width, $image_width, $image_size, $image_size);
     return $im;
 }