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


PHP imagecolorstotal函数代码示例

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


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

示例1: applyFilter

 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     if (function_exists('imagefilter')) {
         // If gd is bundled this will work
         imagefilter($himage, IMG_FILTER_GRAYSCALE);
     } else {
         // If not we need to do some enumeration
         $total = imagecolorstotal($himage);
         if ($total > 0) {
             // This works for indexed images but not for truecolor
             for ($i = 0; $i < $total; $i++) {
                 $index = imagecolorsforindex($himage, $i);
                 $avg = ($index["red"] + $index["green"] + $index["blue"]) / 3;
                 $red = $avg;
                 $green = $avg;
                 $blue = $avg;
                 imagecolorset($himage, $i, $red, $green, $blue);
             }
         } else {
             // For truecolor we need to enum it all
             for ($x = 0; $x < imagesx($himage); $x++) {
                 for ($y = 0; $y < imagesy($himage); $y++) {
                     $index = imagecolorat($himage, $x, $y);
                     $avg = (($index & 0xff) + ($index >> 8 & 0xff) + ($index >> 16 & 0xff)) / 3;
                     imagesetpixel($himage, $x, $y, $avg | $avg << 8 | $avg << 16);
                 }
             }
         }
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:31,代码来源:grayscale.php

示例2: ImageCopyBicubic

/**
 *
 * long description
 * @global object
 * @param object $dst_img
 * @param object $src_img
 * @param int $dst_x 
 * @param int $dst_y 
 * @param int $src_x 
 * @param int $src_y 
 * @param int $dst_w 
 * @param int $dst_h 
 * @param int $src_w 
 * @param int $src_h 
 * @return bool
 * @todo Finish documenting this function
 */
function ImageCopyBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
    global $CFG;
    if (function_exists('ImageCopyResampled') and $CFG->gdversion >= 2) {
        return ImageCopyResampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    $totalcolors = imagecolorstotal($src_img);
    for ($i = 0; $i < $totalcolors; $i++) {
        if ($colors = ImageColorsForIndex($src_img, $i)) {
            ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
        }
    }
    $scaleX = ($src_w - 1) / $dst_w;
    $scaleY = ($src_h - 1) / $dst_h;
    $scaleX2 = $scaleX / 2.0;
    $scaleY2 = $scaleY / 2.0;
    for ($j = 0; $j < $dst_h; $j++) {
        $sY = $j * $scaleY;
        for ($i = 0; $i < $dst_w; $i++) {
            $sX = $i * $scaleX;
            $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
            $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
            $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
            $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
            $color = ImageColorClosest($dst_img, $red, $green, $blue);
            ImageSetPixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
        }
    }
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:49,代码来源:gdlib.php

示例3: analyze

 /**
  * {@inheritdoc}
  */
 public function analyze($filename)
 {
     $imageSize = @getimagesize($filename);
     if ($imageSize === false) {
         throw new UnsupportedFileException('File type not supported.');
     }
     $imageInfo = new ImageInfo();
     $type = null;
     $colors = null;
     if ($imageSize[2] === IMAGETYPE_JPEG) {
         $gd = imagecreatefromjpeg($filename);
         $type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE';
         $colors = imagecolorstotal($gd);
         imagedestroy($gd);
     } elseif ($imageSize[2] === IMAGETYPE_GIF) {
         $gd = imagecreatefromgif($filename);
         $type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE';
         $colors = imagecolorstotal($gd);
         imagedestroy($gd);
     } elseif ($imageSize[2] === IMAGETYPE_PNG) {
         $gd = imagecreatefrompng($filename);
         $type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE';
         $colors = imagecolorstotal($gd);
         imagedestroy($gd);
     }
     $imageInfo->setAnalyzer(get_class($this))->setSize($imageSize[0], $imageSize[1])->setResolution(null, null)->setUnits(null)->setFormat($this->mapFormat($imageSize[2]))->setColors($colors)->setType($type)->setColorspace(!empty($imageSize['channels']) ? $imageSize['channels'] === 4 ? 'CMYK' : 'RGB' : 'RGB')->setDepth($imageSize['bits'])->setCompression(null)->setQuality(null)->setProfiles(null);
     return $imageInfo;
 }
开发者ID:temp,项目名称:image-analyzer,代码行数:31,代码来源:GdDriver.php

示例4: execute

 function execute()
 {
     $img =& $this->image->getImage();
     if (!($t = imagecolorstotal($img))) {
         $t = 256;
         imagetruecolortopalette($img, true, $t);
     }
     $total = imagecolorstotal($img);
     for ($i = 0; $i < $total; $i++) {
         $index = imagecolorsforindex($img, $i);
         $red = $index["red"] * 0.393 + $index["green"] * 0.769 + $index["blue"] * 0.189;
         $green = $index["red"] * 0.349 + $index["green"] * 0.6860000000000001 + $index["blue"] * 0.168;
         $blue = $index["red"] * 0.272 + $index["green"] * 0.534 + $index["blue"] * 0.131;
         if ($red > 255) {
             $red = 255;
         }
         if ($green > 255) {
             $green = 255;
         }
         if ($blue > 255) {
             $blue = 255;
         }
         imagecolorset($img, $i, $red, $green, $blue);
     }
 }
开发者ID:BackupTheBerlios,项目名称:redaxo-svn,代码行数:25,代码来源:class.rex_effect_filter_sepia.inc.php

示例5: transparent

 /**
  * 透過処理済みの新しいイメージオブジェクトを生成する。
  */
 function transparent($image, $info, $newImage = null)
 {
     if ($newImage == null) {
         $newImage = imagecreatetruecolor($this->width, $this->height);
     }
     if ($info[2] == IMAGETYPE_GIF || $info[2] == IMAGETYPE_PNG) {
         // 元画像の透過色を取得する。
         $trnprt_indx = imagecolortransparent($image);
         // パレットサイズを取得する。
         $palletsize = imagecolorstotal($image);
         // 透過色が設定されている場合は透過処理を行う。
         if ($trnprt_indx >= 0 && $trnprt_indx < $palletsize) {
             // カラーインデックスから透過色を取得する。
             $trnprt_color = imagecolorsforindex($image, $trnprt_indx);
             // 取得した透過色から変換後の画像用のカラーインデックスを生成
             $trnprt_indx = imagecolorallocate($newImage, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
             // 生成した透過色で変換後画像を塗りつぶし
             imagefill($newImage, 0, 0, $trnprt_indx);
             // 生成した透過色を変換後画像の透過色として設定
             imagecolortransparent($newImage, $trnprt_indx);
         } elseif ($info[2] == IMAGETYPE_PNG) {
             // アルファブレンディングをOFFにする。
             imagealphablending($newImage, false);
             // アルファブレンドのカラーを作成する。
             $trnprt_indx = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
             // 生成した透過色で変換後画像を塗りつぶし
             imagefill($newImage, 0, 0, $trnprt_indx);
             // 透過色をGIF用に設定
             imagecolortransparent($newImage, $trnprt_indx);
             // 生成した透過色を変換後画像の透過色として設定
             imagesavealpha($newImage, true);
         }
     }
     return $newImage;
 }
开发者ID:naonaox1126,项目名称:vizualizer,代码行数:38,代码来源:Base.php

示例6: convert

 /**
  * Convert an image.
  *
  * @param   img.Image image
  * @return  bool
  * @throws  img.ImagingException
  */
 public function convert($image)
 {
     // Create temporary variable as local variable access is faster
     // than member variable access.
     $handle = $image->handle;
     if (imageistruecolor($handle)) {
         $l = [];
         $h = $image->getHeight();
         $w = $image->getWidth();
         for ($y = 0; $y < $h; $y++) {
             for ($x = 0; $x < $w; $x++) {
                 $rgb = imagecolorat($handle, $x, $y);
                 if (!isset($l[$rgb])) {
                     $g = 0.299 * ($rgb >> 16 & 0xff) + 0.587 * ($rgb >> 8 & 0xff) + 0.114 * ($rgb & 0xff);
                     $l[$rgb] = imagecolorallocate($handle, $g, $g, $g);
                 }
                 imagesetpixel($handle, $x, $y, $l[$rgb]);
             }
         }
         unset($l);
     } else {
         for ($i = 0, $t = imagecolorstotal($handle); $i < $t; $i++) {
             $c = imagecolorsforindex($handle, $i);
             $g = 0.299 * $c['red'] + 0.587 * $c['green'] + 0.114 * $c['blue'];
             imagecolorset($handle, $i, $g, $g, $g);
         }
     }
 }
开发者ID:xp-framework,项目名称:imaging,代码行数:35,代码来源:GrayscaleConverter.class.php

示例7: imagecopybicubic

/**
 * Copies a rectangular portion of the source image to another rectangle in the destination image
 *
 * This function calls imagecopyresampled() if it is available and GD version is 2 at least.
 * Otherwise it reimplements the same behaviour. See the PHP manual page for more info.
 *
 * @link http://php.net/manual/en/function.imagecopyresampled.php
 * @param resource $dst_img the destination GD image resource
 * @param resource $src_img the source GD image resource
 * @param int $dst_x vthe X coordinate of the upper left corner in the destination image
 * @param int $dst_y the Y coordinate of the upper left corner in the destination image
 * @param int $src_x the X coordinate of the upper left corner in the source image
 * @param int $src_y the Y coordinate of the upper left corner in the source image
 * @param int $dst_w the width of the destination rectangle
 * @param int $dst_h the height of the destination rectangle
 * @param int $src_w the width of the source rectangle
 * @param int $src_h the height of the source rectangle
 * @return bool tru on success, false otherwise
 */
function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
    global $CFG;
    if (function_exists('imagecopyresampled') and $CFG->gdversion >= 2) {
        return imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    $totalcolors = imagecolorstotal($src_img);
    for ($i = 0; $i < $totalcolors; $i++) {
        if ($colors = imagecolorsforindex($src_img, $i)) {
            imagecolorallocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
        }
    }
    $scalex = ($src_w - 1) / $dst_w;
    $scaley = ($src_h - 1) / $dst_h;
    $scalex2 = $scalex / 2.0;
    $scaley2 = $scaley / 2.0;
    for ($j = 0; $j < $dst_h; $j++) {
        $sy = $j * $scaley;
        for ($i = 0; $i < $dst_w; $i++) {
            $sx = $i * $scalex;
            $c1 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx, (int) $sy + $scaley2));
            $c2 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx, (int) $sy));
            $c3 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx + $scalex2, (int) $sy + $scaley2));
            $c4 = imagecolorsforindex($src_img, imagecolorat($src_img, (int) $sx + $scalex2, (int) $sy));
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
            $color = imagecolorclosest($dst_img, $red, $green, $blue);
            imagesetpixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
        }
    }
}
开发者ID:JP-Git,项目名称:moodle,代码行数:51,代码来源:gdlib.php

示例8: fit

 /**
  * Fit small image to specified bound
  *
  * @param string $src
  * @param string $dest
  * @param int $width
  * @param int $height
  * @return bool
  */
 public function fit($src, $dest, $width, $height)
 {
     // Calculate
     $size = getimagesize($src);
     $ratio = max($width / $size[0], $height / $size[1]);
     $old_width = $size[0];
     $old_height = $size[1];
     $new_width = intval($old_width * $ratio);
     $new_height = intval($old_height * $ratio);
     // Resize
     @ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT));
     $image = imagecreatefromstring(file_get_contents($src));
     $new_image = wp_imagecreatetruecolor($new_width, $new_height);
     imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
     if (IMAGETYPE_PNG == $size[2] && function_exists('imageistruecolor') && !imageistruecolor($image)) {
         imagetruecolortopalette($new_image, false, imagecolorstotal($image));
     }
     // Destroy old image
     imagedestroy($image);
     // Save
     switch ($size[2]) {
         case IMAGETYPE_GIF:
             $result = imagegif($new_image, $dest);
             break;
         case IMAGETYPE_PNG:
             $result = imagepng($new_image, $dest);
             break;
         default:
             $result = imagejpeg($new_image, $dest);
             break;
     }
     imagedestroy($new_image);
     return $result;
 }
开发者ID:hametuha,项目名称:wpametu,代码行数:43,代码来源:Image.php

示例9: execute

 public function execute()
 {
     $this->media->asImage();
     $img = $this->media->getImage();
     if (!($t = imagecolorstotal($img))) {
         $t = 256;
         imagetruecolortopalette($img, true, $t);
     }
     $total = imagecolorstotal($img);
     for ($i = 0; $i < $total; ++$i) {
         $index = imagecolorsforindex($img, $i);
         $red = $index['red'] * 0.393 + $index['green'] * 0.769 + $index['blue'] * 0.189;
         $green = $index['red'] * 0.349 + $index['green'] * 0.6860000000000001 + $index['blue'] * 0.168;
         $blue = $index['red'] * 0.272 + $index['green'] * 0.534 + $index['blue'] * 0.131;
         if ($red > 255) {
             $red = 255;
         }
         if ($green > 255) {
             $green = 255;
         }
         if ($blue > 255) {
             $blue = 255;
         }
         imagecolorset($img, $i, $red, $green, $blue);
     }
     $this->media->setImage($img);
 }
开发者ID:staabm,项目名称:redaxo,代码行数:27,代码来源:effect_filter_sepia.php

示例10: applyFilter

 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     // If not we need to do some enumeration
     $total = imagecolorstotal($himage);
     if ($total > 0) {
         // This works for indexed images but not for truecolor
         for ($i = 0; $i < $total; $i++) {
             $index = imagecolorsforindex($himage, $i);
             $rgb = rgb($index['red'], $index['green'], $index['blue']);
             $hsv = hsv($rgb);
             $hsv->hue = $this->hue;
             $rgb = rgb($hsv);
             $red = $rgb->red;
             $green = $rgb->green;
             $blue = $rgb->blue;
             imagecolorset($himage, $i, $red, $green, $blue);
         }
     } else {
         // For truecolor we need to enum it all
         for ($x = 0; $x < imagesx($himage); $x++) {
             for ($y = 0; $y < imagesy($himage); $y++) {
                 $index = imagecolorat($himage, $x, $y);
                 $rgb = rgb($index['red'], $index['green'], $index['blue'], $index['alpha']);
                 $hsv = hsv($rgb);
                 $hsv->hue = $this->hue;
                 $rgb = rgb($hsv);
                 $red = $rgb->red;
                 $green = $rgb->green;
                 $blue = $rgb->blue;
                 imagesetpixel($himage, $x, $y, $red << 16 | $green < 8 | $blue);
             }
         }
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:35,代码来源:hue.php

示例11: getColors

 function getColors()
 {
     $colors = array();
     for ($i = 0; $i < imagecolorstotal($this->im); $i++) {
         $colors[] = imagecolorsforindex($this->im, $i);
     }
     return $colors;
 }
开发者ID:kenyattaclark,项目名称:shiftspace,代码行数:8,代码来源:image.php

示例12: image_resize

 /**
  * This function is almost equal to the image_resize (native function of wordpress)
  */
 function image_resize($file, $max_w, $max_h, $crop = false, $far = false, $iar = false, $dest_path = null, $jpeg_quality = 90)
 {
     $image = wp_load_image($file);
     if (!is_resource($image)) {
         return new WP_Error('error_loading_image', $image);
     }
     $size = @getimagesize($file);
     if (!$size) {
         return new WP_Error('invalid_image', __('Could not read image size'), $file);
     }
     list($orig_w, $orig_h, $orig_type) = $size;
     $dims = mf_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop, $far, $iar);
     if (!$dims) {
         $dims = array(0, 0, 0, 0, $orig_w, $orig_h, $orig_w, $orig_h);
     }
     list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
     $newimage = imagecreatetruecolor($dst_w, $dst_h);
     imagealphablending($newimage, false);
     imagesavealpha($newimage, true);
     $transparent = imagecolorallocatealpha($newimage, 255, 255, 255, 127);
     imagefilledrectangle($newimage, 0, 0, $dst_w, $dst_h, $transparent);
     imagecopyresampled($newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
     // convert from full colors to index colors, like original PNG.
     if (IMAGETYPE_PNG == $orig_type && !imageistruecolor($image)) {
         imagetruecolortopalette($newimage, false, imagecolorstotal($image));
     }
     // we don't need the original in memory anymore
     imagedestroy($image);
     $info = pathinfo($dest_path);
     $dir = $info['dirname'];
     $ext = $info['extension'];
     $name = basename($dest_path, ".{$ext}");
     $destfilename = "{$dir}/{$name}.{$ext}";
     if (IMAGETYPE_GIF == $orig_type) {
         if (!imagegif($newimage, $destfilename)) {
             return new WP_Error('resize_path_invalid', __('Resize path invalid'));
         }
     } elseif (IMAGETYPE_PNG == $orig_type) {
         if (!imagepng($newimage, $destfilename)) {
             return new WP_Error('resize_path_invalid', __('Resize path invalid'));
         }
     } else {
         // all other formats are converted to jpg
         //Todo: add option for use progresive JPG
         //imageinterlace($newimage, true); //Progressive JPG
         if (!imagejpeg($newimage, $destfilename, apply_filters('jpeg_quality', $jpeg_quality, 'image_resize'))) {
             return new WP_Error('resize_path_invalid', __('Resize path invalid'));
         }
     }
     imagedestroy($newimage);
     // Set correct file permissions
     $stat = stat(dirname($destfilename));
     $perms = $stat['mode'] & 0666;
     //same permissions as parent folder, strip off the executable bits
     @chmod($destfilename, $perms);
     return $destfilename;
 }
开发者ID:ahsaeldin,项目名称:projects,代码行数:60,代码来源:MF_thumb.php

示例13: _save

 protected function _save($image, $filename = null, $mime_type = null)
 {
     global $ewww_debug;
     if (!defined('EWWW_IMAGE_OPTIMIZER_DOMAIN')) {
         require_once plugin_dir_path(__FILE__) . 'ewww-image-optimizer.php';
     }
     if (!defined('EWWW_IMAGE_OPTIMIZER_JPEGTRAN')) {
         ewww_image_optimizer_init();
     }
     list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type);
     if (!$filename) {
         $filename = $this->generate_filename(null, null, $extension);
     }
     if ('image/gif' == $mime_type) {
         if (!$this->make_image($filename, 'imagegif', array($image, $filename))) {
             return new WP_Error('image_save_error', __('Image Editor Save Failed'));
         }
     } elseif ('image/png' == $mime_type) {
         // convert from full colors to index colors, like original PNG.
         if (function_exists('imageistruecolor') && !imageistruecolor($image)) {
             imagetruecolortopalette($image, false, imagecolorstotal($image));
         }
         if (property_exists('WP_Image_Editor', 'quality')) {
             $compression_level = floor((101 - $this->quality) * 0.09);
             $ewww_debug .= "png quality = " . $this->quality . "<br>";
         } else {
             $compression_level = floor((101 - false) * 0.09);
         }
         if (!$this->make_image($filename, 'imagepng', array($image, $filename, $compression_level))) {
             return new WP_Error('image_save_error', __('Image Editor Save Failed'));
         }
     } elseif ('image/jpeg' == $mime_type) {
         if (method_exists($this, 'get_quality')) {
             if (!$this->make_image($filename, 'imagejpeg', array($image, $filename, $this->get_quality()))) {
                 return new WP_Error('image_save_error', __('Image Editor Save Failed'));
             }
         } else {
             if (!$this->make_image($filename, 'imagejpeg', array($image, $filename, apply_filters('jpeg_quality', $this->quality, 'image_resize')))) {
                 return new WP_Error('image_save_error', __('Image Editor Save Failed'));
             }
         }
     } else {
         return new WP_Error('image_save_error', __('Image Editor Save Failed'));
     }
     // Set correct file permissions
     $stat = stat(dirname($filename));
     $perms = $stat['mode'] & 0666;
     //same permissions as parent folder, strip off the executable bits
     @chmod($filename, $perms);
     ewww_image_optimizer_aux_images_loop($filename, true);
     $ewww_debug = "{$ewww_debug} image editor (gd) saved: {$filename} <br>";
     $image_size = filesize($filename);
     $ewww_debug = "{$ewww_debug} image editor size: {$image_size} <br>";
     ewww_image_optimizer_debug_log();
     return array('path' => $filename, 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), 'width' => $this->size['width'], 'height' => $this->size['height'], 'mime-type' => $mime_type);
 }
开发者ID:aim-web-projects,项目名称:kobe-chuoh,代码行数:56,代码来源:image-editor.php

示例14: thumbnail

function thumbnail($image, $width, $height, $extension)
{
    $data = getImageSize($image);
    $imageInfo["width"] = $data[0];
    $imageInfo["height"] = $data[1];
    $imageInfo["type"] = $data[2];
    switch ($imageInfo["type"]) {
        case 1:
            $img = imagecreatefromgif($image);
            break;
        case 2:
            $img = imageCreatefromjpeg($image);
            break;
        case 3:
            $img = imageCreatefrompng($image);
            break;
        default:
            return false;
    }
    $size["width"] = $imageInfo["width"];
    $size["height"] = $imageInfo["height"];
    if ($width < $imageInfo["width"]) {
        $size["width"] = $width;
    }
    if ($height < $imageInfo["height"]) {
        $size["height"] = $height;
    }
    if ($imageInfo["width"] * $size["width"] > $imageInfo["height"] * $size["height"]) {
        $size["height"] = round($imageInfo["height"] * $size["width"] / $imageInfo["width"]);
    } else {
        $size["width"] = round($imageInfo["width"] * $size["height"] / $imageInfo["height"]);
    }
    $newImg = imagecreatetruecolor($size["width"], $size["height"]);
    $otsc = imagecolortransparent($img);
    if ($otsc >= 0 && $otsc <= imagecolorstotal($img)) {
        $tran = imagecolorsforindex($img, $otsc);
        $newt = imagecolorallocate($newImg, $tran["red"], $tran["green"], $tran["blue"]);
        imagefill($newImg, 0, 0, $newt);
        imagecolortransparent($newImg, $newt);
    }
    imagecopyresized($newImg, $img, 0, 0, 0, 0, $size["width"], $size["height"], $imageInfo["width"], $imageInfo["height"]);
    imagedestroy($img);
    $newName = str_replace('.', $extension . '.', $image);
    switch ($imageInfo["type"]) {
        case 1:
            $result = imageGif($newImg, $newName);
            break;
        case 2:
            $result = imageJPEG($newImg, $newName);
            break;
        case 3:
            $result = imagepng($newImg, $newName);
            break;
    }
    imagedestroy($newImg);
}
开发者ID:leamiko,项目名称:interest,代码行数:56,代码来源:common.php

示例15: invisible

function invisible($Image) {
	$Count = imagecolorstotal($Image);
	if ($Count == 0) { return false; }
	$TotalAlpha = 0;
	for ($i=0; $i<$Count; ++$i) {
		$Color = imagecolorsforindex($Image,$i);
		$TotalAlpha += $Color['alpha'];
	}
	return (($TotalAlpha/$Count) == 127) ? true : false;
	
}
开发者ID:4play,项目名称:gazelle2,代码行数:11,代码来源:image.php


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