当前位置: 首页>>代码示例>>PHP>>正文


PHP imagecreate函数代码示例

本文整理汇总了PHP中imagecreate函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecreate函数的具体用法?PHP imagecreate怎么用?PHP imagecreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了imagecreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getAvatar

 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;
 }
开发者ID:recallfx,项目名称:monsterid.php,代码行数:31,代码来源:MonsterId.php

示例2: run

 /**
  *	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();
 }
开发者ID:JulienCoutault,项目名称:Web,代码行数:35,代码来源:RandomAvatar.php

示例3: executeGetLabel

 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);
 }
开发者ID:taryono,项目名称:school,代码行数:28,代码来源:actions.class.php

示例4: create

 /**
  * 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));
 }
开发者ID:ehazell,项目名称:AZDWR,代码行数:14,代码来源:PaletteImage.php

示例5: getCode

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);
}
开发者ID:hanpc,项目名称:chushen,代码行数:35,代码来源:code_char.php

示例6: mkthumb

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;
    }
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:60,代码来源:thumbs.inc.php

示例7: index

 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);
 }
开发者ID:binaek89,项目名称:cms-canvas,代码行数:31,代码来源:captcha.php

示例8: graph_error

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;
    }
}
开发者ID:greggcz,项目名称:librenms,代码行数:31,代码来源:graph.inc.php

示例9: __construct

 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);
 }
开发者ID:elshafey,项目名称:ir,代码行数:31,代码来源:capatcha.php

示例10: generateAvatarGD

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);
}
开发者ID:kaantunc,项目名称:MYK-BOR,代码行数:26,代码来源:myprofile_avatar_upload.php

示例11: YDGraphPie

 /**
  *  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: ';
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:35,代码来源:YDGraphPie.php

示例12: imgcode

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);
}
开发者ID:FantasticThought,项目名称:tfsda,代码行数:32,代码来源:captcha.php

示例13: apply

 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);
 }
开发者ID:snowjobgit,项目名称:limb,代码行数:7,代码来源:lmbGdCropImageFilter.class.php

示例14: blank

 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);
 }
开发者ID:kofel,项目名称:gutenberg,代码行数:7,代码来源:Image.php

示例15: getCode

 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);
 }
开发者ID:soulence1211,项目名称:SOULENCE,代码行数:26,代码来源:Image.php


注:本文中的imagecreate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。