示例#1
2
 function generateImage($token)
 {
     $iFont = 5;
     // Font ID
     $iSpacing = 2;
     // Spacing between characters
     $iDisplacement = 5;
     // Vertical chracter displacement
     // Establish font metric and image size
     $iCharWidth = ImageFontWidth($iFont);
     $iCharHeight = ImageFontHeight($iFont);
     $iWidth = strlen($token) * ($iCharWidth + $iSpacing);
     $iHeight = $iCharHeight + 2 * $iDisplacement;
     // Create the image
     $pic = ImageCreate($iWidth, $iHeight);
     // Allocate a background and foreground colour
     $col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200));
     for ($x = 0; $x < $iWidth; $x += 2) {
         for ($y = 0; $y < $iHeight; $y += 2) {
             ImageSetPixel($pic, $x, $y, $col['grey']);
         }
     }
     $iX = 1;
     for ($i = 0; $i < strlen($token); $i++) {
         ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']);
         $iX += $iCharWidth + $iSpacing;
     }
     $iX = 2;
     $c = array('blue', 'green', 'red', 'purple');
     for ($i = 0; $i < strlen($token); $i++) {
         $colour = $c[rand(0, count($c) - 1)];
         ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]);
         $iX += $iCharWidth + $iSpacing;
     }
     for ($x = 1; $x < $iWidth; $x += 4) {
         for ($y = 1; $y < $iHeight; $y += 4) {
             ImageSetPixel($pic, $x, $y, $col['white']);
         }
     }
     // Draw some lines
     for ($i = 0; $i < 4; $i++) {
         ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']);
     }
     ob_start();
     if (function_exists('imagejpeg')) {
         ImageJPEG($pic);
     } elseif (function_exists('imagepng')) {
         ImagePNG($pic);
     } else {
         ob_end_clean();
         return false;
     }
     $data = ob_get_contents();
     ob_end_clean();
     ImageDestroy($pic);
     return $data;
 }
示例#2
0
文件: pin.class.php 项目: nanfs/lt
 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);
 }
示例#3
0
 function extractAppInfo($img)
 {
     //アイコン切り出し
     $homeLeftPadding = 34;
     $homeTopPadding = 67;
     $appSideMargin = 38;
     //1列目と2列め、3列めと4列目の間のマージン
     $appCenterMargin = 40;
     //2列めと3列めの間のマージン
     $appBottomMargin = 62;
     $featurePadding = 6;
     //角丸分を削る
     for ($y = 0; $y < 4; $y++) {
         for ($x = 0; $x < 4; $x++) {
             //アイコン切り出し
             $appXAlpha = $x < 2 ? 0 : $appCenterMargin - $appSideMargin;
             $appX = $homeLeftPadding + ($x * (self::appWidth + $appSideMargin) + $appXAlpha);
             $appY = $homeTopPadding + $y * (self::appHeight + $appBottomMargin);
             $appImg = ImageCreateTrueColor(self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2);
             ImageCopyResampled($appImg, $img, 0, 0, $appX + $featurePadding, $appY + $featurePadding, self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2, self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2);
             $appIdx = $y * 4 + $x;
             $filename = "app_icon.{$appIdx}.png";
             ImagePNG($appImg, $filename);
             echo "{$filename} \n";
             //アイコンを3x3に分割して平均色を抽出、特徴量とする
             //$features = $this->calcIconImgFeature($appImg);
             ImageDestroy($appImg);
         }
     }
 }
 function create_error($text)
 {
     $text = $text;
     $size = "8";
     $font = "classes/fonts/trebuchet.ttf";
     $TextBoxSize = imagettfbbox($size, 0, $font, preg_replace("/\\[br\\]/is", "\r\n", $text));
     $TxtBx_Lwr_L_x = $TextBoxSize[0];
     $TxtBx_Lwr_L_y = $TextBoxSize[1];
     $TxtBx_Lwr_R_x = $TextBoxSize[2];
     $TxtBx_Lwr_R_y = $TextBoxSize[3];
     $TxtBx_Upr_R_x = $TextBoxSize[4];
     $TxtBx_Upr_R_y = $TextBoxSize[5];
     $TxtBx_Upr_L_x = $TextBoxSize[6];
     $TxtBx_Upr_L_y = $TextBoxSize[7];
     $width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
     $height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
     $y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $img = imagecreate($width + 2, $height + 1);
     // Only PHP-Version 4.3.2 or higher
     if (function_exists('imageantialias')) {
         imageantialias($img, FALSE);
     }
     $white = imagecolorallocate($img, 255, 255, 255);
     $black = imagecolorallocate($img, 0, 0, 0);
     imagecolortransparent($img, $white);
     ImageTTFText($img, $size, 0, $x, $y, $black, $font, preg_replace("/<br>/is", "\r\n", $text));
     header("Content-Type: image/png");
     ImagePNG($img);
     ImageDestroy($img);
     exit;
 }
示例#5
0
文件: Captcha.php 项目: miaokuan/wee
 public function show()
 {
     $size = min($this->im_y, $this->im_x / $this->text_num);
     $size = ceil($size * 0.8);
     $im = imagecreatetruecolor($this->im_x, $this->im_y);
     $text_c = imagecolorallocate($im, 255, 0, 0);
     $bg_c = imagecolorallocate($im, 255, 255, 255);
     imagefill($im, 0, 0, $bg_c);
     for ($i = 0; $i < $this->text_num; $i++) {
         $ypos = $size * 1.2;
         if (preg_match('/[ygJup]/', $this->text[$i])) {
             $ypos = ceil($ypos * 0.8);
         }
         //反色
         $rnd = rand(1, $this->text_num - 1);
         if ($i % $this->text_num == $rnd) {
             imagefilledellipse($im, $this->im_x * 0.05 + $i * $size * 1.3 + $size / 2, $ypos / 2, $size * 1.2, $this->im_y * 1.1, $text_c);
             imagettftext($im, $size, 0, $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $bg_c, $this->ttf_file, $this->text[$i]);
         } else {
             imagettftext($im, $size, rand(-20, 20), $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $text_c, $this->ttf_file, $this->text[$i]);
         }
     }
     ob_clean();
     header("Content-type: image/png");
     ImagePNG($im);
     ImageDestroy($im);
     echo '= ' . base64_encode('@author:miaokuan<*****@*****.**>');
 }
示例#6
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;
}
示例#7
0
 function SaveImage($im, $filename)
 {
     $res = null;
     // ImageGIF is not included into some GD2 releases, so it might not work
     // output png if gifs are not supported
     if ($this->image_type == 1 && !function_exists('imagegif')) {
         $this->image_type = 3;
     }
     switch ($this->image_type) {
         case 1:
             if ($this->save_to_file) {
                 header("Content-type: image/gif");
                 $res = ImageGIF($im, $filename);
                 $res = ImageGIF($im, NULL);
             } else {
                 header("Content-type: image/gif");
                 $res = ImageGIF($im, $filename);
                 $res = ImageGIF($im, NULL);
             }
             break;
         case 2:
             if ($this->save_to_file) {
                 header("Content-type: image/jpeg");
                 $res = ImageJPEG($im, $filename, $this->quality);
                 $res = ImageJPEG($im, NULL, $this->quality);
             } else {
                 header("Content-type: image/jpeg");
                 $res = ImageJPEG($im, $filename, $this->quality);
                 $res = ImageJPEG($im, NULL, $this->quality);
             }
             break;
         case 3:
             if (PHP_VERSION >= '5.1.2') {
                 // Convert to PNG quality.
                 // PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
                 $quality = 9 - min(round($this->quality / 10), 9);
                 if ($this->save_to_file) {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename, $quality);
                     $res = ImagePNG($im, NULL, $quality);
                 } else {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename, $quality);
                     $res = ImagePNG($im, NULL, $quality);
                 }
             } else {
                 if ($this->save_to_file) {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename);
                     $res = ImagePNG($im);
                 } else {
                     header("Content-type: image/png");
                     $res = ImagePNG($im, $filename);
                     $res = ImagePNG($im);
                 }
             }
             break;
     }
     return $res;
 }
function TransformPicture($inputfname, $outputfname, $transform)
{
    $img = ImageCreateFromPNG($inputfname);
    Imagesavealpha($img, true);
    $sizex = imagesx($img);
    $sizey = imagesy($img);
    for ($x = 0; $x < $sizex; $x++) {
        for ($y = 0; $y < $sizey; $y++) {
            $color = imagecolorat($img, $x, $y);
            $allcolors[dechex($color)]++;
            $blue = 0xff & $color;
            $green = (0xff00 & $color) >> 8;
            $red = (0xff0000 & $color) >> 16;
            foreach ($transform as $line) {
                list($from, $to) = split("\t", $line);
                list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
                if ($blue == $fb and $red == $fr and $green == $fg) {
                    imagesetpixel($img, $x, $y, hexdec($to));
                }
            }
        }
    }
    ImagePNG($img, "{$outputfname}");
    imagedestroy($img);
    print_r($allcolors);
}
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor)
{
    $img_in = ImageCreateFromPNG($inputfname);
    $sizex = imagesx($img_in);
    $sizey = imagesy($img_in);
    $img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle.");
    imagefill($img_out, 0, 0, hexdec($backgroundcolor));
    ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey);
    for ($x = 0; $x < $sizex; $x++) {
        for ($y = 0; $y < $sizey; $y++) {
            $color = imagecolorat($img_in, $x, $y);
            $allcolors[dechex($color)]++;
            $blue = 0xff & $color;
            $green = (0xff00 & $color) >> 8;
            $red = (0xff0000 & $color) >> 16;
            foreach ($transform as $line) {
                list($from, $to) = split("\t", $line);
                list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
                if ($blue == $fb and $red == $fr and $green == $fg) {
                    imagesetpixel($img_out, $x, $y, hexdec($to));
                }
            }
        }
    }
    ImagePNG($img_out, "out/{$outputfname}");
    imagedestroy($img_in);
    imagedestroy($img_out);
    print_r($allcolors);
}
示例#10
0
 public function resize($width, $height)
 {
     $type = exif_imagetype($this->image);
     if ($type == 2) {
         $images_orig = ImageCreateFromJPEG($this->image);
     } elseif ($type == 3) {
         $images_orig = ImageCreateFromPNG($this->image);
     } elseif ($type == 1) {
         $images_orig = ImageCreateFromGIF($this->image);
     } else {
         return false;
     }
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     if ($type == 2) {
         ImageJPEG($images_fin, $this->image);
     } elseif ($type == 3) {
         ImagePNG($images_fin, $this->image);
     } elseif ($type == 1) {
         ImageGIF($images_fin, $this->image);
     }
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     return true;
 }
示例#11
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);
}
 function createAICode()
 {
     global $bBlog;
     $code = $this->randomString();
     $bBlog->db->query("\n\tDELETE FROM `" . T_CHECKCODE . "` WHERE `timestamp`+3000<NOW()");
     $bBlog->db->query("\n\tINSERT INTO `" . T_CHECKCODE . "` ( `id` , `checksum` , `timestamp` )\n\tVALUES ('', '" . md5($code . $_SERVER["REMOTE_ADDR"]) . "', NOW( ))");
     if (!isset($plugins_dir)) {
         $plugins_dir = dirname(__FILE__) . '/';
     }
     $fontfile = "atomicclockradio.ttf";
     $font = $plugins_dir . $fontfile;
     $im = @imageCreate(110, 50) or die("Cannot Initialize new GD image stream");
     $background_color = imageColorAllocate($im, 195, 217, 255);
     $text_color = imageColorAllocate($im, 168, 18, 19);
     ImageTTFText($im, 20, 5, 18, 38, $text_color, $font, $code);
     // Date in the past
     header("Expires: Thu, 28 Aug 1997 05:00:00 GMT");
     // always modified
     $timestamp = gmdate("D, d M Y H:i:s");
     header("Last-Modified: " . $timestamp . " GMT");
     // HTTP/1.1
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     // HTTP/1.0
     header("Pragma: no-cache");
     // dump out the image
     header("Content-type: image/png");
     ImagePNG($im);
 }
示例#13
0
 /** 创建验证码 */
 public function create()
 {
     // 创建图象
     $this->_img_res = imagecreate($this->width, $this->height);
     // 填充背景
     ImageColorAllocate($this->_img_res, $this->backgroundColor[0], $this->backgroundColor[1], $this->backgroundColor[2]);
     // 分配颜色
     $col_ellipse = imagecolorallocate($this->_img_res, $this->iconColor[0], $this->iconColor[1], $this->iconColor[2]);
     $minArea = $this->iconSize / 2 + 3;
     // 混淆用图象,不完整的圆
     for ($i = 0; $i < $this->icon; $i++) {
         $x = mt_rand($minArea, $this->width - $minArea);
         $y = mt_rand($minArea, $this->height - $minArea);
         $s = mt_rand(0, 360);
         $e = $s + 330;
         imagearc($this->_img_res, $x, $y, $this->iconSize, $this->iconSize, $s, $e, $col_ellipse);
     }
     // 验证用图象,完整的圆
     $x = mt_rand($minArea, $this->width - $minArea);
     $y = mt_rand($minArea, $this->height - $minArea);
     $r = $this->iconSize / 2;
     imagearc($this->_img_res, $x, $y, $this->iconSize, $this->iconSize, 0, 360, $col_ellipse);
     // 记录圆心坐标及半径
     $this->captcha_session($this->sess_name, array($x, $y, $r));
     // 生成图象
     Header("Content-type: image/PNG");
     ImagePNG($this->_img_res);
     ImageDestroy($this->_img_res);
     exit;
 }
 function createImage($_text, $_fontsize = 11)
 {
     /* create filename */
     $filename = 'button_' . md5($_text) . '.png';
     $filename = strtolower($filename);
     /* see if file exists already, we cache it */
     if (file_exists(PHPGW_IMAGES_FILEDIR . '/' . $filename)) {
         return $filename;
     }
     $size = imagettfbbox($_fontsize, 0, $this->font, $_text);
     $dx = abs($size[2] - $size[0]);
     $dy = abs($size[5] - $size[3]);
     $xpad = 9;
     $ypad = 9;
     $im = imagecreate($dx + $xpad, $dy + $ypad);
     $blue = ImageColorAllocate($im, 0x2c, 0x6d, 0xaf);
     $black = ImageColorAllocate($im, 0, 0, 0);
     $white = ImageColorAllocate($im, 255, 255, 255);
     ImageRectangle($im, 0, 0, $dx + $xpad - 1, $dy + $ypad - 1, $black);
     ImageRectangle($im, 0, 0, $dx + $xpad, $dy + $ypad, $white);
     ImageTTFText($im, $_fontsize, 0, (int) ($xpad / 2) + 1, $dy + (int) ($ypad / 2), -$black, $this->font, $_text);
     ImageTTFText($im, $_fontsize, 0, (int) ($xpad / 2), $dy + (int) ($ypad / 2) - 1, -$white, $this->font, $_text);
     ImagePNG($im, PHPGW_IMAGES_FILEDIR . '/' . $filename);
     ImageDestroy($im);
     return $filename;
 }
示例#15
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;
}
示例#16
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);
}
示例#17
0
function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
    if ($toFile == "") {
        $toFile = $srcFile;
    }
    $info = "";
    $data = GetImageSize($srcFile, $info);
    switch ($data[2]) {
        case 1:
            if (!function_exists("imagecreatefromgif")) {
                echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromGIF($srcFile);
            break;
        case 2:
            if (!function_exists("imagecreatefromjpeg")) {
                echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromJpeg($srcFile);
            break;
        case 3:
            $im = ImageCreateFromPNG($srcFile);
            break;
    }
    $srcW = ImageSX($im);
    $srcH = ImageSY($im);
    $toWH = $toW / $toH;
    $srcWH = $srcW / $srcH;
    if ($toWH <= $srcWH) {
        $ftoW = $toW;
        $ftoH = $ftoW * ($srcH / $srcW);
    } else {
        $ftoH = $toH;
        $ftoW = $ftoH * ($srcW / $srcH);
    }
    if ($srcW > $toW || $srcH > $toH) {
        if (function_exists("imagecreatetruecolor")) {
            @($ni = ImageCreateTrueColor($ftoW, $ftoH));
            if ($ni) {
                ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            } else {
                $ni = ImageCreate($ftoW, $ftoH);
                ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            }
        } else {
            $ni = ImageCreate($ftoW, $ftoH);
            ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
        }
        if (function_exists('imagejpeg')) {
            ImageJpeg($ni, $toFile);
        } else {
            ImagePNG($ni, $toFile);
        }
        ImageDestroy($ni);
    }
    ImageDestroy($im);
}
示例#18
0
function img_code($code)
{
    if (isset($_GET['color'])) {
        $scolor = explode(',', $_GET['color']);
    } elseif (isset($_COOKIE['kustyle'])) {
        switch ($_COOKIE['kustyle']) {
            case "Summer":
                $scolor = array(17, 119, 67);
                break;
            case "Winter":
                $scolor = array(33, 0, 127);
                break;
            case "Modern":
                $scolor = array(95, 95, 95);
                break;
            case "Dark":
                $scolor = array(200, 200, 200);
                break;
            default:
                $scolor = array(85, 85, 85);
                break;
        }
    } else {
        $scolor = array(85, 85, 85);
    }
    $linenum = 5;
    $img_arr = array("1.png");
    $font_arr = array();
    $font_arr[0]["fname"] = "OpenSans-Light.ttf";
    $font_arr[0]["size"] = 20;
    $n = rand(0, sizeof($font_arr) - 1);
    $img_fn = $img_arr[rand(0, sizeof($img_arr) - 1)];
    // $im=imagecreatefrompng(dirname(__FILE__)."/captcha/back.png");
    $im = imagecreatefrompng("back.png");
    $color = imagecolorallocate($im, 100, 100, 100);
    $x = -15;
    mb_internal_encoding("UTF-8");
    for ($i = 0; $i < mb_strlen($code); $i++) {
        $y = rand(-15, 15);
        $z = 24;
        $x += 20;
        $letter = mb_substr($code, $i, 1);
        imagettftext($im, $font_arr[$n]["size"], $y, $x, $z, $color, img_dir . $font_arr[$n]["fname"], $letter);
        $_SESSION['security_code'] = $code;
    }
    for ($i = 0; $i < $linenum; $i++) {
        //$color = imagecolorallocate($im, rand(0, 255), rand(0, 200), rand(0, 255));
        imageline($im, rand(0, 20), rand(0, 70), rand(120, 150), rand(0, 70), $color);
    }
    $im = opsmaz($im, $scolor);
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s", 10000) . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Content-Type:image/png");
    ImagePNG($im);
    ImageDestroy($im);
}
示例#19
0
 public function captcha()
 {
     $params = array("quantity" => 4, "height" => 33, "fontsize" => 20, "border" => TRUE, "line" => FALSE, "bgcolor" => array(0, 153, 204));
     $this->load->library('captcha', $params);
     $img = $this->captcha->getCaptcha();
     ImagePNG($img);
     ImageDestroy($img);
 }
 static function getAuthImage($text, $w = 200, $h = 40)
 {
     $im_x = $w;
     $im_y = $h;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $button_c = imagecolorallocate($im, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
     imagefill($im, 16, 13, $button_c);
     $font = realpath(THINK_PATH . 'Common/Class/VerifyCode/') . '\\t1.ttf';
     $len = strlen($text);
     $mt_array = array(-1, 1);
     $size = 28;
     for ($i = 0; $i < $len; $i++) {
         $tmp = substr($text, $i, 1);
         $p = array_rand($mt_array);
         $an = $mt_array[$p] * mt_rand(1, 10);
         //角度
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $button_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);
 }
示例#21
0
function bar_chart($question, $answers)
{
    // define colors to draw the bars
    $colors = array(0xff6600, 0x9900, 0x3333cc, 0xff0033, 0xffff00, 0x66ffff, 0x9900cc);
    $total = array_sum($answers['votes']);
    // define spacing values and other magic numbers
    $padding = 5;
    $line_width = 20;
    $scale = $line_width * 7.5;
    $bar_height = 10;
    $x = $y = $padding;
    // allocate a large palette for drawing, since you don't know
    // the image length ahead of time
    $image = ImageCreateTrueColor(150, 500);
    ImageFilledRectangle($image, 0, 0, 149, 499, 0xe0e0e0);
    $black = 0x0;
    // print the question
    $wrapped = explode("\n", wordwrap($question, $line_width));
    foreach ($wrapped as $line) {
        ImageString($image, 3, $x, $y, $line, $black);
        $y += 12;
    }
    $y += $padding;
    // print the answers
    for ($i = 0; $i < count($answers['answer']); $i++) {
        // format percentage
        $percent = sprintf('%1.1f', 100 * $answers['votes'][$i] / $total);
        $bar = sprintf('%d', $scale * $answers['votes'][$i] / $total);
        // grab color
        $c = $i % count($colors);
        // handle cases with more bars than colors
        $text_color = $colors[$c];
        // draw bar and percentage numbers
        ImageFilledRectangle($image, $x, $y, $x + $bar, $y + $bar_height, $text_color);
        ImageString($image, 3, $x + $bar + $padding, $y, "{$percent}%", $black);
        $y += 12;
        // print answer
        $wrapped = explode("\n", wordwrap($answers['answer'][$i], $line_width));
        foreach ($wrapped as $line) {
            ImageString($image, 2, $x, $y, $line, $black);
            $y += 12;
        }
        $y += 7;
    }
    // crop image by copying it
    $chart = ImageCreateTrueColor(150, $y);
    ImageCopy($chart, $image, 0, 0, 0, 0, 150, $y);
    // PHP 5.5+ supports
    // $chart = ImageCrop($image, array('x' => 0, 'y' => 0,
    //                                  'width' => 150, 'height' => $y));
    // deliver image
    header('Content-type: image/png');
    ImagePNG($chart);
    // clean up
    ImageDestroy($image);
    ImageDestroy($chart);
}
function twMachThumbnail($serverPfad, $datei, $breiteThumb, $prefix)
{
    // Bild-Datei (mit Pfad)
    $bildDatei = $serverPfad . $datei;
    // wenn dieses Bild nich gefunden wurde: Abbruch
    if (!file_exists($bildDatei)) {
        return false;
    }
    // wenn dieses Bild schon ein Thumbnail ist: Abbruch
    if (substr($datei, 0, strlen($prefix)) == $prefix) {
        //echo $datei. "<br />";
        //echo strlen($prefix). "<br />";
        //echo $prefix. "<br />";
        //echo substr($datei, strlen($prefix)). "<br />";
        //echo "-----<br />";
        return false;
    }
    // Bilddaten zu dieser Bild-Datei
    $bilddaten = getimagesize($bildDatei);
    $imgOrigBreite = $bilddaten[0];
    $imgOrigHoehe = $bilddaten[1];
    $imgOrigTyp = $bilddaten[2];
    // (1=GIF, 2=JPG, 3=PNG, 4=SWF)
    if ($imgOrigBreite < $breiteThumb) {
        $breiteThumb = $imgOrigBreite;
    }
    $Skalierungsfaktor = $imgOrigBreite / $breiteThumb;
    $thumbHoehe = intval($imgOrigHoehe / $Skalierungsfaktor);
    // wenn es ein gif-Bild ist
    if ($imgOrigTyp == 1) {
        $Originalgrafik = ImageCreateFromGIF($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImageGIF($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 2) {
        $Originalgrafik = ImageCreateFromJPEG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
        ImageJPEG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 3) {
        $Originalgrafik = ImageCreateFromPNG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImagePNG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } else {
        return false;
    }
    // Speicher leeren
    if ($Originalgrafik) {
        imagedestroy($Originalgrafik);
    }
    if ($Thumbnailgrafik) {
        imagedestroy($Thumbnailgrafik);
    }
}
示例#23
0
文件: search.php 项目: nsatvik/Sample
function drawSampleImage()
{
    echo 'drawSampleImage called';
    $im = ImageCreate(200, 200);
    $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
    $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
    ImageFilledRectangle($im, 50, 50, 150, 150, $black);
    header('Content-Type: image/png');
    ImagePNG($im);
}
 function Resize($maxwidth = 10000, $maxheight, $imagename, $filetype, $how = 'keep_aspect')
 {
     $target_temp_file = tempnam("jinn/temp", "gdlib_");
     unlink($target_temp_file);
     $target_temp_file .= '.' . $filetype;
     if (!$maxheight) {
         $maxheight = 10000;
     }
     if (!$maxwidth) {
         $maxwidth = 10000;
     }
     $qual = 100;
     $filename = $imagename;
     $ext = $filetype;
     list($curwidth, $curheight) = getimagesize($filename);
     $factor = min($maxwidth / $curwidth, $maxheight / $curheight);
     $sx = 0;
     $sy = 0;
     $sw = $curwidth;
     $sh = $curheight;
     $dx = 0;
     $dy = 0;
     $dw = $curwidth * $factor;
     $dh = $curheight * $factor;
     if ($ext == "JPEG") {
         $src = ImageCreateFromJPEG($filename);
     }
     if ($ext == "GIF") {
         $src = ImageCreateFromGIF($filename);
     }
     if ($ext == "PNG") {
         $src = ImageCreateFromPNG($filename);
     }
     if (function_exists('ImageCreateTrueColor')) {
         $dst = ImageCreateTrueColor($dw, $dh);
     } else {
         $dst = ImageCreate($dw, $dh);
     }
     if (function_exists('ImageCopyResampled')) {
         imageCopyResampled($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     } else {
         imageCopyResized($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     }
     if ($ext == "JPEG") {
         ImageJPEG($dst, $target_temp_file, $qual);
     }
     if ($ext == "PNG") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     if ($ext == "GIF") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     ImageDestroy($dst);
     return $target_temp_file;
 }
示例#25
0
文件: common.php 项目: xi67/MAB-LAB
 function generateImageFile($image, $size, $holo)
 {
     $id = $_SESSION['asset_colors_id'];
     date_default_timezone_set('UTC');
     $date = date("Ymd");
     $folder = HOLO_COLORS_GEN_DIR . $date . "/" . $_SESSION['asset_colors_id'] . "/res/drawable-" . $size;
     if (file_exists($folder) == FALSE) {
         mkdir($folder, 0777, true);
     }
     ImagePNG($image, $folder . "/" . str_replace("{{holo}}", $holo, $this->_name));
     imagedestroy($image);
 }
示例#26
0
 function createpicture($action)
 {
     foreach ($this->pictures as $this->picture) {
         $imgsize = getimagesize($this->directory . $this->picture);
         $org_width = $imgsize[0];
         $org_height = $imgsize[1];
         $new_width = $this->width;
         // if ( $org_width > $new_width || $org_height > $this->height_max || $action == 'thumb' )  {
         $new_height = $org_height / $org_width * $new_width;
         $imgfile = substr($this->picture, strlen($this->picture) - 3);
         if (preg_match('/".$imgfile."/i', 'jpg') || preg_match('/".$imgfile."/i', 'jpeg')) {
             $org_picture = imagecreatefromjpeg($this->directory . $this->picture);
         } else {
             if (preg_match('/".$imgfile."/i', 'png')) {
                 $org_picture = imagecreatefrompng($this->directory . $this->picture);
             } else {
                 if (preg_match('/".$imgfile."/i', 'gif')) {
                     $org_picture = imagecreatefromgif($this->directory . $this->picture);
                 }
             }
         }
         if ($org_width < $new_width) {
             $new_width = $org_width;
         }
         if ($org_height < $new_height) {
             $new_height = $org_height;
         }
         if ($new_height > $this->height_max) {
             $new_height = $this->height_max;
             $new_width = $new_height / $org_height * $org_width;
         }
         if (!preg_match($imgfile / i, 'gif')) {
             $newpicture = ImageCreateTrueColor($new_width, $new_height);
         } else {
             if (preg_match($imgfile / i, 'gif')) {
                 $newpicture = imagecreate($new_width, $new_height);
             }
         }
         ImageCopyresampled($newpicture, $org_picture, 0, 0, 0, 0, $new_width, $new_height, $org_width, $org_height);
         if (preg_match('/".$imgfile."/i', 'jpg') || preg_match('/".$imgfile."/i', 'jpeg')) {
             ImageJPEG($newpicture, $this->dir_target . $this->picture);
         } else {
             if (preg_match('/".$imgfile."/i', 'png')) {
                 ImagePNG($newpicture, $this->dir_target . $this->picture);
             } else {
                 if (preg_match('/".$imgfile."/i', 'gif')) {
                     ImageGIF($newpicture, $this->dir_target . $this->picture);
                 }
             }
         }
         //   }
     }
 }
示例#27
0
 function IndexAction()
 {
     $str = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 4));
     $_SESSION['VerifyCode'] = strtolower(implode('', $code));
     $width = 115;
     $height = 29;
     $im = ImageCreate($width, $height);
     // 创建图形
     ImageColorAllocate($im, 255, 255, 255);
     // 填充背景颜色为白色
     // 用淡色给图形添加杂色
     for ($i = 0; $i < 100; $i++) {
         $pxcolor = ImageColorAllocate($im, 230, 104, 66);
         ImageSetPixel($im, mt_rand(0, $width), mt_rand(0, $height), $pxcolor);
     }
     // 用深色调绘制边框
     $bordercolor = ImageColorAllocate($im, 255, 255, 255);
     ImageRectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor);
     $offset = rand(10, 30);
     $font = array('View/font/UniversityRomanStd.otf');
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 106);
         shuffle($font);
         imagettftext($im, 22, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += $width / 5 - rand(0, 2);
     }
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 5));
     // 干扰字符
     $offset = rand(10, 30);
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 66);
         shuffle($font);
         imagettftext($im, 8, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += rand(5, 10);
     }
     // 禁止缓存
     header("pragma:no-cache\r\n");
     header("Cache-Control:no-cache\r\n");
     header("Expires:0\r\n");
     if (ImageTypes() & IMG_PNG) {
         header('Content-Type:image/png');
         ImagePNG($im);
     } elseif (ImageTypes() & IMG_JPEG) {
         header('Content-Type:image/jpeg');
         ImageJPEG($im);
     } else {
         header('Content-Type:image/gif');
         ImageGif($im);
     }
 }
示例#28
0
 private function saveImageToFile($image, $filepath, $fileformat = 'jpg')
 {
     switch ($fileformat) {
         case "jpg":
         case "jpeg":
             ImageJPEG($image, $filepath);
             break;
         case "png":
             ImagePNG($image, $filepath);
             break;
     }
 }
示例#29
0
function create_avatar($imgpath, $thumbpath, $neueBreite, $neueHoehe)
{
    $size = getimagesize($imgpath);
    $breite = $size[0];
    $hoehe = $size[1];
    $RatioW = $neueBreite / $breite;
    $RatioH = $neueHoehe / $hoehe;
    if ($RatioW < $RatioH) {
        $neueBreite = $breite * $RatioW;
        $neueHoehe = $hoehe * $RatioW;
    } else {
        $neueBreite = $breite * $RatioH;
        $neueHoehe = $hoehe * $RatioH;
    }
    $neueBreite = round($neueBreite, 0);
    $neueHoehe = round($neueHoehe, 0);
    if (function_exists('gd_info')) {
        $tmp = gd_info();
        $imgsup = $tmp['GIF Create Support'] ? 1 : 2;
        unset($tmp);
    } else {
        $imgsup = 2;
    }
    if ($size[2] < $imgsup or $size[2] > 3) {
        return false;
    }
    if ($size[2] == 1) {
        $altesBild = imagecreatefromgif($imgpath);
    } elseif ($size[2] == 2) {
        $altesBild = imagecreatefromjpeg($imgpath);
    } elseif ($size[2] == 3) {
        $altesBild = imagecreatefrompng($imgpath);
    }
    if (function_exists('imagecreatetruecolor') and $size[2] != 1) {
        $neuesBild = png_create_transparent($neueBreite, $neueHoehe);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } elseif (function_exists('imagecreatetruecolor') and $size[2] == 1) {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        gif_create_transparent($neuesBild, $altesBild);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } else {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    }
    if ($size[2] == 1) {
        ImageGIF($neuesBild, $thumbpath);
    } elseif ($size[2] == 2) {
        ImageJPEG($neuesBild, $thumbpath);
    } elseif ($size[2] == 3) {
        ImagePNG($neuesBild, $thumbpath);
    }
    return true;
}
示例#30
0
 /**
  * 生成二维码后返回内容
  * @param $value
  * @return array
  */
 private function _getQrCodeContent($value)
 {
     apf_require_file('phpqrcode.php', 'classes/util/phpqrcode');
     $errorCorrectionLevel = "M";
     $matrixPointSize = "5";
     $image = QRcode::getImage($value, false, $errorCorrectionLevel, $matrixPointSize, 2);
     ob_start();
     ImagePNG($image);
     $content = ob_get_contents();
     ImageDestroy($image);
     ob_end_clean();
     return $content;
 }