Esempio n. 1
1
 public function getAvatar($string, $widthHeight = 12, $theme = 'default')
 {
     $widthHeight = max($widthHeight, 12);
     $md5 = md5($string);
     $fileName = _TMP_DIR_ . '/' . $md5 . '.png';
     if ($this->tmpFileExists($fileName)) {
         return $fileName;
     }
     // Create seed.
     $seed = intval(substr($md5, 0, 6), 16);
     mt_srand($seed);
     $body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
     // Avatar random parts.
     $parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
     $avatar = imagecreate($widthHeight, $widthHeight);
     imagesavealpha($avatar, true);
     imagealphablending($avatar, false);
     $background = imagecolorallocate($avatar, 0, 0, 0);
     $line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
     imagecolortransparent($avatar, $background);
     imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
     // Fill avatar with random parts.
     foreach ($parts as &$part) {
         $this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
     }
     imagepng($avatar, $fileName);
     imagecolordeallocate($avatar, $line_colour);
     imagecolordeallocate($avatar, $background);
     imagedestroy($avatar);
     return $fileName;
 }
Esempio n. 2
0
 public function executeGetLabel()
 {
     $student = StudentPeer::retrieveByPK($this->getRequestParameter('id'));
     $this->forward404Unless($student);
     $this->student = $student;
     define('IMG_FORMAT_PNG', 1);
     define('IMG_FORMAT_JPEG', 2);
     define('IMG_FORMAT_WBMP', 4);
     define('IMG_FORMAT_GIF', 8);
     require 'FColor.php';
     require 'BarCode.php';
     require 'FDrawing.php';
     include 'code128.barcode.php';
     $color_black = new FColor(0, 0, 0);
     $color_white = new FColor(255, 255, 255);
     $code_generated = new code128(32, $color_black, $color_white, 1, $student->getCode(), 3);
     $drawing = new FDrawing(1024, 1024, '', $color_white);
     $drawing->init();
     $drawing->add_barcode($code_generated);
     $drawing->draw_all();
     $im = $drawing->get_im();
     #$im2 = imagecreate($code_generated->lastX,$code_generated->lastY);
     $im2 = imagecreate(300, 100);
     imagecopyresized($im2, $im, 0, 0, 0, 0, 300, 100, 300, 100);
     ##imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY);
     $drawing->set_im($im2);
     $drawing->finish(IMG_FORMAT_PNG);
 }
Esempio n. 3
0
 /**
  * Return captcha image
  * @param number $maxChar
  */
 public function generate($maxChar = 4)
 {
     // $characters = '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
     $characters = 'ABCDEFGHKMNPQRST';
     $captchaText = '';
     for ($i = 0; $i < $maxChar; $i++) {
         $captchaText .= $characters[rand(0, strlen($characters) - 1)];
     }
     strtoupper(substr(md5(microtime()), 0, 7));
     \Session::put('captchaHash', \Hash::make($captchaText));
     $image = imagecreate(30 * $maxChar, 35);
     $background = imagecolorallocatealpha($image, 255, 255, 255, 1);
     $textColor = imagecolorallocatealpha($image, 206, 33, 39, 1);
     $x = 5;
     $y = 20;
     $angle = 0;
     for ($i = 0; $i < 7; $i++) {
         $fontSize = 16;
         $text = substr($captchaText, $i, 1);
         imagettftext($image, $fontSize, $angle, $x, $y, $textColor, public_path('/fonts/LibreBaskerville/librebaskerville-regular.ttf'), $text);
         $x = $x + 17 + mt_rand(1, 10);
         $y = mt_rand(18, 25);
         $angle = mt_rand(0, 20);
     }
     header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
     header('Pragma: no-cache');
     header('Content-type: image/jpeg');
     imagejpeg($image, null, 100);
     imagedestroy($image);
 }
Esempio n. 4
0
function getCode($num, $w, $h)
{
    // 去掉了 0 1 O l 等
    $str = "23456789abcdefghijkmnpqrstuvwxyz";
    $code = '';
    for ($i = 0; $i < $num; $i++) {
        $code .= $str[mt_rand(0, strlen($str) - 1)];
    }
    //将生成的验证码写入session,备验证页面使用
    $_SESSION["my_checkcode"] = $code;
    //创建图片,定义颜色值
    Header("Content-type: image/PNG");
    $im = imagecreate($w, $h);
    $black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
    $gray = imagecolorallocate($im, 118, 151, 199);
    $bgcolor = imagecolorallocate($im, 235, 236, 237);
    //画背景
    imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
    //画边框
    imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
    //imagefill($im, 0, 0, $bgcolor);
    //在画布上随机生成大量点,起干扰作用;
    for ($i = 0; $i < 80; $i++) {
        imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
    }
    //将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
    $strx = rand(5, 10);
    for ($i = 0; $i < $num; $i++) {
        $strpos = rand(1, 6);
        imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
        $strx += $w / 5;
    }
    imagepng($im);
    imagedestroy($im);
}
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files")
{
    // Größe und Typ ermitteln
    list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src);
    if (!$src_typ) {
        return false;
    }
    // calculate new size
    if ($src_width >= $src_height) {
        $new_image_height = $src_height / $src_width * $img_width;
        $new_image_width = $img_width;
        if ($new_image_height > $img_height) {
            $new_image_width = $new_image_width / $new_image_height * $img_height;
            $new_image_height = $img_height;
        }
    } else {
        $new_image_width = $src_width / $src_height * $img_height;
        $new_image_height = $img_height;
        if ($new_image_width > $img_width) {
            $new_image_height = $new_image_height / $new_image_width * $img_width;
            $new_image_width = $img_width;
        }
    }
    // for the case that the thumbnail would be bigger then the original picture
    if ($new_image_height > $src_height) {
        $new_image_width = $new_image_width * $src_height / $new_image_height;
        $new_image_height = $src_height;
    }
    if ($new_image_width > $src_width) {
        $new_image_height = $new_image_height * $new_image_width / $src_width;
        $new_image_width = $src_width;
    }
    if ($src_typ == 1) {
        $image = imagecreatefromgif($folder_scr . "/" . $img_src);
        $new_image = imagecreate($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 2) {
        $image = imagecreatefromjpeg($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 3) {
        $image = imagecreatefrompng($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagepng($new_image, $des_src . "/" . $img_src . "_thumb");
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } else {
        return false;
    }
}
Esempio n. 6
0
 public function index()
 {
     $code = substr(sha1(mt_rand()), 17, 6);
     $this->session->set_userdata('captcha_code', $code);
     $width = '120';
     $height = '40';
     $font = APPPATH . 'modules/contact/assets/fonts/monofont.ttf';
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
Esempio n. 7
0
function graph_error($string)
{
    global $vars, $config, $debug, $graphfile;
    $vars['bg'] = 'FFBBBB';
    include 'includes/graphs/common.inc.php';
    $rrd_options .= ' HRULE:0#555555';
    $rrd_options .= " --title='" . $string . "'";
    rrdtool_graph($graphfile, $rrd_options);
    if ($height > '99') {
        shell_exec($rrd_cmd);
        d_echo('<pre>' . $rrd_cmd . '</pre>');
        if (is_file($graphfile) && !$debug) {
            header('Content-type: image/png');
            $fd = fopen($graphfile, 'r');
            fpassthru($fd);
            fclose($fd);
            unlink($graphfile);
            exit;
        }
    } else {
        if (!$debug) {
            header('Content-type: image/png');
        }
        $im = imagecreate($width, $height);
        $px = (imagesx($im) - 7.5 * strlen($string)) / 2;
        imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0));
        imagepng($im);
        imagedestroy($im);
        exit;
    }
}
function generateAvatarGD($gdversion, $src_img, $srcWidth, $srcHeight, $dstWidth, $dstHeight, $quality, $location)
{
    if ($srcWidth > $dstWidth || $srcHeight > $dstHeight) {
        $ratio = $srcWidth / $srcHeight;
        if ($dstWidth / $dstHeight > $ratio) {
            $dstWidth = $dstHeight * $ratio;
        } else {
            $dstHeight = $dstWidth / $ratio;
        }
    } else {
        $dstWidth = $srcWidth;
        $dstHeight = $srcHeight;
    }
    if ((int) $gdversion == 1) {
        $dst_img = imagecreate($dstWidth, $dstHeight);
        imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight);
    } else {
        $dst_img = imagecreatetruecolor($dstWidth, $dstHeight);
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight);
    }
    $tmpfile = tempnam(CKunenaPath::tmpdir(), "kn_");
    imagejpeg($dst_img, $tmpfile, $quality);
    CKunenaFile::copy($tmpfile, $location);
    unlink($tmpfile);
    imagedestroy($dst_img);
}
Esempio n. 9
0
 public function __construct($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     /* @var $CI My_Controller */
     $CI = get_instance();
     $CI->session->set_userdata('security_code', $code);
 }
Esempio n. 10
0
function imgcode($nums, $width, $high)
{
    //去除了數字0和1 字母小寫O和L,為了避免辨識不清楚
    //$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMOPQRSTUBWXYZ";
    $str = "0123456789";
    $code = '';
    for ($i = 0; $i < $nums; $i++) {
        $code .= $str[mt_rand(0, strlen($str) - 1)];
    }
    $_SESSION['captcha'] = $code;
    //建立圖示,設置寬度及高度與顏色等等條件
    $image = imagecreate($width, $high);
    $black = imagecolorallocate($image, mt_rand(0, 200), mt_rand(0, 200), mt_rand(0, 200));
    $border_color = imagecolorallocate($image, 21, 106, 235);
    $background_color = imagecolorallocate($image, 235, 236, 237);
    //建立圖示背景
    imagefilledrectangle($image, 0, 0, $width, $high, $background_color);
    //建立圖示邊框
    imagerectangle($image, 0, 0, $width - 1, $high - 1, $border_color);
    //在圖示布上隨機產生大量躁點
    for ($i = 0; $i < 80; $i++) {
        imagesetpixel($image, rand(0, $width), rand(0, $high), $black);
    }
    $strx = rand(3, 8);
    for ($i = 0; $i < $nums; $i++) {
        $strpos = rand(1, 6);
        imagestring($image, 5, $strx, $strpos, substr($code, $i, 1), $black);
        $strx += rand(10, 30);
    }
    imagepng($image);
    imagedestroy($image);
}
 /**
  *  This is the class constructor for the YDGraphPie class.
  *
  *  @param  $width              (optional) the width of the graph in pixels
  *  @param  $height             (optional) the height of the graph in pixels
  *  @param  $margin             (optional) the margin to keep around the graph
  *  @param  $backgroundColor    (optional) the background color for the graph
  */
 function YDGraphPie($width = 400, $height = 300, $margin = 7, $backgroundColor = '#ffffff')
 {
     // Initialize the parent class
     $this->YDAddOnModule();
     // Setup the module
     $this->_author = "David Bittencourt";
     $this->_version = "1.3";
     $this->_copyright = "(c) 2005 David Bittencourt, muitocomplicado@hotmail.com";
     $this->_description = "This class implements a pie chart rendering utility";
     // Setup the defaults
     $this->m_title = "";
     $this->m_width = $width;
     $this->m_height = $height;
     $this->m_image = imagecreate($this->m_width, $this->m_height);
     $this->m_margin = $margin;
     $vBackColor = YDGraph::_decode_color($backgroundColor);
     $this->m_backgroundColor = imagecolorallocate($this->m_image, $vBackColor[0], $vBackColor[1], $vBackColor[2]);
     $this->m_strokeColor = imagecolorallocate($this->m_image, $vBackColor[0], $vBackColor[1], $vBackColor[2]);
     $this->m_fillColor = $this->m_backgroundColor;
     $this->m_numberOfDecimals = 0;
     $this->m_thousandsSeparator = ',';
     $this->m_decimalSeparator = '.';
     $this->m_showtotal = false;
     $this->m_total = null;
     $this->m_formattotal = true;
     $this->m_totalstring = 'Total: ';
 }
 function apply(lmbAbstractImageContainer $container)
 {
     list($x, $y, $width, $height) = $this->calculateCropArea($container->getWidth(), $container->getHeight());
     $im = $container->isPallete() ? imagecreate($width, $height) : imagecreatetruecolor($width, $height);
     imagecopy($im, $container->getResource(), 0, 0, $x, $y, $width, $height);
     $container->replaceResource($im);
 }
Esempio n. 13
0
 public static function blank($width, $height)
 {
     $handle = imagecreate($width, $height);
     $whiteColor = imagecolorallocate($handle, 0xff, 0xff, 0xff);
     $blackColor = imagecolorallocate($handle, 0x0, 0x0, 0x0);
     return new self($handle, $whiteColor, $blackColor);
 }
Esempio n. 14
0
 public static function getCode($width = 70, $height = 24, $len = 4)
 {
     self::init();
     header('content-type:image/png');
     $checkWord = '';
     $checkChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ1234567890';
     for ($num = 0; $num < $len; $num++) {
         $char = rand(0, strlen($checkChar) - 1);
         $checkWord .= $checkChar[$char];
     }
     $_SESSION['code'] = strtolower($checkWord);
     $image = imagecreate($width, $height);
     $font = FONTS_PATH . 'ariblk.ttf';
     $red = imagecolorallocate($image, 0xf3, 0x61, 0x61);
     $blue = imagecolorallocate($image, 0x53, 0x68, 0xbd);
     $green = imagecolorallocate($image, 0x6b, 0xc1, 0x46);
     $colors = array($red, $blue, $green);
     $gray = imagecolorallocate($image, 0xf5, 0xf5, 0xf5);
     imagefill($image, 0, 0, $gray);
     imageline($image, rand(0, 5), rand(6, 18), rand(65, 70), rand(6, 18), $colors[rand(0, 2)]);
     for ($num = 0; $num < $len; $num++) {
         imagettftext($image, rand(12, 16), (rand(0, 60) + 330) % 360, 5 + 15 * $num + rand(0, 4), 18 + rand(0, 4), $colors[rand(0, 2)], $font, $checkWord[$num]);
     }
     imagepng($image);
     imagedestroy($image);
 }
Esempio n. 15
0
function return_image($boolean)
{
    if (function_exists('imagecreate')) {
        $im = imagecreate(1, 1);
        if ($boolean) {
            imagecolorallocate($im, 0, 255, 0);
        } else {
            imagecolorallocate($im, 255, 0, 0);
        }
        header("Content-type: image/gif");
        imagegif($im);
        imagedestroy($im);
    } else {
        $grape_gif = '
        R0lGODlhIAAgALMAAAAAAAAAgHCAkC6LV76+vvXeswD/ANzc3DLNMubm+v/6zS9PT6Ai8P8A////
        /////yH5BAEAAAkALAAAAAAgACAAAAS00MlJq7046803AF3ofAYYfh8GIEvpoUZcmtOKAO5rLMva
        0rYVKqX5IEq3XDAZo1GGiOhw5rtJc09cVGo7orYwYtYo3d4+DBxJWuSCAQ30+vNTGcxnOIARj3eT
        YhJDQ3woDGl7foNiKBV7aYeEkHEignKFkk4ciYaImJqbkZ+PjZUjaJOElKanqJyRrJyZgSKkokOs
        NYa2q7mcirC5I5FofsK6hcHHgsSgx4a9yzXK0rrV19gRADs=
        ';
        $php_rules = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
        if ($boolean) {
            $data = base64_decode($grape_gif);
            header("Content-type: image/gif");
        } else {
            $data = base64_decode($php_rules);
            header("Content-type: image/png");
        }
        echo $data;
    }
}
Esempio n. 16
0
function resize_image_gd($src, $dest, $quality, $width, $height, $image_info)
{
    global $convert_options;
    $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
    if ($convert_options['convert_gd2']) {
        $thumb = imagecreatetruecolor($width, $height);
    } else {
        $thumb = imagecreate($width, $height);
    }
    $image_create_handle = "imagecreatefrom" . $types[$image_info[2]];
    if ($image = $image_create_handle($src)) {
        if ($convert_options['convert_gd2']) {
            imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
        } else {
            imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
        }
        if ($image_info[2] == 3) {
            $quality = 9;
        }
        $image_handle = "image" . $types[$image_info[2]];
        $image_handle($thumb, $dest, $quality);
        imagedestroy($image);
        imagedestroy($thumb);
    }
    return file_exists($dest) ? 1 : 0;
}
Esempio n. 17
0
 /**
  * Class constructor generates the CAPTCHA image.
  *
  * @return blob the image
  * @access public
  */
 function __construct()
 {
     session_start();
     $image = imagecreate($this->width, $this->height);
     $random_str = $this->gen_str($this->chars_nr);
     #md5( microtime() );						// md5 to generate the random string
     $result_str = substr($random_str, 0, $this->chars_nr);
     //trim $chars_nr digit
     $bg_color = imagecolorallocate($image, $this->background_color['red'], $this->background_color['green'], $this->background_color['blue']);
     // background color
     $tx_color = imagecolorallocate($image, $this->text_color['red'], $this->text_color['gree'], $this->text_color['blue']);
     // text color
     for ($i = 0; $i <= $this->lines; $i++) {
         $line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         //line color
         imageline($image, rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), $line_color);
         // Create lines on image
     }
     imagestring($image, 5, 20, 10, $result_str, $tx_color);
     // Draw a random string horizontally
     $_SESSION['key'] = $result_str;
     // Carry the data through session
     header("Content-type: image/png");
     // Out out the image
     imagepng($image);
     // Output image to browser
 }
Esempio n. 18
0
function captcha($width, $height, $code)
{
    $font = "./font/ChalkboardBold.ttf";
    $font_size = 17;
    $image = imagecreate($width, $height);
    $background_color = imagecolorallocate($image, 255, 255, 255);
    $text_color = imagecolorallocate($image, 20, 40, 100);
    $noise_color = imagecolorallocate($image, 100, 120, 180);
    for ($i = 0; $i < $width * $height / 3; $i++) {
        imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
    }
    for ($i = 0; $i < $width * $height / 150; $i++) {
        imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
    }
    $x = 3;
    $y = 20;
    imagettftext($image, $font_size, rand(-45, 45), $x, $y + rand() % 16, $text_color, $font, $code[0]);
    imagettftext($image, $font_size, rand(-45, 45), $x + 23, $y + rand() % 16, $text_color, $font, $code[1]);
    imagettftext($image, $font_size, rand(-45, 45), $x + 46, $y + rand() % 16, $text_color, $font, $code[2]);
    imagettftext($image, $font_size, rand(-45, 45), $x + 69, $y + rand() % 16, $text_color, $font, $code[3]);
    imagettftext($image, $font_size, rand(-45, 45), $x + 92, $y + rand() % 16, $text_color, $font, $code[4]);
    imagettftext($image, $font_size, rand(-45, 45), $x + 115, $y + rand() % 16, $text_color, $font, $code[5]);
    header('Content-Type: image/jpeg');
    imagejpeg($image);
    imagedestroy($image);
}
Esempio n. 19
0
 /**
  * Automatically resizes an image and returns formatted IMG tag
  *
  * @param string $path Path to the image file, relative to the webroot/img/ directory.
  * @param integer $width Image of returned image
  * @param integer $height Height of returned image
  * @param boolean $aspect Maintain aspect ratio (default: true)
  * @param array	$htmlAttributes Array of HTML attributes.
  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
  * @return mixed	Either string or echos the value, depends on AUTO_OUTPUT and $return.
  * @access public
  */
 public function resize($path, $width, $height, $aspect = true, $htmlAttributes = array(), $return = false)
 {
     $types = array(1 => "gif", "jpeg", "png", "swf", "psd", "wbmp");
     // used to determine image type
     if (empty($htmlAttributes['alt'])) {
         $htmlAttributes['alt'] = 'thumb';
     }
     // Ponemos alt default
     $uploadsDir = 'uploads';
     $fullpath = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $uploadsDir . DS;
     $url = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $path;
     if (!($size = getimagesize($url))) {
         return;
     }
     // image doesn't exist
     if ($aspect) {
         // adjust to aspect.
         if ($size[1] / $height > $size[0] / $width) {
             // $size[0]:width, [1]:height, [2]:type
             $width = ceil($size[0] / $size[1] * $height);
         } else {
             $height = ceil($width / ($size[0] / $size[1]));
         }
     }
     $relfile = $this->webroot . $uploadsDir . '/' . $this->cacheDir . '/' . $width . 'x' . $height . '_' . basename($path);
     // relative file
     $cachefile = $fullpath . $this->cacheDir . DS . $width . 'x' . $height . '_' . basename($path);
     // location on server
     if (file_exists($cachefile)) {
         $csize = getimagesize($cachefile);
         $cached = $csize[0] == $width && $csize[1] == $height;
         // image is cached
         if (@filemtime($cachefile) < @filemtime($url)) {
             // check if up to date
             $cached = false;
         }
     } else {
         $cached = false;
     }
     if (!$cached) {
         $resize = $size[0] > $width || $size[1] > $height || ($size[0] < $width || $size[1] < $height);
     } else {
         $resize = false;
     }
     if ($resize) {
         $image = call_user_func('imagecreatefrom' . $types[$size[2]], $url);
         if (function_exists("imagecreatetruecolor") && ($temp = imagecreatetruecolor($width, $height))) {
             imagecopyresampled($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         } else {
             $temp = imagecreate($width, $height);
             imagecopyresized($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         }
         call_user_func("image" . $types[$size[2]], $temp, $cachefile);
         imagedestroy($image);
         imagedestroy($temp);
     } else {
         //copy($url, $cachefile);
     }
     return $this->output(sprintf($this->Html->tags['image'], $relfile, $this->Html->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
 }
Esempio n. 20
0
 /**
  * GImage constructor.
  *
  * @param integer $width
  * @param integer $height
  */
 function GImage($width = 800, $height = 600)
 {
     $this->_width = $width;
     $this->_height = $height;
     $this->_image = imagecreate($width, $height);
     $this->setColor(255, 255, 255);
 }
function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
Esempio n. 22
0
 /**
  * Create the image.
  *
  * The Height is 60 times the scale and the width is simply 
  * 180% of the height.
  */
 protected function _createImage()
 {
     $this->_height = $this->scale * 60;
     $this->_width = 1.8 * $this->_height;
     $this->_image = imagecreate($this->_width, $this->_height);
     $bg_color = ImageColorAllocate($this->_image, 0xff, 0xff, 0xff);
 }
Esempio n. 23
0
/**
 * Generate a cached thumbnail for object lists (eg. carrier, order states...etc)
 *
 * @param string $image Real image filename
 * @param string $cacheImage Cached filename
 * @param integer $size Desired size
 */
function cacheImage($image, $cacheImage, $size, $imageType = 'jpg')
{
    if (file_exists($image)) {
        if (!file_exists(_PS_TMP_IMG_DIR_ . $cacheImage)) {
            $imageGd = $imageType == 'gif' ? imagecreatefromgif($image) : imagecreatefromjpeg($image);
            $x = imagesx($imageGd);
            $y = imagesy($imageGd);
            /* Size is already ok */
            if ($y < $size) {
                copy($image, _PS_TMP_IMG_DIR_ . $cacheImage);
            } else {
                $ratioX = $x / ($y / $size);
                $newImage = $imageType == 'gif' ? imagecreate($ratioX, $size) : imagecreatetruecolor($ratioX, $size);
                /* Allow to keep nice look even if resized */
                $white = imagecolorallocate($newImage, 255, 255, 255);
                imagefill($newImage, 0, 0, $white);
                imagecopyresampled($newImage, $imageGd, 0, 0, 0, 0, $ratioX, $size, $x, $y);
                imagecolortransparent($newImage, $white);
                /* Quality alteration and image creation */
                if ($imageType == 'gif') {
                    imagegif($newImage, _PS_TMP_IMG_DIR_ . $cacheImage);
                } else {
                    imagejpeg($newImage, _PS_TMP_IMG_DIR_ . $cacheImage, 86);
                }
            }
        }
        return '<img src="../img/tmp/' . $cacheImage . '" alt="" class="imgm" />';
    }
    return '';
}
Esempio n. 24
0
function smart_spam($code)
{
    @putenv('GDFONTPATH=' . realpath('.'));
    $font = 'FONT.TTF';
    // antispam image height
    $height = 40;
    // antispam image width
    $width = 110;
    $font_size = $height * 0.6;
    $image = @imagecreate($width, $height);
    $background_color = @imagecolorallocate($image, 255, 255, 255);
    $noise_color = @imagecolorallocate($image, 20, 40, 100);
    /* add image noise */
    for ($i = 0; $i < $width * $height / 4; $i++) {
        @imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
    }
    /* render text */
    $text_color = @imagecolorallocate($image, 20, 40, 100);
    @imagettftext($image, $font_size, 0, 7, 29, $text_color, $font, $code) or die('Cannot render TTF text.');
    //output image to the browser *//*
    header('Content-Type: image/png');
    @imagepng($image) or die('imagepng error!');
    @imagedestroy($image);
    exit;
}
Esempio n. 25
0
/**
 * Resizes the given image resource to the specified size keeping the original
 * proportions of the image.
 *
 * @param resource $source
 * @param int $thumbWidth
 * @param int $thumbHeight
 *
 * @return resource
 */
function imageThumb($source, $thumbWidth = 0, $thumbHeight = 0)
{
    $srcWidth = imagesx($source);
    $srcHeight = imagesy($source);
    if ($srcWidth > $thumbWidth || $srcHeight > $thumbHeight) {
        if ($thumbWidth == 0) {
            $thumbWidth = $thumbHeight * $srcWidth / $srcHeight;
        } elseif ($thumbHeight == 0) {
            $thumbHeight = $thumbWidth * $srcHeight / $srcWidth;
        } else {
            $a = $thumbWidth / $thumbHeight;
            $b = $srcWidth / $srcHeight;
            if ($a > $b) {
                $thumbWidth = $b * $thumbHeight;
            } else {
                $thumbHeight = $thumbWidth / $b;
            }
        }
        if (function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
            $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
        } else {
            $thumb = imagecreate($thumbWidth, $thumbHeight);
        }
        // preserve png transparency
        imagealphablending($thumb, false);
        imagesavealpha($thumb, true);
        imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
        imagedestroy($source);
        $source = $thumb;
    }
    return $source;
}
Esempio n. 26
0
 /**
  * 生成验证码
  * @param  string $file 图片保存文件名,不指定则图片会被直接输出
  * @return null
  */
 public function get($file = "")
 {
     $support = $this->support();
     list($code, $answer) = $this->generateCode();
     $image = null;
     @session_start();
     $_SESSION['vitex.captcha.answer'] = strtolower($answer);
     if ($support == 'imagick') {
         $image = new \Imagick();
         $image->newImage($this->width, $this->height, "none");
         $image->setImageFormat('png');
         $image = $this->imagickLine($image, $this->linenum);
         $image = $this->imagickDrawText($image, $code);
         $image->swirlImage(30);
         $image->oilPaintImage(1);
         if ($file) {
             $image->writeImage($file);
         } else {
             header("Content-type:image/png");
             echo $image->getImageBlob();
         }
     } else {
         $image = imagecreate($this->width, $this->height);
         $color = imagecolorallocate($image, 255, 255, 255);
         imagecolortransparent($image, $color);
         $this->gdLine($image, $this->linenum);
         $this->gdDrawText($image, $code);
         if ($file) {
             imagepng($image, $file);
         } else {
             header("Content-type: image/jpeg; Cache-Control: no-store, no-cache, must-revalidate");
             imagepng($image);
         }
     }
 }
 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.5;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 20, 20, 20);
     $text_color = imagecolorallocate($image, 230, 197, 89);
     $noise_color = imagecolorallocate($image, 0, 0, 0);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     /*for( $i=0; $i<($width*$height)/150; $i++ ) {
     			imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
     		}*/
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
Esempio n. 28
0
 /**
  * Create a palette image
  *
  * @param int $width
  * @param int $height
  * @return WideImage_PaletteImage
  */
 static function create($width, $height)
 {
     if ($width * $height <= 0 || $width < 0) {
         throw new WideImage_InvalidImageDimensionException("Can't create an image with dimensions [{$width}, {$height}].");
     }
     return new WideImage_PaletteImage(imagecreate($width, $height));
 }
 public function testLoadGDResource()
 {
     $image = imagecreate(18, 18);
     $adapter = $this->getAdapterMock('GD', 'load', $image);
     $loader = $this->getImageLoaderPartialMock($adapter, 'GD');
     $this->assertSame($adapter, $loader->load($image));
 }
Esempio n. 30
-1
 /**
  *	Génère l'avatar
  */
 public function run()
 {
     //On créer l'image avec les dimentions données
     $image = imagecreate($this->_size, $this->_size);
     //On créer la couleur en fonction du hash de la chaine de caractères
     $color = imagecolorallocate($image, hexdec(substr($this->_color, 0, 2)), hexdec(substr($this->_color, 2, 2)), hexdec(substr($this->_color, 4, 2)));
     //on défini le fond de l'image (blanc)
     $bg = imagecolorallocate($image, 255, 255, 255);
     //nombre de blocs à placer dans l'image (taille de l'image/taille des blocs)
     $c = $this->_size / $this->_blockSize;
     for ($x = 0; $x < ceil($c / 2); $x++) {
         for ($y = 0; $y < $c; $y++) {
             // Si le nombre est pair $pixel vaut true sinon $pixel vaut false
             $pixel = hexdec($this->_hash[(int) ($x * ceil($c / 2)) + $y]) % 2 == 0;
             if ($pixel) {
                 $pixelColor = $color;
             } else {
                 $pixelColor = $bg;
             }
             // On place chaque bloc de l'image
             //imagefilledrectangle($image, $x*$this->_blockSize, $y*$this->_blockSize, ($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
             //imagefilledrectangle($image, $this->_size-$x*$this->_blockSize, $y*$this->_blockSize, $this->_size-($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
             imagefilledrectangle($image, $x * $this->_blockSize, $y * $this->_blockSize, ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
             imagefilledrectangle($image, $this->_size - $x * $this->_blockSize, $y * $this->_blockSize, $this->_size - ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
         }
     }
     ob_start();
     imagepng($image);
     //on place l'image en mémoire
     $this->_image = ob_get_contents();
     ob_clean();
 }