예제 #1
0
파일: Authcode.php 프로젝트: beyondye/ENPHP
 /**
  * 显示验证码
  */
 function create()
 {
     $this->image = imageCreate($this->width, $this->height);
     $this->back = $this->getColor($this->bgcolor);
     imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back);
     $size = $this->width / $this->charLen - 4;
     if ($size > $this->height) {
         $size = $this->height;
     }
     $left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5;
     $code = '';
     for ($i = 0; $i < $this->charLen; $i++) {
         $randKey = rand(0, count($this->arrChr) - 1);
         $randText = $this->arrChr[$randKey];
         $code .= $randText;
         $textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100));
         $font = $this->fontPath . '/' . rand(1, 5) . ".ttf";
         $randsize = rand($size - $size / 10, $size + $size / 10);
         $location = $left + ($i * $size + $size / 10);
         @imagettftext($this->image, $randsize, rand(-18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $randText);
     }
     if ($this->showNoisePix == true) {
         $this->setNoisePix();
     }
     if ($this->showNoiseLine == true) {
         $this->setNoiseLine();
     }
     if ($this->showBorder == true) {
         $this->borderColor = $this->getColor($this->borderColor);
         imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor);
     }
     $this->text = strtolower($code);
 }
예제 #2
0
 /**
  * @see wcf\system\image\adapter\IImageAdapter::createEmptyImage()
  */
 public function createEmptyImage($width, $height)
 {
     $this->image = imageCreate($width, $height);
     $this->type = IMAGETYPE_PNG;
     $this->setColor(0xff, 0xff, 0xff);
     $this->color = null;
 }
예제 #3
0
 function Graph($res)
 {
     if ($res == "svga") {
         $wd = "800";
         $ht = "600";
     } elseif ($res == "xga") {
         $wd = "1024";
         $ht = "768";
     } elseif ($res == "sxga") {
         $wd = "1280";
         $ht = "1024";
     } elseif ($res == "uxga") {
         $wd = "1600";
         $ht = "1200";
     } else {
         $wd = "640";
         $ht = "480";
     }
     $this->img = imageCreate($wd, $ht);
     $this->wte = imageColorAllocate($this->img, 255, 255, 255);
     $this->blk = imageColorAllocate($this->img, 0, 0, 0);
     $this->gry = imageColorAllocate($this->img, 100, 100, 100);
     $this->red = imageColorAllocate($this->img, 150, 0, 0);
     $this->grn = imageColorAllocate($this->img, 0, 150, 0);
     $this->blu = imageColorAllocate($this->img, 0, 0, 150);
     imagestring($this->img, 2, 5, 5, $res, $this->blu);
 }
예제 #4
0
 public static function code39($text, $height = 50, $widthScale = 1)
 {
     // if (!preg_match('/^[A-Z0-9-. $+\/%]+$/i', $text)) {
     //            throw new Exception('Invalid text input.');
     //        }
     // $text = '*' . strtoupper($text) . '*'; // *UPPERCASE TEXT*
     $length = strlen($text);
     $barcode = imageCreate($length * 16 * $widthScale, $height);
     $bg = imagecolorallocate($barcode, 255, 255, 255);
     //sets background to yellow
     imagecolortransparent($barcode, $bg);
     //makes that yellow transparent
     $black = imagecolorallocate($barcode, 0, 0, 0);
     //defines a color for black
     $chars = str_split($text);
     $colors = '';
     foreach ($chars as $char) {
         $colors .= self::$code39[$char];
     }
     foreach (str_split($colors) as $i => $color) {
         if ($color == 'b') {
             // imageLine($barcode, $i, 0, $i, $height-13, $black);
             //                imageFilledRectangle($barcode, $widthScale * $i, 0, $widthScale * ($i+1) -1 , $height-13, $black);
             imageFilledRectangle($barcode, $widthScale * $i, 0, $widthScale * ($i + 1) - 1, $height, $black);
         }
     }
     //16px per bar-set, halved, minus 6px per char, halved (5*length)
     // $textcenter = $length * 5 * $widthScale;
     //$textcenter = ($length * 8 * $widthScale) - ($length * 3);
     //
     //        imageString($barcode, 2, $textcenter, $height-13, $text, $black);
     header("Content-type: image/png");
     // out out the image
     imagepng($barcode);
 }
예제 #5
0
 public function createImage($text = '', $fontSize = 5)
 {
     // GD's built-in fonts are numbered from 1 - 5
     $font_size = $fontSize;
     // Calculate the appropriate image size
     $image_height = intval(imageFontHeight($font_size) * 2);
     $image_width = intval(strlen($text) * imageFontWidth($font_size) * 1.3);
     // Create the image
     $image = imageCreate($image_width, $image_height);
     // Create the colors to use in the image
     // gray background
     $back_color = imageColorAllocate($image, 216, 216, 216);
     // blue text
     $text_color = imageColorAllocate($image, 0, 0, 255);
     // black border
     $rect_color = imageColorAllocate($image, 0, 0, 0);
     // Figure out where to draw the text
     // (Centered horizontally and vertically
     $x = ($image_width - imageFontWidth($font_size) * strlen($text)) / 2;
     $y = ($image_height - imageFontHeight($font_size)) / 2;
     // Draw the text
     imageString($image, $font_size, $x, $y, $text, $text_color);
     // Draw a black border
     imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color);
     // Send the image to the browser
     header('Content-Type: image/png');
     imagePNG($image);
     imageDestroy($image);
 }
 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);
 }
예제 #7
0
 private function getCreateImage()
 {
     $this->image = imageCreate($this->width, $this->height);
     $background = imageColorAllocate($this->image, 255, 255, 255);
     $border = imageColorAllocate($this->image, 0, 0, 0);
     imageRectangle($this->image, 0, 0, $this->width - 1, $tihs->height - 1, $border);
 }
예제 #8
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();
}
예제 #9
0
 private function getCreateImage()
 {
     //用来创建图像资源,并初使化背影
     $this->image = imageCreate($this->width, $this->height);
     $back = imageColorAllocate($this->image, 255, 255, 255);
     $border = imageColorAllocate($this->image, 0, 0, 0);
     imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $border);
 }
예제 #10
0
 function writeCopy($filename, $width, $height) {
          if($this->isLoaded()) {
              $imageNew = imageCreate($width, $height);
              if(!$imageNew) {
                  echo "ERREUR : Nouvelle image non créée";
              }
              imageCopyResized($imageNew, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
              imageJpeg($imageNew, $filename);
          }
 }
예제 #11
0
function sendErrorImageAndDie($cerr)
{
    $new = imageCreate(600, 30);
    $bgc = imageColorAllocate($new, 255, 255, 255);
    $tc = imageColorAllocate($new, 0, 0, 0);
    imageFilledRectangle($new, 0, 0, 150, 30, $bgc);
    imageString($new, 5, 5, 5, "Error: {$cerr}", $tc);
    sendImage($new);
    die;
}
예제 #12
0
 private function getCreateImage()
 {
     //创建指定大小的画布(基于调色板)
     $this->image = imageCreate($this->width, $this->height);
     //设置颜色(白色)
     $back = imagecolorallocate($this->image, 255, 255, 255);
     //设置颜色(黑色)
     $border = imagecolorallocate($this->image, 0, 0, 0);
     //在图像中绘制一个矩形
     imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $border);
 }
예제 #13
0
 function Generate($imgName)
 {
     //        $this->GenStr();
     $this->img = imageCreate(200, 50);
     $this->GenColors();
     $this->PutLetters();
     $this->PutEllipses();
     $this->PutLines();
     imagePNG($this->img, $imgName);
     return $this->strCheck;
 }
예제 #14
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;
}
예제 #15
0
파일: fst.php 프로젝트: GavinLai/SimMatch
 function show_emptyimg($format = 'gif')
 {
     header('Content-Type: image/' . $format);
     $width = 1;
     $height = 1;
     $img = imageCreate($width, $height);
     //imageFilledRectangle($img, 0, 0, $width, $height, imagecolorallocate($img, 255, 255, 255));
     ImageColorTransparent($img, imagecolorallocate($img, 255, 255, 255));
     imagegif($img);
     imagedestroy($img);
     exit;
 }
예제 #16
0
function text2image($height, $text)
{
header("Content-type: image/png");
$width = $height * strlen($text)/ 5 * 2;
$font = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf";
$image = imageCreate($width, $height);
$backgroundColor = imageColorAllocate($image, 255, 255, 255);
$textColor = imageColorAllocate($image, 0, 0, 0);
imagefttext($image, $height/2, 0, 0, $height/10*9, $textColor, $font, $text); 
imageInterlace($image, 1);
imageColorTransparent($image, $backgroundColor);
imagePNG($image);
}
예제 #17
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;
 }
예제 #18
0
 /**
  * Placeholder code adapted from dummyimage.com
  */
 public static function placeholder($width, $height)
 {
     $file_format = 'gif';
     $width = $width;
     $height = $height;
     $text_angle = 0;
     $font = Load::getModulePath('media') . 'assets/mplus-1c-medium.ttf';
     $img = imageCreate($width, $height);
     $bg_color = imageColorAllocate($img, 196, 196, 196);
     $fg_color = imageColorAllocate($img, 94, 94, 94);
     $lines = 1;
     $text = $width . 'x' . $height;
     $fontsize = max(min($width / strlen($text) * 1.15, $height * 0.5), 5);
     $textBox = self::_imagettfbbox_t($fontsize, $text_angle, $font, $text);
     $textWidth = ceil(($textBox[4] - $textBox[1]) * 1.07);
     $textHeight = ceil((abs($textBox[7]) + abs($textBox[1])) * 1);
     $textX = ceil(($width - $textWidth) / 2);
     $textY = ceil(($height - $textHeight) / 2 + $textHeight);
     imageFilledRectangle($img, 0, 0, $width, $height, $bg_color);
     imagettftext($img, $fontsize, $text_angle, $textX, $textY, $fg_color, $font, $text);
     $offset = 60 * 60 * 24 * 14;
     //14 Days
     $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
     header($ExpStr);
     //Set a far future expire date. This keeps the image locally cached by the user for less hits to the server.
     header('Cache-Control:	max-age=120');
     header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - $offset) . " GMT");
     header('Content-type: image/' . $file_format);
     //Set the header so the browser can interpret it as an image and not a bunch of weird text.
     switch ($file_format) {
         case 'gif':
             imagegif($img);
             break;
         case 'png':
             imagepng($img);
             break;
         case 'jpg':
             imagejpeg($img);
             break;
         case 'jpeg':
             imagejpeg($img);
             break;
     }
     imageDestroy($img);
     exit;
 }
예제 #19
0
 function FunctionGraph($x1 = 2, $y1 = 2)
 {
     $width = 800;
     $height = 600;
     $this->x0 = -$x1;
     $this->y0 = -$y1;
     $this->x1 = $x1;
     $this->y1 = $y1;
     $this->posX0 = $width / 2;
     $this->posY0 = $height / 2;
     $this->scale = (double) ($width - 20) / ($this->x1 - $this->x0);
     $this->img = imageCreate($width, $height);
     $this->wte = imageColorAllocate($this->img, 255, 255, 255);
     $this->blk = imageColorAllocate($this->img, 0, 0, 0);
     $this->gry = imageColorAllocate($this->img, 100, 100, 100);
     $this->grn = imageColorAllocate($this->img, 0, 150, 0);
     $this->blu = imageColorAllocate($this->img, 0, 0, 150);
 }
예제 #20
0
 public function creat_images($num)
 {
     $type = 2;
     header("Content-type: image/PNG");
     // 產生種子, 作圖形干擾用
     srand((double) microtime() * 10000000000);
     // 產生圖檔, 及定義顏色
     $img_x = 120;
     $img_y = 28;
     $im = imageCreate($img_x, $img_y);
     //ImageColorAllocate 分配圖形的顏色
     $back = ImageColorAllocate($im, rand(200, 255), rand(200, 255), rand(200, 255));
     $authText = $this->num2adb($num);
     imageFill($im, 0, 0, $back);
     // imageString($im, 5, rand(0,55), rand(0,40), $authText, $font);
     $str_x = 0;
     $str_y = 0;
     for ($i = 0; $i < strlen($authText); $i++) {
         $str_x += rand(10, 20);
         $str_y = rand(0, $img_y / 2);
         $font = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
         imageString($im, 5, $str_x, $str_y, $authText[$i], $font);
     }
     // 插入圖形干擾點共 50 點, 可插入更多, 但可能會使圖形太過混雜
     for ($i = 0; $i < rand(50, 200); $i++) {
         $point = ImageColorAllocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($im, rand(0, $img_x), rand(0, $img_y), $point);
     }
     for ($i = 1; $i <= rand(2, 5); $i++) {
         $point = ImageColorAllocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imageline($im, rand(0, $img_x), rand(0, $img_y), rand(0, $img_x), rand(0, $img_y), $point);
     }
     // 定義圖檔類型並輸入, 最後刪除記憶體
     if ($type == 1) {
         ob_start();
         ImagePNG($im);
         $output = ob_get_contents();
         ob_end_clean();
         echo base64_encode($output);
     } else {
         ImagePNG($im);
     }
     ImageDestroy($im);
 }
예제 #21
0
 /**
  * Create test image.
  *
  * @param string $filename
  * @return void
  */
 protected function createTestImage($filename)
 {
     $filename = $this->getFullPath($filename);
     if (!file_exists($filename)) {
         // Create an image with the specified dimensions
         $image = imageCreate(300, 200);
         // Create a color (this first call to imageColorAllocate
         //  also automatically sets the image background color)
         $colorYellow = imageColorAllocate($image, 255, 255, 0);
         // Draw a rectangle
         imageFilledRectangle($image, 50, 50, 250, 150, $colorYellow);
         $directory = dirname($filename);
         if (!file_exists($directory)) {
             mkdir($directory, 0777, true);
         }
         imageJpeg($image, $filename);
         // Release memory
         imageDestroy($image);
     }
 }
예제 #22
0
파일: Visual.php 프로젝트: arsenyru/geodata
 public function getPNG()
 {
     // создаем картинку
     $image = imageCreate($this->width + $this->widthLegend, $this->height);
     $backColor = imageColorAllocate($image, $this->colorBG >> 16, ($this->colorBG >> 8) % 256, $this->colorBG % 256);
     $centerColor = imageColorAllocate($image, $this->colorCenter >> 16, ($this->colorCenter >> 8) % 256, $this->colorCenter % 256);
     $pointsColor = imageColorAllocate($image, $this->colorPoints >> 16, ($this->colorPoints >> 8) % 256, $this->colorPoints % 256);
     $legendColor = imageColorAllocate($image, $this->colorLegend >> 16, ($this->colorLegend >> 8) % 256, $this->colorLegend % 256);
     // background
     imageFilledRectangle($image, 0, 0, $this->width, $this->height, $backColor);
     imageRectangle($image, $this->width, 0, $this->widthLegend + $this->width - 1, $this->height - 1, $legendColor);
     // добавляем масштаб в легенду
     imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2 - 1, $this->width + 10, $this->height - $this->fontSize * 2 + 1, $legendColor);
     imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2, $this->width + 20, $this->height - $this->fontSize * 2, $legendColor);
     imageLine($image, $this->width + 20, $this->height - $this->fontSize * 2 - 1, $this->width + 20, $this->height - $this->fontSize * 2 + 1, $legendColor);
     imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize + 20, $this->height - $this->fontSize * 1.5, $legendColor, $this->pathToFont, "{$this->metersIn10Pix} {$this->metersLabel}");
     // center
     imageFilledEllipse($image, $this->centerWidth, $this->centerHeight, $this->sizePoints, $this->sizePoints, $centerColor);
     imageTTFText($image, $this->fontSize, 0, $this->centerWidth, $this->centerHeight + $this->fontSize + $this->sizePoints, $centerColor, $this->pathToFont, "0");
     imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2, $legendColor, $this->pathToFont, "0 - {$this->centerLabel}");
     // points
     $i = 1;
     foreach ($this->pointsBased as $v) {
         $angle = $v->getPoint()->getAzimuth() - 90;
         // угол для тригонометрии
         $pointWidth = $this->centerWidth + $this->k * ($v->getPoint()->getDistance() * cos(deg2rad($angle)));
         $pointHeight = $this->centerHeight + $this->k * ($v->getPoint()->getDistance() * sin(deg2rad($angle)));
         // рисуем точку
         imageEllipse($image, $pointWidth, $pointHeight, $this->sizePoints, $this->sizePoints, $pointsColor);
         // подпись
         imageTTFText($image, $this->fontSize, 0, $pointWidth, $pointHeight + $this->fontSize + $this->sizePoints, $pointsColor, $this->pathToFont, $i);
         // в легенду
         imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2 * ($i + 1), $legendColor, $this->pathToFont, "{$i} - " . $v->getTitle());
         $i++;
     }
     ob_start();
     imagePng($image);
     $str = ob_get_clean();
     return $str;
 }
예제 #23
0
 function draw()
 {
     header("Content-type: image/" . $this->format);
     $this->image = imageCreate($this->x, $this->y);
     $transparrent = ImageColorAllocate($this->image, 254, 254, 254);
     imagecolortransparent($this->image, $transparrent);
     $black = ImageColorAllocate($this->image, 0, 0, 0);
     $white = ImageColorAllocate($this->image, 255, 255, 255);
     ImageFill($this->image, 0, 0, $transparrent);
     //Shadow
     imagefilledellipse($this->image, $this->x / 2 + 5, $this->y / 2 + 5, $this->x - 20, $this->y - 20, $black);
     //Main Circle
     imagefilledellipse($this->image, $this->x / 2, $this->y / 2, $this->x - 20, $this->y - 20, $white);
     //Inner Ring
     imageellipse($this->image, $this->x / 2, $this->y / 2, $this->x - 20, $this->y - 20, $black);
     //Needle
     imagefilledrectangle($this->image, $this->x / 2 - 2, 30, $this->x / 2 + 2, $this->y / 2, $black);
     //Center Pin
     imagefilledellipse($this->image, $this->x / 2, $this->y / 2, 10, 10, $black);
     ImagePNG($this->image);
     ImageDestroy($this->image);
 }
예제 #24
0
function create_thumb($imgpath, $thumbpath, $neueBreite)
{
    $size = getimagesize($imgpath);
    $breite = $size[0];
    $hoehe = $size[1];
    $neueHoehe = intval($hoehe * $neueBreite / $breite);
    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 = imagecreatetruecolor($neueBreite, $neueHoehe);
        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;
}
예제 #25
0
 public static function show()
 {
     $width = self::$width;
     $height = self::$height;
     $len = self::$len;
     $bgcolor = self::$bgcolor;
     $noise = self::$noise;
     $noisenum = self::$noisenum;
     $border = self::$border;
     $bordercolor = self::$bordercolor;
     self::$_image = imageCreate($width, $height);
     $back = self::getcolor($bgcolor);
     imageFilledRectangle(self::$_image, 0, 0, $width, $height, $back);
     $size = $width / $len;
     if ($size > $height) {
         $size = $height;
     }
     $left = ($width - $len * ($size + $size / 10)) / $size;
     for ($i = 0; $i < $len; $i++) {
         $randtext = self::vchar();
         self::$_code .= $randtext;
         $textColor = imageColorAllocate(self::$_image, rand(0, 100), rand(0, 100), rand(0, 100));
         $font = dirname(__FILE__) . "/3.ttf";
         $randsize = rand($size - $size / 5, $size - $size / 10);
         $location = $left + ($i * $size + $size / 10);
         imagettftext(self::$_image, $randsize, rand(-18, 18), $location, rand($size - $size / 100, $size + $size / 100), $textColor, $font, $randtext);
     }
     if ($noise == true) {
         self::setnoise();
     }
     self::setCode(self::$_code);
     //setrawcookie("code",$code,time()+3600,"/");
     //setcookie("code", $code, time()+120);
     $bordercolor = self::getcolor($bordercolor);
     if ($border == true) {
         imageRectangle(self::$_image, 0, 0, $width - 1, $height - 1, $bordercolor);
     }
     return self::$_image;
 }
예제 #26
0
function create_image($text, $size, $font, $color, $bgcolor, $x = 0, $y = 0)
{
    if ($x > 0) {
        $img_x = $x;
    } else {
        $img_x = $size * 0.8 * strlen($text);
    }
    // the factor reduces the amount of whitespace at the end of the string
    if ($y > 0) {
        $img_y = $y;
    } else {
        $img_y = $size + 10;
    }
    $img_base = (int) (($size + 10) * 0.75);
    // a rough guesstimate of where the text baseline should be in the image
    // echo "Text is $text, $img_x, $img_y, $img_base, R: $r G: $g B: $b <br />"; exit;
    $im = @imageCreate($img_x, $img_y) or die("Cannot Initialize new GD image stream");
    $background_color = imageColorAllocate($im, hexdec(substr($bgcolor, 0, 2)), hexdec(substr($bgcolor, 2, 2)), hexdec(substr($bgcolor, 4, 2)));
    $text_color = imageColorAllocate($im, hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
    ImageTTFText($im, $size, 0, 2, $img_base, $text_color, $font, $text);
    /*
    	// 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/jpeg");
    ImageJPEG($im);
}
 /**
  * Create PNG of font name written with font TTF.
  */
 public function generate_image()
 {
     $width = $height = $font_size = $left_margin = $background_color = $font_color = false;
     extract($this->preview_attributes, EXTR_IF_EXISTS);
     // Text Mask
     $mask = imageCreate($width, $height);
     $background = imageColorAllocate($mask, $background_color[0], $background_color[1], $background_color[2]);
     $foreground = imageColorAllocate($mask, $font_color[0], $font_color[1], $font_color[2]);
     $ttf_path = $this->font->maybe_get_remote_ttf();
     if (!file_exists($ttf_path)) {
         wp_die('Could not load $ttf_path: ' . $ttf_path);
     }
     // Text
     $y = $this->get_centered_y_coordinate($font_size, $ttf_path, $this->font->family);
     imagettftext($mask, $font_size, 0, $left_margin, $y, $foreground, $ttf_path, $this->font->family);
     // White fill
     $white = imageCreate($width, $height);
     $background = imageColorAllocate($white, $background_color[0], $background_color[1], $background_color[2]);
     // Image
     $image = imagecreatetruecolor($width, $height);
     imagesavealpha($image, true);
     imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));
     // Apply Mask to Image
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $alpha = imagecolorsforindex($mask, imagecolorat($mask, $x, $y));
             $alpha = 127 - floor($alpha['red'] / 2);
             $color = imagecolorsforindex($white, imagecolorat($white, $x, $y));
             imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $color['red'], $color['green'], $color['blue'], $alpha));
         }
     }
     ob_start();
     imagePNG($image);
     $image = ob_get_clean();
     $this->save_image($image);
     // header("Content-type: image/png");
     // echo $image;
 }
예제 #28
0
 /**
  * 显示验证码
  *
  */
 function show()
 {
     $this->image = imageCreate($this->width, $this->height);
     $this->back = $this->getColor($this->bgcolor);
     imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back);
     $size = $this->width / $this->charLen - 4;
     if ($size > $this->height) {
         $size = $this->height;
     }
     $left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5;
     $code = '';
     for ($i = 0; $i < $this->charLen; $i++) {
         $randKey = rand(0, count($this->arrChr) - 1);
         $randText = $this->arrChr[$randKey];
         $code .= $randText;
         $textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100));
         $font = $this->fontPath . "1.ttf";
         $randsize = rand($size - $size / 10, $size + $size / 10);
         $location = $left + ($i * $size + $size / 10);
         imagestring($this->image, mt_rand(3, 5), $location, 5, $randText, imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)));
         //imagettftext($this->image, $randsize, rand(- 18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $code);
     }
     if ($this->showNoisePix == true) {
         $this->setNoisePix();
     }
     if ($this->showNoiseLine == true) {
         $this->setNoiseLine();
     }
     if ($this->showBorder == true) {
         $this->borderColor = $this->getColor($this->borderColor);
         imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor);
     }
     $this->CI->session->set_userdata('auth_code', $code);
     ob_clean();
     header("Content-type: image/jpeg");
     imagejpeg($this->image);
     imagedestroy($this->image);
 }
예제 #29
0
 public function index()
 {
     $new_number = "";
     $img_width = 48;
     $img_height = 16;
     $mycharset = array();
     for ($i = 0; $i <= 9; $i++) {
         array_push($mycharset, $i);
     }
     for ($i = 0; $i < 26; $i++) {
         array_push($mycharset, chr(ord("A") + $i));
     }
     srand(microtime() * 100000);
     for ($ti = 0; $ti < 4; $ti++) {
         $newnumber = $mycharset[rand(0, 35)];
         if ($newnumber == "0") {
             $newnumber = 1;
         }
         if ($newnumber == "o" || $newnumber == "O") {
             $newnumber = "L";
         }
         $new_number .= $newnumber;
     }
     $new_number = strtoupper($new_number);
     $_SESSION["code"] = $new_number;
     $number_img = imageCreate($img_width, $img_height);
     imagecolorallocate($number_img, 255, 255, 255);
     for ($i = 1; $i <= 128; $i++) {
         imagestring($number_img, 1, mt_rand(1, $img_width), mt_rand(1, $img_height), "*", imagecolorallocate($number_img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)));
     }
     for ($i = 0; $i < strlen($new_number); $i++) {
         imagestring($number_img, mt_rand(3, 5), $i * $img_width / 4 + mt_rand(1, 4), mt_rand(1, $img_height / 5), $new_number[$i], imagecolorallocate($number_img, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)));
     }
     header('Content-Type: image/jpeg');
     imagepng($number_img);
     imagedestroy($number_img);
 }
예제 #30
0
<?php

header("Content-type:  image/gif");
dl('php3_gd.dll');
//header("Content-type:  image/png");
$image = imageCreate(100, 100);
imageGIF($image);
//imagePNG($image);
// create an interlaced image for better loading in the browser
imageInterlace($image, 1);
// mark background color as being transparent
$colorBackgr = imageColorAllocate($image, 192, 192, 192);
imageColorTransparent($image, $colorBackgr);