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


PHP imagecreatetruecolor函数代码示例

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


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

示例1: set_img

 private static function set_img()
 {
     self::$res_img = imagecreatetruecolor(self::$width, self::$height);
     $color_bg = imagecolorallocate(self::$res_img, 255, 255, 255);
     //填充图片
     imagefilledrectangle(self::$res_img, 0, self::$height, self::$width, 0, $color_bg);
 }
开发者ID:think-css,项目名称:yungou,代码行数:7,代码来源:checkcode.class.php

示例2: thumb

function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5)
{
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    //image_50/sdfsdkfjkelwkerjle.jpg
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
开发者ID:Wumingla,项目名称:shopImooc,代码行数:26,代码来源:resizeImage2.php

示例3: fill_color

 /**
  * Background fill an image using the provided color
  *
  * @param int $width The desired width of the new image
  * @param int $height The desired height of the new image
  * @param Array the desired pad colors in RGB format, array should be array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '' );
  */
 private function fill_color(array $colors)
 {
     $current_size = $this->editor->get_size();
     $size = array('width' => $this->args['width'], 'height' => $this->args['height']);
     $offsetLeft = ($size['width'] - $current_size['width']) / 2;
     $offsetTop = ($size['height'] - $current_size['height']) / 2;
     $new_image = imagecreatetruecolor($size['width'], $size['height']);
     // This is needed to support alpha
     imagesavealpha($new_image, true);
     imagealphablending($new_image, false);
     // Check if we are padding vertically or horizontally
     if ($current_size['width'] != $size['width']) {
         $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['left'], 0, 3), substr($colors['left'], 3, 3), substr($colors['left'], 6, 3), substr($colors['left'], 9, 3));
         // Fill left color
         imagefilledrectangle($new_image, 0, 0, $offsetLeft + 5, $size['height'], $colorToPaint);
         $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['right'], 0, 3), substr($colors['right'], 3, 3), substr($colors['right'], 6, 3), substr($colors['left'], 9, 3));
         // Fill right color
         imagefilledrectangle($new_image, $offsetLeft + $current_size['width'] - 5, 0, $size['width'], $size['height'], $colorToPaint);
     } elseif ($current_size['height'] != $size['height']) {
         $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['top'], 0, 3), substr($colors['top'], 3, 3), substr($colors['top'], 6, 3), substr($colors['left'], 9, 3));
         // Fill top color
         imagefilledrectangle($new_image, 0, 0, $size['width'], $offsetTop + 5, $colorToPaint);
         $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['bottom'], 0, 3), substr($colors['bottom'], 3, 3), substr($colors['bottom'], 6, 3), substr($colors['left'], 9, 3));
         // Fill bottom color
         imagefilledrectangle($new_image, 0, $offsetTop - 5 + $current_size['height'], $size['width'], $size['height'], $colorToPaint);
     }
     imagecopy($new_image, $this->editor->get_image(), $offsetLeft, $offsetTop, 0, 0, $current_size['width'], $current_size['height']);
     $this->editor->update_image($new_image);
     $this->editor->update_size();
 }
开发者ID:shads196770,项目名称:cbox-theme,代码行数:37,代码来源:wpthumb.background-fill.php

示例4: getImage

 private function getImage()
 {
     $image = imagecreatefromstring(file_get_contents($this->file['tmp_name']));
     if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') {
         $exif = exif_read_data($this->file['tmp_name']);
         if (!empty($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 8:
                     $image = imagerotate($image, 90, 0);
                     break;
                 case 3:
                     $image = imagerotate($image, 180, 0);
                     break;
                 case 6:
                     $image = imagerotate($image, -90, 0);
                     break;
             }
         }
     }
     // Get new sizes
     $width = imagesx($image);
     $height = imagesy($image);
     //list($width, $height) = getimagesize($this->file['tmp_name']);
     list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800);
     // Load
     $resizeImage = imagecreatetruecolor($newWidth, $newHeight);
     // Resize
     imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     return $resizeImage;
 }
开发者ID:ambujaacool,项目名称:MyApp,代码行数:30,代码来源:ImageUpload.php

示例5: createnewpicture

 private function createnewpicture()
 {
     $local = $this->path_two . $this->file['name'];
     move_uploaded_file($this->file['tmp_name'], $local);
     $filename = $this->file['tmp_name'] . "/" . $this->file['name'];
     $this->location = $this->path . "/" . $this->file['name'];
     switch ($this->file['type']) {
         case 'image/jpeg':
             $src = imagecreatefromjpeg($local);
             break;
         case 'image/png':
             $src = imagecreatefrompng($local);
             break;
         case 'image/gif':
             $src = imagecreatefromgif($local);
             break;
         default:
             break;
     }
     $sx = imagesx($src);
     $sy = imagesy($src);
     $new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
     if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
         if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
             //imagejpeg($this->location);
             return true;
         }
     } else {
         return false;
     }
 }
开发者ID:JiaJia01,项目名称:homework_09,代码行数:31,代码来源:picture.php

示例6: init

 public function init(awImage $image)
 {
     if ($this->resource === NULL) {
         $this->setImageSize($image->width, $image->height);
         // Create image
         $this->resource = imagecreatetruecolor($this->imageWidth, $this->imageHeight);
         if (!$this->resource) {
             awImage::drawError("Class Image: Unable to create a graph.");
         }
         imagealphablending($this->resource, TRUE);
         // Antialiasing is now handled by the Driver object
         $this->setAntiAliasing($image->getAntiAliasing());
         // Original color
         $this->filledRectangle(new awWhite(), new awLine(new awPoint(0, 0), new awPoint($this->imageWidth, $this->imageHeight)));
         $shadow = $image->shadow;
         if ($shadow !== NULL) {
             $shadow = $shadow->getSpace();
             $p1 = new awPoint($shadow->left, $shadow->top);
             $p2 = new awPoint($this->imageWidth - $shadow->right - 1, $this->imageHeight - $shadow->bottom - 1);
             // Draw image background
             $this->filledRectangle($image->getBackground(), new awLine($p1, $p2));
             // Draw image border
             $image->border->rectangle($this, $p1, $p2);
         }
     }
 }
开发者ID:greench,项目名称:prestashop,代码行数:26,代码来源:gd.class.php

示例7: fastimagecopyresampled

function fastimagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
{
    // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.
    // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".
    // Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
    // Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain.
    //
    // Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example
    // 1.5. Must be greater than zero.
    // Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.
    // 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.
    // 2 = Up to 95 times faster.  Images appear a little sharp, some prefer this over a quality of 3.
    // 3 = Up to 60 times faster.  Will give high quality smooth results very close to imagecopyresampled, just faster.
    // 4 = Up to 25 times faster.  Almost identical to imagecopyresampled for most images.
    // 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.
    if (empty($src_image) || empty($dst_image) || $quality <= 0) {
        return false;
    }
    if ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) {
        $temp = imagecreatetruecolor($dst_w * $quality + 1, $dst_h * $quality + 1);
        imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h);
        imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality);
        imagedestroy($temp);
    } else {
        imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    return true;
}
开发者ID:njanani,项目名称:olio-cassandra,代码行数:28,代码来源:ImageUtil.php

示例8: DrawGraph

 function DrawGraph($file = "")
 {
     $this->graph_width = $this->graph_padding['left'] + count($this->data) * ($this->bar_width + $this->bar_padding * 2) + $this->graph_padding['right'];
     $this->axis_deepness = $this->bar_height;
     $this->im = imagecreatetruecolor($this->graph_width, $this->graph_height);
     $this->axis_frontgridlines = 0;
     $this->axis_xscalevisible = 0;
     $this->axis_positions = array($this->axis_positions[0], 0, 0, 0);
     CGraph::DrawGraph();
     if ($this->axis_minY > 0) {
         $this->axis_minY = 0;
     }
     if ($this->axis_maxY < 0) {
         $this->axis_maxY = 0;
     }
     $this->__Draw_LeftBottom_Axis();
     $p = 0;
     foreach ($this->data as $name => $value) {
         $p++;
         $this->__DrawBarText($p, $name);
         $this->__DrawBar($p, $value);
     }
     $this->__Draw_TopRight_Axis();
     CGraph::DrawGraph2();
     if (strlen($file)) {
         $ret = imagepng($this->im, $file);
     } else {
         header("Content-Type: image/png");
         // thanks to Marcin G. :)
         imagepng($this->im);
         $ret = true;
     }
     imagedestroy($this->im);
     return $ret;
 }
开发者ID:pablius,项目名称:oob-n1,代码行数:35,代码来源:class.3dbargraph.php

示例9: codeimage

 static function codeimage()
 {
     $image = imagecreatetruecolor(100, 30);
     $bgcolor = imagecolorallocate($image, 255, 255, 255);
     imagefill($image, 0, 0, $bgcolor);
     $code = '';
     for ($i = 0; $i < 4; $i++) {
         $fontsize = 6;
         $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
         $data = "abcdefghjkmnpqrstuvwxy3456789";
         $fontcontent = substr($data, rand(1, strlen($data) - 1), 1);
         $code .= $fontcontent;
         $x = $i * 100 / 4 + rand(5, 10);
         $y = rand(5, 10);
         imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
     }
     for ($i = 0; $i < 200; $i++) {
         $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
         imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor);
     }
     for ($i = 0; $i < 2; $i++) {
         $linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
         imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor);
     }
     $return['code'] = $code;
     $return['image'] = $image;
     return $return;
     //		header('content-type:image/png');
     //		imagepng($image);
 }
开发者ID:HivenKay,项目名称:ESalon,代码行数:30,代码来源:LfCodeimage.php

示例10: upload

function upload($tmp, $name, $nome, $larguraP, $pasta)
{
    $ext = strtolower(end(explode('.', $name)));
    if ($ext == 'jpg') {
        $img = imagecreatefromjpeg($tmp);
    } elseif ($ext == 'gif') {
        $img = imagecreatefromgif($tmp);
    } else {
        $img = imagecreatefrompng($tmp);
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $largura = $x > $larguraP ? $larguraP : $x;
    $altura = $largura * $y / $x;
    if ($altura > $larguraP) {
        $altura = $larguraP;
        $largura = $altura * $x / $y;
    }
    $nova = imagecreatetruecolor($largura, $altura);
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
    imagejpeg($nova, "{$pasta}/{$nome}");
    imagedestroy($img);
    imagedestroy($nova);
    return $nome;
}
开发者ID:mauriliovilela,项目名称:ser-social,代码行数:25,代码来源:funcoes.php

示例11: resizeTo

 public function resizeTo($width, $height)
 {
     if (osc_use_imagick()) {
         $bg = new Imagick();
         $bg->newImage($width, $height, 'white');
         $this->im->thumbnailImage($width, $height, true);
         $geometry = $this->im->getImageGeometry();
         $x = ($width - $geometry['width']) / 2;
         $y = ($height - $geometry['height']) / 2;
         $bg->compositeImage($this->im, imagick::COMPOSITE_OVER, $x, $y);
         $this->im = $bg;
     } else {
         $w = imagesx($this->im);
         $h = imagesy($this->im);
         if ($w / $h >= $width / $height) {
             //$newW = $width;
             $newW = $w > $width ? $width : $w;
             $newH = $h * ($newW / $w);
         } else {
             //$newH = $height;
             $newH = $h > $height ? $height : $h;
             $newW = $w * ($newH / $h);
         }
         $newIm = imagecreatetruecolor($width, $height);
         //$newW, $newH);
         imagealphablending($newIm, false);
         $colorTransparent = imagecolorallocatealpha($newIm, 255, 255, 255, 127);
         imagefill($newIm, 0, 0, $colorTransparent);
         imagesavealpha($newIm, true);
         imagecopyresampled($newIm, $this->im, ($width - $newW) / 2, ($height - $newH) / 2, 0, 0, $newW, $newH, $w, $h);
         imagedestroy($this->im);
         $this->im = $newIm;
     }
     return $this;
 }
开发者ID:jmcclenon,项目名称:Osclass,代码行数:35,代码来源:ImageResizer.php

示例12: create

 public static function create()
 {
     $image = imagecreatetruecolor(100, 40) or die('cannot create canvas.<br>');
     $red = imagecolorallocate($image, 255, 0, 0);
     $green = imagecolorallocate($image, 0, 255, 0);
     $blue = imagecolorallocate($image, 0, 0, 255);
     $white = imagecolorallocate($image, 255, 255, 255);
     $black = imagecolorallocate($image, 0, 0, 0);
     imagefill($image, 0, 0, $white);
     imagerectangle($image, 1, 1, 99, 39, $black);
     $color = [$red, $green, $blue];
     for ($i = 1; $i <= 100; $i++) {
         imagesetpixel($image, mt_rand(2, 98), mt_rand(2, 38), $color[mt_rand(0, 2)]);
     }
     $source = "abcdefghigklmnopqrstuvwxyz0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ";
     $first = $source[mt_rand(0, 61)];
     $second = $source[mt_rand(0, 61)];
     $third = $source[mt_rand(0, 61)];
     $fourth = $source[mt_rand(0, 61)];
     $_SESSION['captcha'] = $first . $second . $third . $fourth;
     $font = dirname(dirname(__DIR__)) . '/../public/assets/fonts/SpicyRice.ttf';
     imagettftext($image, 20, mt_rand(-20, 20), 10, 30, $blue, $font, $first);
     imagettftext($image, 20, mt_rand(-20, 20), 30, 30, $blue, $font, $second);
     imagettftext($image, 20, mt_rand(-20, 20), 50, 30, $blue, $font, $third);
     imagettftext($image, 20, mt_rand(-20, 20), 70, 30, $blue, $font, $fourth);
     return imagejpeg($image);
 }
开发者ID:marious,项目名称:talkingspace_forum,代码行数:27,代码来源:Captcha.php

示例13: createImage

 /**
  * Cria a imagem apartir dos dados do Sprite.
  */
 public function createImage()
 {
     $img = imagecreatetruecolor($this->width, $this->height);
     //http://in.php.net/manual/en/function.imagecreatetruecolor.php
     imagecolortransparent($img, imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha']));
     $i = 0;
     $p = 0;
     while ($i < strlen($this->data)) {
         $b = ord($this->data[$i]);
         //http://in.php.net/manual/en/function.ord.php
         if ($b == 0) {
             $i++;
             $dest = $p + ord($this->data[$i]);
             $color = imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha']);
             //http://in.php.net/manual/en/function.imagecolorallocatealpha.php
             for ($p; $p < $dest; $p++) {
                 imagesetpixel($img, $p % $this->width, $p / $this->width, $color);
             }
         } else {
             $color = imagecolorallocatealpha($img, $this->palette[$b]['red'], $this->palette[$b]['green'], $this->palette[$b]['blue'], $this->palette[$b]['alpha']);
             imagesetpixel($img, $p % $this->width, $p / $this->width, $color);
             //http://in.php.net/manual/en/function.imagesetpixel.php
             $p++;
         }
         $i++;
     }
     return $img;
 }
开发者ID:puring0815,项目名称:OpenKore,代码行数:31,代码来源:Sprite.php

示例14: imageThumb

/**
 * 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;
}
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:42,代码来源:images.inc.php

示例15: 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


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