Example #1
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);
 }
Example #2
0
 /**
  * 显示验证码
  */
 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);
 }
Example #3
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();
}
Example #4
0
    /**
     * Generates a wallpaper with the latest data and updates desktop background
     *
     * @param array $data Array with the latest build history per project
     */
    private function updateBackground($data)
    {
        $this->updatedAt = microtime(true);
        $this->image = imagecreatetruecolor($this->get('image_width'), $this->get('image_height'));
        imageantialias($this->image, true);
        $this->initializeColors();
        imagefill($this->image, 0, 0, $this->get('background_color'));
        $numProject = 0;
        foreach ($data['projects'] as $project => $builds) {
            // the most recent build is always shown on top
            rsort($builds);
            $x1 = $this->get('horizontal_padding') + ($this->get('bar_width') + $this->get('horizontal_gutter')) * $numProject;
            $x2 = $x1 + $this->get('bar_width');
            // plot each project slug
            $this->addTextToImage(substr($project, 0, $this->get('max_number_letters')), $x1, $this->get('vertical_padding') - 0.2 * $this->get('font_size'));
            foreach ($builds as $i => $build) {
                $y1 = $this->get('vertical_padding') + $this->get('font_size') + ($this->get('bar_height') + $this->get('vertical_gutter')) * $i;
                $y2 = $y1 + $this->get('bar_height');
                $color = 'ok' == $build ? $this->get('success_color') : $this->get('failure_color');
                // plot a bar for each project build
                imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
            }
            $numProject++;
        }
        $this->addTextToImage('Last update: ' . $data['last_update'], $this->get('horizontal_padding'), $this->get('image_height') - $this->get('font_size'));
        // Hack: two different images are needed to update the wallpaper
        // One holds the current wallpaper and the other is the new one
        // If you use just one image and modify it, the OS doesn't reload it
        if (file_exists($this->evenBackgroundImagePath)) {
            $this->imagePath = $this->oddBackgroundImagePath;
            unlink($this->evenBackgroundImagePath);
        } elseif (file_exists($this->oddBackgroundImagePath)) {
            $this->imagePath = $this->evenBackgroundImagePath;
            unlink($this->oddBackgroundImagePath);
        } else {
            $this->imagePath = $this->oddBackgroundImagePath;
        }
        imagepng($this->image, $this->imagePath);
        imagedestroy($this->image);
        // Wallpaper is reloaded via AppleScript
        $scriptPath = $this->dir . '/update-background.scpt';
        file_put_contents($scriptPath, <<<END
tell application "System Events"
    tell current desktop
        set picture to POSIX file "file://localhost/{$this->imagePath}"
    end tell
end tell
END
);
        system("osascript {$scriptPath}");
    }
Example #5
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;
 }
Example #6
0
 /**
  * Make image
  *
  */
 protected function _image()
 {
     $this->_image = imagecreate($this->config['width'], $this->config['height']);
     imageFilledRectangle($this->_image, 0, 0, $this->config['width'], $this->config['height'], $this->_color($this->config['bgColor']));
     $seed = $this->_seed();
     $fonts = $this->_fonts();
     $_SESSION[$this->config['sessionValueKey']] = $seed;
     $_SESSION[$this->config['sessionTtlKey']] = time() + $this->config['ttl'];
     for ($i = 0; $i < $this->config['length']; $i++) {
         $char = substr($seed, $i, 1);
         $x = $this->config['padding'] + $i * ($this->config['size'] + $this->config['space']);
         $y = mt_rand(0.7 * $this->config['height'], 0.9 * $this->config['height']);
         $charColor = imageColorAllocate($this->_image, mt_rand(50, 155), mt_rand(50, 155), mt_rand(50, 155));
         imagettftext($this->_image, $this->config['size'], mt_rand(-18, 18), $x, $y, $charColor, $fonts[$i], $char);
     }
     $this->_noise();
 }
Example #7
0
function textToImg($text, $backRGB, $strRGB, $fontPath, $fontSize, $margin)
{
    // 大きさを測定
    $result = imageTTFBBox($fontSize, 0, $fontPath, $text);
    // 幅と高さを取得
    $width = abs($result[4]) + abs($result[6]) + $margin * 2;
    $height = abs($result[1]) + abs($result[7]) + $margin * 2;
    // イメージリソースを生成
    $img = imageCreateTrueColor($width, $height);
    // 色を生成
    $backColor = imageColorAllocate($img, $backRGB['red'], $backRGB['green'], $backRGB['blue']);
    $strColor = imageColorAllocate($img, $strRGB['red'], $strRGB['green'], $strRGB['blue']);
    // 背景を塗りつぶす
    imageFilledRectangle($img, 0, 0, $width, $height, $backColor);
    // 文字を描く
    imageTTFText($img, $fontSize, 0, $margin + abs($result[0]), $margin + abs($result[7]), $strColor, $fontPath, $text);
    return $img;
}
 /**
  * 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);
     }
 }
Example #9
0
 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;
 }
Example #10
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;
 }
Example #11
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);
 }
Example #12
0
 private function output($saveStr = false)
 {
     $this->image = ImageCreate($this->larguaImagem, $this->alturaImagem);
     $background = $this->color($this->corDeFundo);
     imageFilledRectangle($this->image, 0, 0, $this->larguaImagem, $this->alturaImagem, $background);
     srand($this->make_seed());
     # space in chars
     $percent80 = $this->larguaImagem - $this->larguaImagem * 0.15;
     #$textSpace = ceil(($this->larguaImagem-40)/$this->maxChars) ;
     $textSpace = ceil($percent80 / $this->maxChars);
     $topMargim = $this->alturaImagem > 20 ? $this->alturaImagem / 2.2 : 5;
     # generate chars
     for ($i = 0; $i < $this->maxChars; $i++) {
         $this->gerarValor = str_shuffle($this->gerarValor);
         shuffle($this->hexcolors);
         shuffle($this->fonts);
         # select a char on array
         $char = $this->gerarValor[0];
         # rotarion of chars
         $rotate = $this->rotateImg > 1 ? rand(-9, 10) : 0;
         # join chars value
         $saveStr .= $char;
         # make captcha
         imagettftext($this->image, $this->fontSize, $rotate, 10 + $i * $textSpace, rand($this->alturaImagem, $topMargim), $this->randcolor(), "{$this->serverRoot}{$this->path}{$this->fonts[0]}", $char);
     }
     for ($k = 0; $k < $this->maxChars / 2; $k++) {
         if ($this->noSquare == 0) {
             $this->randsquare();
         }
         $this->randline();
     }
     header("Content-type: image/jpeg");
     imagejpeg($this->image);
     imagedestroy($this->image, '', 100);
     return $saveStr;
 }
Example #13
0
 function draw_rectangle($x1, $y1, $x2, $y2, $color, $filled)
 {
     if ($filled) {
         imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
     } else {
         imageRectangle($this->image, $x1, $y1, $x2, $y2, $color);
     }
 }
Example #14
0
// this works because Julian dates specify an absolute number
// of days -> the difference between Julian birthday and
// "Julian today" gives the number of days alive
$daysGone = abs(gregorianToJD($birthMonth, $birthDay, $birthYear) - gregorianToJD(date("m"), date("d"), date("Y")));
// create image
$image = imageCreate($diagramWidth, $diagramHeight);
// allocate all required colors
$colorBackgr = imageColorAllocate($image, 192, 192, 192);
$colorForegr = imageColorAllocate($image, 255, 255, 255);
$colorGrid = imageColorAllocate($image, 0, 0, 0);
$colorCross = imageColorAllocate($image, 0, 0, 0);
$colorPhysical = imageColorAllocate($image, 0, 0, 255);
$colorEmotional = imageColorAllocate($image, 255, 0, 0);
$colorIntellectual = imageColorAllocate($image, 0, 255, 0);
// clear the image with the background color
imageFilledRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $colorBackgr);
// calculate start date for diagram and start drawing
$nrSecondsPerDay = 60 * 60 * 24;
$diagramDate = time() - $daysToShow / 2 * $nrSecondsPerDay + $nrSecondsPerDay;
for ($i = 1; $i < $daysToShow; $i++) {
    $thisDate = getDate($diagramDate);
    $xCoord = $diagramWidth / $daysToShow * $i;
    // draw day mark and day number
    imageLine($image, $xCoord, $diagramHeight - 25, $xCoord, $diagramHeight - 20, $colorGrid);
    imageString($image, 3, $xCoord - 5, $diagramHeight - 16, $thisDate["mday"], $colorGrid);
    $diagramDate += $nrSecondsPerDay;
}
// draw rectangle around diagram (marks its boundaries)
imageRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 20, $colorGrid);
// draw middle cross
imageLine($image, 0, ($diagramHeight - 20) / 2, $diagramWidth, ($diagramHeight - 20) / 2, $colorCross);
Example #15
0
 protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color)
 {
     $color = $this->gdColor($color);
     if ($color === false) {
         return false;
     }
     return imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
 }
function cforms2_reset_captcha()
{
    check_admin_referer('cforms2_reset_captcha');
    $cformsSettings = get_option('cforms_settings');
    $cap = $cformsSettings['global']['cforms_captcha_def'];
    ### overwrite for admin demo purposes, no cookie set though
    if (count($_GET) > 4) {
        $cap = $_GET;
    }
    $min = cforms2_prepVal($cap['c1'], 4);
    $max = cforms2_prepVal($cap['c2'], 5);
    $src = cforms2_prepVal($cap['ac'], 'abcdefghijkmnpqrstuvwxyz23456789');
    $img_sz_type = 0;
    $img_sz_width = cforms2_prepVal($cap['w'], 115);
    $img_sz_height = cforms2_prepVal($cap['h'], 25);
    $im_bg_type = 1;
    $im_bg_url = plugin_dir_path(__FILE__) . 'captchabg/' . cforms2_prepVal($cap['bg'], '1.gif');
    $font_url = plugin_dir_path(__FILE__) . 'captchafonts/' . cforms2_prepVal($cap['f'], 'font4.ttf');
    $min_font_size = cforms2_prepVal($cap['f1'], 17);
    $max_font_size = cforms2_prepVal($cap['f2'], 19);
    $min_angle = cforms2_prepVal($cap['a1'], -12);
    $max_angle = cforms2_prepVal($cap['a2'], 12);
    $col_txt_type = 4;
    $col = cforms2_prepVal($cap['c'], '#000066');
    $col_txt_r = hexdec(substr($col, 1, 2));
    $col_txt_g = hexdec(substr($col, 3, 2));
    $col_txt_b = hexdec(substr($col, 5, 2));
    $border = cforms2_prepVal($cap['l'], '#000066');
    $border_r = hexdec(substr($border, 1, 2));
    $border_g = hexdec(substr($border, 3, 2));
    $border_b = hexdec(substr($border, 5, 2));
    $char_padding = 2;
    $output_type = 'png';
    $no = cforms2_prepVal($_GET['ts'], '');
    ### captcha random code
    $srclen = strlen($src) - 1;
    $length = mt_rand($min, $max);
    $turing = '';
    for ($i = 0; $i < $length; $i++) {
        $turing .= substr($src, mt_rand(0, $srclen), 1);
    }
    $tu = $cap['i'] == 'i' ? strtolower($turing) : $turing;
    if (!(isset($_GET['c1']) || isset($_GET['c2']) || isset($_GET['ac']))) {
        setcookie("turing_string_" . $no, $cap['i'] . '+' . md5($tu), time() + 60 * 60 * 5, "/");
    }
    $font = $font_url;
    ### initialize variables
    $length = strlen($turing);
    $data = array();
    $image_width = $image_height = 0;
    $codelen = 0;
    ### build the data array of the characters, size, placement, etc.
    for ($i = 0; $i < $length; $i++) {
        $char = substr($turing, $i, 1);
        $size = mt_rand($min_font_size, $max_font_size);
        $angle = mt_rand($min_angle, $max_angle);
        $bbox = ImageTTFBBox($size, $angle, $font, $char);
        $char_width = max($bbox[2], $bbox[4]) - min($bbox[0], $bbox[6]);
        $char_height = max($bbox[1], $bbox[3]) - min($bbox[7], $bbox[5]);
        $codelen = $codelen + $char_width + $char_padding;
        $image_width += $char_width + $char_padding;
        $image_height = max($image_height, $char_height);
        $data[] = array('char' => $char, 'size' => $size, 'angle' => $angle, 'height' => $char_height, 'width' => $char_width);
    }
    ### calculate the final image size, adding some padding
    $x_padding = 12;
    if ($img_sz_type == 1) {
        $image_width += $x_padding * 2;
        $image_height = $image_height * 1.5 + 2;
    } else {
        $image_width = $img_sz_width;
        $image_height = $img_sz_height;
    }
    ### build the image, and allocte the colors
    $im = ImageCreate($image_width, $image_height);
    $d1 = $d2 = $d3 = 0;
    while ($d1 < 50 and $d2 < 50 and $d3 < 50) {
        $r = mt_rand(200, 255);
        $g = mt_rand(200, 255);
        $b = mt_rand(200, 255);
        $d1 = abs($r - $g);
        $d2 = abs($r - $b);
        $d3 = abs($g - $b);
    }
    ImageColorAllocate($im, $r, $g, $b);
    $color_border = ImageColorAllocate($im, $border_r, $border_g, $border_b);
    ImageColorAllocate($im, round($r * 0.85), round($g * 0.85), round($b * 0.85));
    ImageColorAllocate($im, round($r * 0.95), round($g * 0.95), round($b * 0.95));
    ImageColorAllocate($im, round($r * 0.9), round($g * 0.9), round($b * 0.9));
    $d1 = mt_rand(0, 50);
    $d2 = mt_rand(0, 50);
    $d3 = mt_rand(0, 50);
    $d1 = $d2 = $d3 = 0;
    while ($d1 < 100 and $d2 < 100 and $d3 < 100) {
        $r = mt_rand(0, 150);
        $g = mt_rand(0, 150);
        $b = mt_rand(0, 150);
        $d1 = abs($r - $g);
        $d2 = abs($r - $b);
        $d3 = abs($g - $b);
    }
    switch ($col_txt_type) {
        case 1:
            $col_txt = ImageColorAllocate($im, $r, $g, $b);
            break;
        case 2:
            $col_txt = ImageColorAllocate($im, 0, 0, 0);
            break;
        case 3:
            $col_txt = ImageColorAllocate($im, 255, 255, 255);
            break;
        case 4:
            $col_txt = ImageColorAllocate($im, $col_txt_r, $col_txt_g, $col_txt_b);
            break;
    }
    $image_data = getimagesize($im_bg_url);
    $image_type = $image_data[2];
    if ($image_type == 1) {
        $img_src = imagecreatefromgif($im_bg_url);
    } elseif ($image_type == 2) {
        $img_src = imagecreatefromjpeg($im_bg_url);
    } elseif ($image_type == 3) {
        $img_src = imagecreatefrompng($im_bg_url);
    }
    if ($im_bg_type == 1) {
        imagesettile($im, $img_src);
        imageFilledRectangle($im, 0, 0, $image_width, $image_height, IMG_COLOR_TILED);
    } else {
        imagecopyresampled($im, $img_src, 0, 0, 0, 0, $image_width, $image_height, $image_data[0], $image_data[1]);
    }
    $pos_x = ($image_width - $codelen) / 2;
    foreach ($data as $d) {
        $pos_y = ($image_height + $d['height']) / 2;
        ImageTTFText($im, $d['size'], $d['angle'], $pos_x, $pos_y, $col_txt, $font, $d['char']);
        $pos_x += $d['width'] + $char_padding;
    }
    ### a nice border
    ImageRectangle($im, 0, 0, $image_width - 1, $image_height - 1, $color_border);
    // There can be some output from other loaded PHP files, therefore clean output.
    ob_end_clean();
    switch ($output_type) {
        case 'jpeg':
            Header('Content-type: image/jpeg');
            ImageJPEG($im, NULL, 100);
            break;
        case 'png':
        default:
            Header('Content-type: image/png');
            ImagePNG($im);
            break;
    }
    flush();
    ImageDestroy($im);
    die;
}
Example #17
0
 function makeThumb($width = 128, $height = 128)
 {
     $image_info = $this->getInfo($this->src_image_name);
     if (!$image_info) {
         return false;
     }
     $src_image_type = $image_info["type"];
     $img = $this->createImage($src_image_type, $this->src_image_name);
     if (!$img) {
         return false;
     }
     $width = $width == 0 ? $image_info["width"] : $width;
     $height = $height == 0 ? $image_info["height"] : $height;
     $width = $width > $image_info["width"] ? $image_info["width"] : $width;
     $height = $height > $image_info["height"] ? $image_info["height"] : $height;
     $srcW = $image_info["width"];
     $srcH = $image_info["height"];
     if ($srcH * $width > $srcW * $height) {
         $width = round($srcW * $height / $srcH);
     } else {
         $height = round($srcH * $width / $srcW);
     }
     //*
     $new = @imagecreatetruecolor($width, $height);
     $white = @imagecolorallocate($new, 0xff, 0xff, 0xff);
     @imagefilltoborder($new, 0, 0, $white, $white);
     if ($new) {
         $backgroundColor = @imageColorAllocate($new, 255, 255, 255);
         @imageFilledRectangle($new, 0, 0, $width - 1, $height - 1, $backgroundColor);
         ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     } else {
         $new = imagecreate($width, $height);
         $backgroundColor = @imageColorAllocate($new, 255, 255, 255);
         @imageFilledRectangle($new, 0, 0, $width - 1, $height - 1, $backgroundColor);
         ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     }
     //*/
     if ($this->save_file) {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     $src_img = ImageGIF($new, $this->save_file);
                 } else {
                     $src_img = ImagePNG($new, $this->save_file);
                 }
                 break;
             case 2:
                 $src_img = ImageJPEG($new, $this->save_file, $this->jpeg_quality);
                 break;
             case 3:
                 $src_img = ImagePNG($new, $this->save_file);
                 break;
             default:
                 $src_img = ImageJPEG($new, $this->save_file, $this->jpeg_quality);
                 break;
         }
     } else {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     header("Content-type: image/gif");
                     $src_img = ImageGIF($new);
                 } else {
                     header("Content-type: image/png");
                     $src_img = ImagePNG($new);
                 }
                 break;
             case 2:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($new, "", $this->jpeg_quality);
                 break;
             case 3:
                 header("Content-type: image/png");
                 $src_img = ImagePNG($new);
                 break;
             default:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($new, "", $this->jpeg_quality);
                 break;
         }
     }
     ImageDestroy($new);
     ImageDestroy($img);
     return true;
 }
Example #18
0
    foreach ($per_host as $index => $percent) {
        $week_day++;
        if ($week_day > 6) {
            $week_day -= 7;
        }
        if ($index / 2 == (int) ($index / 2)) {
            $color = imageColorAllocate($img, 249, 243, 70);
            $color2 = imageColorAllocate($img, 242, 226, 42);
            $color3 = imageColorAllocate($img, 226, 210, 34);
        } else {
            $color = imageColorAllocate($img, 11, 215, 252);
            $color2 = imageColorAllocate($img, 7, 203, 239);
            $color3 = imageColorAllocate($img, 7, 187, 219);
        }
        $y1 = round($imageW - $imageW * $percent + 12);
        imageFilledRectangle($img, $x1, $y1, $x2, $y2, $color);
        $points = array(0 => $x1, 1 => $y1, 2 => $x1 + 3, 3 => $y1 - 5, 4 => $x1 + $collW + 3, 5 => $y1 - 5, 6 => $x2, 7 => $y1);
        imageFilledPolygon($img, $points, 4, $color2);
        $points = array(0 => $x2, 1 => $y1, 2 => $x1 + $collW + 3, 3 => $y1 - 5, 4 => $x1 + $collW + 3, 5 => $y2 - 5, 6 => $x2, 7 => $y2);
        imageFilledPolygon($img, $points, 4, $color3);
        // imageTTFtext($img, 7, 90, $x1+8, 50, $colorBlack, BASEDIR.'/assets/fonts/font.ttf', $host_data[$index]);
        imagestringup($img, 1, $x1 + 3, 52, $host_data[$index], $colorBlack);
        imageTTFtext($img, 6, 0, $x1 + 3, 66, $colorBlack, BASEDIR . '/assets/fonts/font.ttf', $arr_week[$week_day]);
        $x1 += $collW;
        $x2 += $collW;
    }
    //Header("Content-type: image/gif");
    ImageGIF($img, BASEDIR . $imagecache);
    ImageDestroy($img);
}
echo '<img src="' . $imagecache . '?' . date_fixed(SITETIME, "dmY") . '" alt="Неделя" /><br /><br />';
function check_selection_main()
{
    //global $b_row;
    # check the status of the block.
    ###################################################
    if (USE_LOCK_TABLES == 'Y') {
        $sql = "LOCK TABLES blocks WRITE, temp_orders WRITE, currencies READ, prices READ, banners READ";
        $result = mysql_query($sql) or die(" <b>Dear Webmaster: The current MySQL user does not have permission to lock tables. Please give this user permission to lock tables, or turn off locking in the Admin. To turn off locking in the Admin, please go to Main Config and look under the MySQL Settings.<b>");
    } else {
        // poor man's lock
        $sql = "UPDATE `config` SET `val`='YES' WHERE `key`='SELECT_RUNNING' AND `val`='NO' ";
        $result = mysql_query($sql) or die(mysql_error());
        if (mysql_affected_rows() == 0) {
            // make sure it cannot be locked for more than 30 secs
            // This is in case the proccess fails inside the lock
            // and does not release it.
            $unix_time = time();
            // get the time of last run
            $sql = "SELECT * FROM `config` where `key` = 'LAST_SELECT_RUN' ";
            $result = @mysql_query($sql);
            $t_row = @mysql_fetch_array($result);
            if ($unix_time > $t_row['val'] + 30) {
                // release the lock
                $sql = "UPDATE `config` SET `val`='NO' WHERE `key`='SELECT_RUNNING' ";
                $result = @mysql_query($sql) or die(mysql_error());
                // update timestamp
                $sql = "REPLACE INTO config (`key`, `val`) VALUES ('LAST_SELECT_RUN', '{$unix_time}')  ";
                $result = @mysql_query($sql) or die(mysql_error());
            }
            usleep(5000000);
            // this function is executing in another process. sleep for half a second
            check_selection_main();
            return;
        }
    }
    ####################################################
    $upload_image_file = get_tmp_img_name();
    $size = getimagesize($upload_image_file);
    $new_size = get_required_size($size[0], $size[1]);
    $block_id = $_REQUEST['block_id'];
    //print_r($_REQUEST);
    // get width and height of uploaded image
    //echo "[".$size[0]." ".$size[1]."] ";
    //echo $block_id;
    if (function_exists("imagecreatetruecolor")) {
        $dest = imagecreatetruecolor(BLK_WIDTH, BLK_HEIGHT);
        $whole_image = imagecreatetruecolor($new_size[0], $new_size[1]);
    } else {
        $dest = imagecreate(BLK_WIDTH, BLK_HEIGHT);
        $whole_image = imagecreate($new_size[0], $new_size[1]);
    }
    $parts = split('\\.', $upload_image_file);
    $ext = strtolower(array_pop($parts));
    //echo $ext."($upload_image_file)\n";
    switch ($ext) {
        case 'jpeg':
        case 'jpg':
            $upload_image = imagecreatefromjpeg($upload_image_file);
            break;
        case 'gif':
            $upload_image = imagecreatefromgif($upload_image_file);
            break;
        case 'png':
            $upload_image = imagecreatefrompng($upload_image_file);
            break;
    }
    // create the requ
    //$imagebg = imageCreateFromPNG (SERVER_PATH_TO_ADMIN.'temp/block.png'); // transparent PNG
    //echo GRID_BLOCK;
    $imagebg = imageCreateFromstring(GRID_BLOCK);
    imageSetTile($whole_image, $imagebg);
    imageFilledRectangle($whole_image, 0, 0, $new_size[0], $new_size[1], IMG_COLOR_TILED);
    imagecopy($whole_image, $upload_image, 0, 0, 0, 0, $size[0], $size[1]);
    //imagepng($whole_image);
    for ($i = 0; $i < $size[1]; $i += BLK_HEIGHT) {
        for ($j = 0; $j < $size[0]; $j += BLK_WIDTH) {
            $map_x = $j + $_REQUEST['map_x'];
            $map_y = $i + $_REQUEST['map_y'];
            $r_x = $map_x;
            $r_y = $map_y;
            //echo "map_x: $map_x map_y: $map_y \n";
            $GRD_WIDTH = BLK_WIDTH * G_WIDTH;
            $cb = $map_x / BLK_WIDTH + $map_y / BLK_HEIGHT * ($GRD_WIDTH / BLK_WIDTH);
            $in_str = $in_str . "{$comma}{$cb}";
            $comma = ',';
            $block_info[$cb]['map_x'] = $map_x;
            $block_info[$cb]['map_y'] = $map_y;
            // bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )
            imagecopy($dest, $whole_image, 0, 0, $j, $i, BLK_WIDTH, BLK_HEIGHT);
            //echo "imagecopy ( $dest, $whole_image, 0, 0, $j, $i, ".BLK_HEIGHT.", '".BLK_WIDTH."' );";
            ob_start();
            imagepng($dest);
            $data = ob_get_contents();
            ob_end_clean();
            $data = base64_encode($data);
            $block_info[$cb]['image_data'] = $data;
        }
    }
    //
    imagedestroy($dest);
    imagedestroy($upload_image);
    //print_r ($block_info);
    // create a temporary order and place the blocks on a temp order
    place_temp_order($in_str, $price);
    //echo "in_str is:".$in_str;
    reserve_temp_order_pixels($block_info, $in_str);
    ###################################################
    if (USE_LOCK_TABLES == 'Y') {
        $sql = "UNLOCK TABLES";
        $result = mysql_query($sql) or die(mysql_error() . " <b>Dear Webmaster: The current MySQL user set in config.php does not have permission to lock tables. Please give this user permission to lock tables, or set USE_LOCK_TABLES to N in the config.php file that comes with this script.<b>");
    } else {
        // release the poor man's lock
        $sql = "UPDATE `config` SET `val`='NO' WHERE `key`='SELECT_RUNNING' ";
        mysql_query($sql);
        $unix_time = time();
        // update timestamp
        $sql = "REPLACE INTO config (`key`, `val`) VALUES ('LAST_SELECT_RUN', '{$unix_time}')  ";
        $result = @mysql_query($sql) or die(mysql_error());
    }
    ####################################################
}
if (file_exists($filename)) {
    $handle = fopen($filename, 'r');
    $contents = fread($handle, filesize($filename));
    $size = getimagesize($filename);
    fclose($handle);
    $image = imagecreatefromstring($contents);
} else {
    $image = imagecreatefrompng('pointer.png');
    $size = getimagesize('pointer.png');
}
$new_size = get_required_size($size[0], $size[1]);
$out = imagecreatetruecolor($new_size[0], $new_size[1]);
$imagebg = imageCreateFromPNG('block.png');
// tile filler
imageSetTile($out, $imagebg);
imageFilledRectangle($out, 0, 0, $new_size[0], $new_size[1], IMG_COLOR_TILED);
imagecopy($out, $image, 0, 0, 0, 0, $size[0], $size[1]);
if (MDS_RESIZE == 'YES') {
    // make it smaller
    $newsize_img = imagecreate($new_size[0], $new_size[1]);
    imagecopyresampled($newsize_img, $image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
    imagecopy($out, $newsize_img, 0, 0, 0, 0, $new_size[0], $new_size[1]);
}
//);
//imagestring ($out, 2, 10, 10, 'hello'.$new_size[0]." - ".$new_size[1], 0 );
//imagedestroy($image);
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header("Content-type: image/x-png");
Example #21
0
			*/
				$xprec="";
				$yprec="";
				$temoin_prec="";

				// On place les points
				$tab_x=array();
				$tab_y=array();
				for($i=1;$i<$nbMat+1;$i++){
					//if(($moyenne[$k][$i]!="")&&($moyenne[$k][$i]!="-")&&($moyenne[$k][$i]!="N.NOT")&&($moyenne[$k][$i]!="ABS")&&($moyenne[$k][$i]!="DIS")){
					if(($moyenne[$k][$i]!="")&&($moyenne[$k][$i]!="-")&&(preg_match("/^[0-9]{1,}/", $moyenne[$k][$i]))) {

						$angle=round(($i-1)*360/$nbMat);
						$tab=coordcirc($moyenne[$k][$i],$angle);

						imageFilledRectangle($img,$tab[0]-2,$tab[1]-2,$tab[0]+2,$tab[1]+2,$couleureleve[$k]);

						$tab_x[]=$tab[0];
						$tab_y[]=$tab[1];
					}
					else{
						$tab_x[]="";
						$tab_y[]="";
					}
				}


				// On joint ces points
				$xprec="";
				$yprec="";
				for($i=0;$i<count($tab_x);$i++){
Example #22
0
 /**
  * Draws a rectangle with rounded corners on the image
  * @param Point $leftTop Point of the upper left corner
  * @param Dimension $dimension Dimension of the rectangle
  * @param integer $cornerSize The number of pixels which should be round of
  * @param Color $color
  * @param integer $width
  * @return null
  */
 public function fillRoundedRectangle(Point $leftTop, Dimension $dimension, $cornerSize, $color)
 {
     $color = $this->allocateColor($color);
     $x = $leftTop->getX();
     $y = $leftTop->getY();
     $width = $dimension->getWidth();
     $height = $dimension->getHeight();
     $cornerWidth = $cornerSize * 2;
     $innerWidth = $width - $cornerWidth;
     $innerHeight = $height - $cornerWidth;
     // left top
     imageFilledArc($this->resource, $x + $cornerSize, $y + $cornerSize, $cornerWidth, $cornerWidth, 180, 270, $color, IMG_ARC_PIE);
     // top
     imageFilledRectangle($this->resource, $x + $cornerSize, $y, $x + $width - $cornerSize, $y + $cornerSize, $color);
     // right top
     imageFilledArc($this->resource, $x + $width - $cornerSize, $y + $cornerSize, $cornerWidth, $cornerWidth, 270, 360, $color, IMG_ARC_PIE);
     // center
     imageFilledRectangle($this->resource, $x, $y + $cornerSize, $x + $width, $y + $height - $cornerSize, $color);
     // left down
     imageFilledArc($this->resource, $x + $cornerSize, $y + $height - $cornerSize, $cornerWidth, $cornerWidth, 90, 180, $color, IMG_ARC_PIE);
     // down
     imageFilledRectangle($this->resource, $x + $cornerSize, $y + $height - $cornerSize, $x + $width - $cornerSize, $y + $height, $color);
     // right down
     imageFilledArc($this->resource, $x + $width - $cornerSize, $y + $height - $cornerSize, $cornerWidth, $cornerWidth, 0, 90, $color, IMG_ARC_PIE);
 }
Example #23
0
 case 'rectangle':
     if (!$params) {
         break;
     }
     $check_size_allowed($params);
     if (!preg_match('/^[0-9]+x[0-9]+x[0-9]+x[0-9]+x[0-9a-f]{6}$/i', $params)) {
         if (!Settings::isProductionState()) {
             exit('Error processing params for action "rectangle". Example: 32x32x64x64xff00cc');
         }
         die;
     }
     list($x1, $y1, $x2, $y2, $c) = explode('x', $params);
     $image->apply();
     $ih = $image->getHandler();
     $c = imageColorAllocate($ih, hexdec($c[0] . $c[1]), hexdec($c[2] . $c[3]), hexdec($c[4] . $c[5]));
     imageFilledRectangle($ih, $x1, $y1, $x2, $y2, $c);
     unset($ih);
     break;
 case 'roundaa':
     if (!$params) {
         break;
     }
     $check_size_allowed($params);
     if (!preg_match('/^[0-9]+x[0-9a-f]{6}x[0-9]{1}$/i', $params)) {
         if (!Settings::isProductionState()) {
             exit('Error processing params for action "roundaa". Example: 7xff00ccx4');
         }
         die;
     }
     list($r, $c, $aa) = explode('x', $params);
     $image->roundedCorners($r, $c, $aa);
Example #24
0
<?php

$dest = dirname(realpath(__FILE__)) . '/bug22544.png';
@unlink($dest);
$image = imageCreateTruecolor(640, 100);
$transparent = imageColorAllocate($image, 0, 0, 0);
$red = imageColorAllocate($image, 255, 50, 50);
imageColorTransparent($image, $transparent);
imageFilledRectangle($image, 0, 0, 640 - 1, 100 - 1, $transparent);
imagePng($image, $dest);
echo md5_file($dest) . "\n";
@unlink($dest);
Example #25
0
function legend($im, $sz, $C)
{
    $r = 30;
    $fn = 5;
    $x = $sz - (4 * $r + 7) - 2;
    $y = $sz - $r - 3;
    imageFilledRectangle($im, $x, $y, $x + 4 * $r + 7, $y + $r + 1, $C['dkgray']);
    imageRectangle($im, $x + 0 * $r + 1, $y + 1, $x + 1 * $r + 0, $y + $r, $C['red']);
    imageRectangle($im, $x + 1 * $r + 2, $y + 1, $x + 2 * $r + 2, $y + $r, $C['yellow']);
    imageRectangle($im, $x + 2 * $r + 4, $y + 1, $x + 3 * $r + 4, $y + $r, $C['darkgreen']);
    imageRectangle($im, $x + 4 * $r + 6, $y + 1, $x + 3 * $r + 6, $y + $r, $C['brightgreen']);
    imageString($im, $fn, $x + 3 + 0 * $r, $y + $r / 3, "<30", $C['red']);
    imageString($im, $fn, $x + 5 + 1 * $r, $y + $r / 3, "30+", $C['yellow']);
    imageString($im, $fn, $x + 7 + 2 * $r, $y + $r / 3, "35+", $C['darkgreen']);
    imageString($im, $fn, $x + 9 + 3 * $r, $y + $r / 3, "40+", $C['brightgreen']);
}
Example #26
0
 //echo $ext."($upload_image_file)\n";
 switch (strtolower($ext)) {
     case 'jpeg':
     case 'jpg':
         $upload_image = imagecreatefromjpeg($tmp_image_file);
         break;
     case 'gif':
         $upload_image = imagecreatefromgif($tmp_image_file);
         break;
     case 'png':
         $upload_image = imagecreatefrompng($tmp_image_file);
         break;
 }
 $imagebg = imageCreateFromstring(GRID_BLOCK);
 imageSetTile($whole_image, $imagebg);
 imageFilledRectangle($whole_image, 0, 0, $size['x'], $size['y'], IMG_COLOR_TILED);
 imagecopy($whole_image, $upload_image, 0, 0, 0, 0, $img_size[0], $img_size[1]);
 //imagepng($whole_image);
 for ($i = 0; $i < $size['y']; $i += BLK_HEIGHT) {
     for ($j = 0; $j < $size['x']; $j += BLK_WIDTH) {
         $map_x = $j + $low_x;
         $map_y = $i + $low_y;
         $r_x = $map_x;
         $r_y = $map_y;
         $GRD_WIDTH = BLK_WIDTH * G_WIDTH;
         $cb = $map_x / BLK_WIDTH + $map_y / BLK_HEIGHT * ($GRD_WIDTH / BLK_WIDTH);
         // bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )
         imagecopy($dest, $whole_image, 0, 0, $j, $i, BLK_WIDTH, BLK_HEIGHT);
         ob_start();
         imagepng($dest);
         $data = ob_get_contents();
Example #27
0
$height = "25";
//图片高
$len = "4";
//生成几位验证码
$bgcolor = "#ffffff";
//背景色
$noise = true;
//生成杂点
$noisenum = 200;
//杂点数量
$border = false;
//边框
$bordercolor = "#000000";
$image = imageCreate($width, $height);
$back = getcolor($bgcolor);
imageFilledRectangle($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 = rand(0, 9);
    $code .= $randtext;
    $textColor = imageColorAllocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
    $font = rand(1, 4) . ".ttf";
    $randsize = rand($size - $size / 10, $size + $size / 10);
    $location = $left + ($i * $size + $size / 10);
    imagettftext($image, $randsize, rand(-18, 18), $location, rand($size - $size / 10, $size + $size / 10), $textColor, $font, $randtext);
}
if ($noise == true) {
Example #28
0
 /**
  * Function: drawActor
  *
  * Draws then given cloud.
  */
 function drawActor($x, $y, $w, $h, $fill = null, $stroke = null, $shadow = false)
 {
     if (isset($fill)) {
         if ($shadow) {
             $dx = mxConstants::$SHADOW_OFFSETX;
             $dy = mxConstants::$SHADOW_OFFSETY;
             imageFilledEllipse($this->image, $x + 0.5 * $w + $dx, $y + 0.2 * $h + $dy, 0.4 * $w, 0.4 * $h, $this->shadowColor);
             imageFilledEllipse($this->image, $x + 0.2 * $w + $dx, $y + 0.6 * $h + $dy, 0.4 * $w, 0.4 * $h, $this->shadowColor);
             imageFilledEllipse($this->image, $x + 0.8 * $w + $dx, $y + 0.6 * $h + $dy, 0.4 * $w, 0.4 * $h, $this->shadowColor);
             imageFilledRectangle($this->image, $x + 0.2 * $w + $dx, $y + 0.4 * $h + $dy, $x + 0.8 * $w + $dx, $y + 0.6 * $h + $dy, $this->shadowColor);
             imageFilledRectangle($this->image, $x + $dx, $y + 0.6 * $h + $dy, $x + $w + $dx, $y + $h + $dy, $this->shadowColor);
         }
         $fill = $this->getColor($fill);
         imageFilledEllipse($this->image, $x + 0.5 * $w, $y + 0.2 * $h, 0.4 * $w, 0.4 * $h, $fill);
         imageFilledEllipse($this->image, $x + 0.2 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, $fill);
         imageFilledEllipse($this->image, $x + 0.8 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, $fill);
         imageFilledRectangle($this->image, $x + 0.2 * $w, $y + 0.4 * $h, $x + 0.8 * $w, $y + 0.6 * $h, $fill);
         imageFilledRectangle($this->image, $x, $y + 0.6 * $h, $x + $w, $y + $h, $fill);
     }
     if ($stroke != null) {
         $stroke = $this->getColor($stroke);
         imageEllipse($this->image, $x + 0.5 * $w, $y + 0.2 * $h, 0.4 * $w, 0.4 * $h, $stroke);
         imageLine($this->image, $x + 0.2 * $w, $y + 0.4 * $h, $x + 0.8 * $w, $y + 0.4 * $h, $stroke);
         imageArc($this->image, $x + 0.2 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, 180, 270, $stroke);
         imageArc($this->image, $x + 0.8 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, 270, 360, $stroke);
         imageLine($this->image, $x, $y + 0.6 * $h, $x, $y + $h, $stroke);
         imageLine($this->image, $x, $y + $h, $x + $w, $y + $h, $stroke);
         imageLine($this->image, $x + $w, $y + $h, $x + $w, $y + 0.6 * $h, $stroke);
     }
 }
Example #29
0
 public function make_img()
 {
     $this->image = imageCreate($this->width, $this->height);
     //创建图片
     $this->backcolorRGB = $this->getcolor($this->backcolor);
     //将#ffffff格式的背景色转换成RGB格式
     imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->backcolorRGB);
     //画一矩形 并填充
     $this->size = $this->width / $this->len;
     //宽度除以字符数 = 每个字符需要的宽度
     if ($this->size > $this->height) {
         $this->size = $this->height;
     }
     //如果 每个字符需要的宽度 大于图片高度 则 单字符宽度=高度(正方块)
     $this->sizestr2str = $this->size / 10;
     //以每个字符的1/10宽度为 字符间距
     $left = ($this->width - $this->len * ($this->size + $this->sizestr2str)) / $this->size;
     // (验证码图片宽度 - 实际需要的宽度)/每个字符的宽度 = 距离左边的宽度
     for ($i = 0; $i < 3; $i++) {
         //生成干扰线
         $linecolor = imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
         imageline($this->image, rand(0, 30), rand(0, 30), rand(30, 80), rand(0, 30), $linecolor);
     }
     $text = '';
     for ($i = 0; $i < $this->len; $i++) {
         $randtext = rand(0, 9);
         //验证码数字 0-9随机数
         $text .= $randtext;
         //写入session的数字
         $textColor = imageColorAllocate($this->image, rand(50, 155), rand(50, 155), rand(50, 155));
         //图片文字颜色
         if (!isset($this->textsize)) {
             $this->textsize = rand($this->size - $this->size / 10, $this->size + $this->size / 10);
         }
         //如果未定义字体大小 则取随机大小
         $location = $left + ($i * $this->size + $this->size / 10);
         imagettftext($this->image, $this->textsize, rand(-18, 18), $location, rand($this->size - $this->size / 10, $this->size + $this->size / 10), $textColor, $this->font, $randtext);
         //生成单个字体图象
     }
     if (isset($this->noisenum)) {
         $this->setnoise();
     }
     //杂点处理
     if (isset($this->bordercolor)) {
         $this->bordercolorRGB = $this->getcolor($this->bordercolor);
         imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->bordercolorRGB);
     }
     return $text;
 }
Example #30
0
$disp_height = $height;
$height *= $multiplier;
$height += $top_margin + $bottom_margin;
if ($height < 18) {
    $height = 18;
}
$segment_size = ($width - $left_margin - $right_margin) / (($date - $start_date) / 86400 - 1);
/* height = max of sum of projects+tasks+comments for each day + margins */
$image = imageCreate($width, $height);
$color_background = imageColorAllocate($image, 255, 255, 255);
$color_projects = imageColorAllocate($image, 0, 0, 255);
$color_tasks = imageColorAllocate($image, 0, 128, 0);
$color_comments = imageColorAllocate($image, 255, 0, 0);
$color_foreground = imageColorAllocate($image, 0, 0, 0);
/* fill background */
imageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $colors_background);
imagecolortransparent($image, $color_background);
$projects_points = array(0 => $left_margin, 1 => $height - $bottom_margin - 1);
$tasks_points = array(0 => $left_margin, 1 => $height - $bottom_margin - 1);
$comments_points = array(0 => $left_margin, 1 => $height - $bottom_margin - 1);
$count = 2;
$x_pos = $left_margin;
for ($date = $start_date; $date < time(); $date += 86400) {
    $projects_points[$count] = $x_pos;
    $tasks_points[$count] = $x_pos;
    $comments_points[$count] = $x_pos;
    $x_pos += $segment_size;
    $count++;
    $y_pos = $height - $bottom_margin - 1 - $projects["new"][$id][date("Y-m-d", $date)] * $multiplier;
    $projects_points[$count] = $y_pos;
    $y_pos -= $tasks["new"][$id][date("Y-m-d", $date)] * $multiplier;