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


PHP imagecolorset函数代码示例

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


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

示例1: changeBackground

function changeBackground($im, $red, $green, $blue)
{
    imagetruecolortopalette($im, false, 255);
    $ig = imagecolorat($im, 0, 0);
    imagecolorset($im, $ig, $red, $green, $blue);
    return $im;
}
开发者ID:JasonAJames,项目名称:jasonajamescom,代码行数:7,代码来源:qrcode-image.php

示例2: run

 public function run($file)
 {
     $res = $this->open_image($file);
     if ($res != TRUE) {
         return FALSE;
     }
     $this->image_progressive = isset($this->settings['field_settings']['progressive_jpeg']) === TRUE && $this->settings['field_settings']['progressive_jpeg'] == 'yes' ? TRUE : FALSE;
     $this->Ageimage = array(1, 0, 60);
     imagetruecolortopalette($this->EE->channel_images->image, 1, 256);
     for ($c = 0; $c < 256; $c++) {
         $col = imagecolorsforindex($this->EE->channel_images->image, $c);
         $new_col = floor($col['red'] * 0.2125 + $col['green'] * 0.7154 + $col['blue'] * 0.0721);
         $noise = rand(-$this->Ageimage[1], $this->Ageimage[1]);
         if ($this->Ageimage[2] > 0) {
             $r = $new_col + $this->Ageimage[2] + $noise;
             $g = floor($new_col + $this->Ageimage[2] / 1.86 + $noise);
             $b = floor($new_col + $this->Ageimage[2] / -3.48 + $noise);
         } else {
             $r = $new_col + $noise;
             $g = $new_col + $noise;
             $b = $new_col + $noise;
         }
         imagecolorset($this->EE->channel_images->image, $c, max(0, min(255, $r)), max(0, min(255, $g)), max(0, min(255, $b)));
     }
     $this->save_image($file);
     return TRUE;
 }
开发者ID:ayuinc,项目名称:laboratoria-v2,代码行数:27,代码来源:action.sepia.php

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

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

示例5: setColorPalette

function setColorPalette($input, $output, $clut)
{
    $gd = null;
    if (file_exists($input)) {
        $gd = imagecreatefrompng($input);
    } else {
        throw new Exception("Unable to apply color-table: {$input} does not exist.");
    }
    if (!$gd) {
        throw new Exception("Unable to apply color-table: {$input} is not a valid image.");
    }
    $ctable = imagecreatefrompng($clut);
    for ($i = 0; $i <= 255; $i++) {
        $rgb = imagecolorat($ctable, 0, $i);
        $r = $rgb >> 16 & 0xff;
        $g = $rgb >> 8 & 0xff;
        $b = $rgb & 0xff;
        imagecolorset($gd, $i, $r, $g, $b);
    }
    // Enable interlacing
    imageinterlace($gd, true);
    imagepng($gd, $output);
    // Cleanup
    if ($input != $output) {
        unlink($input);
    }
    imagedestroy($gd);
    imagedestroy($ctable);
}
开发者ID:Helioviewer-Project,项目名称:api,代码行数:29,代码来源:ImageBuilderOld.php

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

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

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

示例9: setColorPalette

function setColorPalette($input, $clut, $base64 = false)
{
    $gd = null;
    if ($base64) {
        $input = base64_decode($input);
    }
    $gd = imagecreatefromstring($input);
    $ctable = imagecreatefrompng($clut);
    for ($i = 0; $i <= 255; $i++) {
        $rgb = imagecolorat($ctable, 0, $i);
        $r = $rgb >> 16 & 0xff;
        $g = $rgb >> 8 & 0xff;
        $b = $rgb & 0xff;
        imagecolorset($gd, $i, $r, $g, $b);
    }
    // start buffering
    ob_start();
    imagepng($gd, NULL);
    $blob = ob_get_contents();
    // end capture
    ob_end_clean();
    // be tidy; free up memory
    imagedestroy($gd);
    imagedestroy($ctable);
    if ($base64) {
        $blob = base64_encode($blob);
    }
    return $blob;
}
开发者ID:Helioviewer-Project,项目名称:api,代码行数:29,代码来源:ImageBuilderNew.php

示例10: AdjBrightContrast

function AdjBrightContrast($img, $bright, $contr)
{
    $nbr = imagecolorstotal($img);
    for ($i = 0; $i < $nbr; ++$i) {
        $colarr = imagecolorsforindex($img, $i);
        $r = AdjRGBBrightContrast($colarr["red"], $bright, $contr);
        $g = AdjRGBBrightContrast($colarr["green"], $bright, $contr);
        $b = AdjRGBBrightContrast($colarr["blue"], $bright, $contr);
        imagecolorset($img, $i, $r, $g, $b);
    }
}
开发者ID:nourchene-benslimane,项目名称:rth_backup,代码行数:11,代码来源:adjimg.php

示例11: generate

 public function generate()
 {
     $findColor = Image_Image::hexColorToArrayColor($this->find);
     $replaceColor = Image_Image::hexColorToArrayColor($this->replace);
     $index = imagecolorclosest($this->_owner->image, $findColor['red'], $findColor['green'], $findColor['blue']);
     //find
     imagecolorset($this->_owner->image, $index, $replaceColor['red'], $replaceColor['green'], $replaceColor['blue']);
     //replace
     unset($index);
     return true;
 }
开发者ID:joogoo,项目名称:php5-image,代码行数:11,代码来源:Colorize.php

示例12: applyFilter

 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $dest = $aResource->getResource();
     if (imageistruecolor($dest)) {
         imagetruecolortopalette($dest, false, 256);
     }
     foreach ($this->search as $search) {
         $searchRgb = new Color($search);
         $index = imagecolorclosest($aResource->getResource(), $searchRgb->getRed(), $searchRgb->getGreen(), $searchRgb->getBlue());
         // get White COlor
         imagecolorset($aResource->getResource(), $index, $this->replace->getRed(), $this->replace->getGreen(), $this->replace->getBlue());
         // SET NEW COLOR
     }
     $aResource->setResource($dest);
 }
开发者ID:elgervb,项目名称:imagemanipulation,代码行数:20,代码来源:ImageFilterReplaceColor.php

示例13: imagetint

 /**
  * Tints an image.
  * 
  * @param data $img
  * @param int $tint_r
  * @param int $tint_g
  * @param int $tint_b
  * @return data
  * 
  * @example:
  * imagetint($img);  // Grayscale, no tinting
  * imagetint($img, 304, 242, 209);  // What I use for sepia
  * imagetint($img, 0, 0, 255);  // A berry blue image
  * 
  * The RGB values for tinting are normally from 0 to 255.
  * But, you can use values larger than 255 to lighten and "burn" the image.
  * The sepia example above does this a little, the below example provides
  * a better example of lightening the image and burning the light areas
  * out a little:
  * 
  * imagetint($img, 400, 400, 400);  // Lighten image
  * imagetint($img, 127, 127, 127);  // Darken image
  */
 public function imagetint(&$img, $tint_r = 255, $tint_g = 255, $tint_b = 255)
 {
     if (!$this->gd) {
         return;
     }
     $width = imagesx($this->gd);
     $height = imagesy($this->gd);
     $dest = imagecreate($width, $height);
     for ($i = 0; $i < 256; $i++) {
         imagecolorallocate($dest, $i, $i, $i);
     }
     imagecopyresized($dest, $this->gd, 0, 0, 0, 0, $width, $height, $width, $height);
     for ($i = 0; $i < 256; $i++) {
         imagecolorset($dest, $i, min($i * abs($tint_r) / 255, 255), min($i * abs($tint_g) / 255, 255), min($i * abs($tint_b) / 255, 255));
     }
     $img = imagecreate($width, $height);
     imagecopy($this->gd, $dest, 0, 0, 0, 0, $width, $height);
     imagedestroy($dest);
     $output = clone $this;
     $output->setImageResource($this->gd);
     return $output;
 }
开发者ID:helpfulrobot,项目名称:arillo-silverstripe-cleanutilities,代码行数:45,代码来源:CleanGD.php

示例14: send_thumb

function send_thumb($image, $compression, $sizex, $sizey, $generateOnly = false)
{
    global $bg_color_preview_R, $bg_color_preview_G, $bg_color_preview_B;
    set_error_handler("on_error_no_output");
    ini_set("gd.jpeg_ignore_warning", 1);
    // since php 5.1.3 this leads that corrupt jpgs are read much better!
    set_error_handler("on_error");
    $srcx = 0;
    $srcy = 0;
    $dimx = $sizex;
    $dimy = $sizey;
    $usethumbs = false;
    if (file_exists(dirname(__FILE__) . "/thumbs") && is_writable(dirname(__FILE__) . "/thumbs")) {
        // is a caching dir available and writeable?
        $cachename = dirname(__FILE__) . "/thumbs/" . sha1($image . $sizex) . ".jpg";
        $usethumbs = true;
    }
    if ($usethumbs && file_exists($cachename)) {
        // we return the jpg!
        header("Content-type: image/jpg");
        header("Content-Length: " . filesize($cachename));
        header("Pragma: no-cache");
        header("Expires: 0");
        $fp = fopen($cachename, "rb");
        while ($content = fread($fp, 8192)) {
            print $content;
        }
        fclose($fp);
        return true;
    } else {
        if (file_exists($image)) {
            $oldsize = getimagesize($image);
            // for broken images we try to read the exif data!
            if ($oldsize[0] == 0) {
                $oldsize = get_exif_size($image, $image);
            }
            $oldsizex = $oldsize[0];
            $oldsizey = $oldsize[1];
            if ($oldsizex < $sizex && $oldsizey < $sizey) {
                $sizex = $oldsizex;
                $sizey = $oldsizey;
            }
            $height = $sizey;
            $width = $height / $oldsizey * $oldsizex;
            if ($width > $sizex) {
                $width = $sizex;
                $height = $width / $oldsizex * $oldsizey;
            }
            if (isMemoryOk($oldsize, "")) {
                $src = get_image_src($image, $oldsize[2]);
                if (!$src) {
                    // error in image!
                    if ($sizex < 100) {
                        // we return an empty white one ;).
                        $src = ImageCreateTrueColor($oldsizex, $oldsizey);
                        $back = imagecolorallocate($src, 255, 255, 255);
                        imagefilledrectangle($src, 0, 0, $oldsizex, $oldsizex, $back);
                    }
                    debug($image . " is not a valid image - please check the file.");
                    return false;
                }
                // $dst = ImageCreateTrueColor($width, $height);
                $dst = ImageCreateTrueColor($dimx, $dimy);
                if ($dimx < 100) {
                    // white bg for small preview
                    $back = imagecolorallocate($dst, $bg_color_preview_R, $bg_color_preview_G, $bg_color_preview_B);
                } else {
                    // gray bg for big preview
                    $back = imagecolorallocate($dst, 245, 245, 245);
                }
                imagefilledrectangle($dst, 0, 0, $dimx, $dimy, $back);
                if ($dimx > 100) {
                    // border
                    imagerectangle($dst, 0, 0, $dimx - 1, $dimy - 1, imagecolorallocate($dst, 160, 160, 160));
                }
                $offsetx = 0;
                $offsetx_b = 0;
                if ($dimx > $width) {
                    // we have to center!
                    $offsetx = floor(($dimx - $width) / 2);
                } else {
                    if ($dimx > 100) {
                        $offsetx = 4;
                        $offsetx_b = 8;
                    }
                }
                $offsety = 0;
                $offsety_b = 0;
                if ($dimy > $height) {
                    // we have to center!
                    $offsety = floor(($dimy - $height) / 2);
                } else {
                    if ($dimx > 100) {
                        $offsety = 4;
                        $offsety_b = 8;
                    }
                }
                $trans = imagecolortransparent($src);
                imagecolorset($src, $trans, 255, 255, 255);
                imagecolortransparent($src, imagecolorallocate($src, 0, 0, 0));
//.........这里部分代码省略.........
开发者ID:jmp0207,项目名称:w3studiocms,代码行数:101,代码来源:tfu_helper.php

示例15: image_resize

 static function image_resize($src, $dest, $width, $height, $quality = 90)
 {
     if (!file_exists($src)) {
         return false;
     }
     $size = getimagesize($src);
     if ($size === false) {
         return false;
     }
     $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
     $w = $size[0];
     $h = $size[1];
     if ($width < $w && $w > $h) {
         $new_width = $width;
         $coef = $w / $width;
         $new_height = round($h / $coef);
     } elseif ($h == $w) {
         $new_height = min($height, $width);
         $new_width = $new_height;
     } else {
         $new_height = $height;
         $coef = $h / $height;
         $new_width = round($w / $coef);
     }
     if ($width > $w && $height > $h) {
         $new_width = $w;
         $new_height = $h;
     }
     if ($format == 'jpeg') {
         $image_src = imagecreatefromjpeg($src);
     }
     if ($format == 'png') {
         $image_src = imagecreatefrompng($src);
     }
     if ($format == 'gif') {
         $image_src = imagecreatefromgif($src);
     }
     $image_dest = imagecreatetruecolor($new_width, $new_height);
     $image_dest2 = imagecreatetruecolor($w, $h);
     imagecopyresampled($image_dest, $image_src, 0, 0, 0, 0, $new_width, $new_height, $w, $h);
     //imagecopyresampled($image_dest2, $image_src, 0, 0, 0, 0, $w, $h, $w, $h);
     imagecolorset($image_dest, 0, 255, 255, 255);
     if ($format == 'jpeg') {
         imagejpeg($image_dest, $dest, $quality);
     }
     if ($format == 'png') {
         imagepng($image_dest, $dest, $quality);
     }
     if ($format == 'gif') {
         imagegif($image_dest, $dest, $quality);
     }
     //echo imagecolorat($image_dest,1,1).'<br>src='.imagecolorat($image_dest2,1,1);exit;
     //imagecolortransparent($image_dest, "#000000");
     imagedestroy($image_src);
     imagedestroy($image_dest);
     return true;
 }
开发者ID:askovorodka,项目名称:sqc,代码行数:57,代码来源:class.image.php


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